Skip to content

Commit

Permalink
Modify test case
Browse files Browse the repository at this point in the history
Signed-off-by: gaobinlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Apr 11, 2024
1 parent f172517 commit 8c9a08d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/plugins/workspace/server/integration_tests/duplicate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { loggingSystemMock, savedObjectsClientMock } from '../../../../core/serv
import { setupServer } from '../../../../core/server/test_utils';
import { registerDuplicateRoute } from '../routes/duplicate';
import { createListStream } from '../../../../core/server/utils/streams';
import Boom from '@hapi/boom';

jest.mock('../../../../core/server/saved_objects/export', () => ({
exportSavedObjectsToStream: jest.fn(),
Expand Down Expand Up @@ -110,9 +111,16 @@ describe(`duplicate saved objects among workspaces`, () => {
await server.stop();
});

it('formats successful response if all requested saved objects are not valid', async () => {
it('duplicate failed if the requested saved objects are not valid', async () => {
const savedObjects = [mockIndexPattern, mockDashboard];
clientMock.get.mockResolvedValueOnce({ success: true });
exportSavedObjectsToStream.mockResolvedValueOnce(createListStream([]));
exportSavedObjectsToStream.mockImplementation(() => {
const err = Boom.badRequest();
err.output.payload.attributes = {
objects: savedObjects,
};
throw err;
});

const result = await supertest(httpSetup.server.listener)
.post(URL)
Expand All @@ -130,9 +138,9 @@ describe(`duplicate saved objects among workspaces`, () => {
includeReferencesDeep: true,
targetWorkspace: 'test_workspace',
})
.expect(200);
.expect(400);

expect(result.body).toEqual({ success: true, successCount: 0 });
expect(result.body.error).toEqual('Bad Request');
expect(savedObjectsClient.bulkCreate).not.toHaveBeenCalled(); // no objects were created
});

Expand Down

0 comments on commit 8c9a08d

Please sign in to comment.