diff --git a/src/plugins/workspace/server/integration_tests/routes.test.ts b/src/plugins/workspace/server/integration_tests/routes.test.ts index 36f1b4e6d8a..101ca824f9f 100644 --- a/src/plugins/workspace/server/integration_tests/routes.test.ts +++ b/src/plugins/workspace/server/integration_tests/routes.test.ts @@ -21,6 +21,7 @@ const testWorkspace: WorkspaceAttribute = { describe('workspace service', () => { let root: ReturnType; let opensearchServer: osdTestServer.TestOpenSearchUtils; + let osd: osdTestServer.TestOpenSearchDashboardsUtils; beforeAll(async () => { const { startOpenSearch, startOpenSearchDashboards } = osdTestServer.createTestServers({ adjustTimeout: (t: number) => jest.setTimeout(t), @@ -37,8 +38,8 @@ describe('workspace service', () => { }, }); opensearchServer = await startOpenSearch(); - const startOSDResp = await startOpenSearchDashboards(); - root = startOSDResp.root; + osd = await startOpenSearchDashboards(); + root = osd.root; }, 30000); afterAll(async () => { await root.shutdown(); @@ -52,15 +53,17 @@ describe('workspace service', () => { page: 1, }) .expect(200); - await Promise.all( - listResult.body.result.workspaces.map((item: WorkspaceAttribute) => - // workspace delete API will not able to delete reserved workspace - // to clean up the test data, change it saved objects delete API - osdTestServer.request - .delete(root, `/api/saved_objects/${WORKSPACE_TYPE}/${item.id}`) - .expect(200) + const savedObjectsRepository = osd.coreStart.savedObjects.createInternalRepository([ + WORKSPACE_TYPE, + ]); + await expect( + Promise.all( + listResult.body.result.workspaces.map((item: WorkspaceAttribute) => + // this will delete reserved workspace + savedObjectsRepository.delete(WORKSPACE_TYPE, item.id) + ) ) - ); + ).resolves.toBeInstanceOf(Array); }); it('create', async () => { await osdTestServer.request @@ -229,7 +232,8 @@ describe('workspace service', () => { page: 1, }) .expect(200); - expect(listResult.body.result.total).toEqual(2); + // Global and Management workspace will be created by default after workspace list API called. + expect(listResult.body.result.total).toEqual(4); }); it('unable to perform operations on workspace by calling saved objects APIs', async () => { const result = await osdTestServer.request @@ -291,7 +295,8 @@ describe('workspace service', () => { }) .expect(200); expect(findResult.body.total).toEqual(0); - expect(listResult.body.result.total).toEqual(1); + // Global and Management workspace will be created by default after workspace list API called. + expect(listResult.body.result.total).toEqual(3); }); }); });