From 46238e12577bb7dd58fab35937b644f712afd91c Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Tue, 17 Oct 2023 13:51:02 +0800 Subject: [PATCH] feat: optimize unit test Signed-off-by: SuZhou-Joe --- .../server/integration_tests/routes.test.ts | 28 ++++++++++++++----- test/api_integration/apis/workspace/index.ts | 15 ++++++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/plugins/workspace/server/integration_tests/routes.test.ts b/src/plugins/workspace/server/integration_tests/routes.test.ts index b8fdfaa98435..0f6c027ea61d 100644 --- a/src/plugins/workspace/server/integration_tests/routes.test.ts +++ b/src/plugins/workspace/server/integration_tests/routes.test.ts @@ -4,9 +4,13 @@ */ import { WorkspaceAttribute } from 'src/core/types'; -import { omit } from 'lodash'; import * as osdTestServer from '../../../../core/test_helpers/osd_server'; +const omitId = (object: T): Omit => { + const { id, ...others } = object; + return others; +}; + const testWorkspace: WorkspaceAttribute = { id: 'fake_id', name: 'test_workspace', @@ -60,7 +64,7 @@ describe('workspace service', () => { const result: any = await osdTestServer.request .post(root, `/api/workspaces`) .send({ - attributes: omit(testWorkspace, 'id'), + attributes: omitId(testWorkspace), }) .expect(200); @@ -71,7 +75,7 @@ describe('workspace service', () => { const result = await osdTestServer.request .post(root, `/api/workspaces`) .send({ - attributes: omit(testWorkspace, 'id'), + attributes: omitId(testWorkspace), }) .expect(200); @@ -85,7 +89,7 @@ describe('workspace service', () => { const result: any = await osdTestServer.request .post(root, `/api/workspaces`) .send({ - attributes: omit(testWorkspace, 'id'), + attributes: omitId(testWorkspace), }) .expect(200); @@ -93,7 +97,7 @@ describe('workspace service', () => { .put(root, `/api/workspaces/${result.body.result.id}`) .send({ attributes: { - ...omit(testWorkspace, 'id'), + ...omitId(testWorkspace), name: 'updated', }, }) @@ -111,7 +115,7 @@ describe('workspace service', () => { const result: any = await osdTestServer.request .post(root, `/api/workspaces`) .send({ - attributes: omit(testWorkspace, 'id'), + attributes: omitId(testWorkspace), }) .expect(200); @@ -130,7 +134,17 @@ describe('workspace service', () => { await osdTestServer.request .post(root, `/api/workspaces`) .send({ - attributes: omit(testWorkspace, 'id'), + attributes: omitId(testWorkspace), + }) + .expect(200); + + await osdTestServer.request + .post(root, `/api/workspaces`) + .send({ + attributes: { + ...omitId(testWorkspace), + name: 'another test workspace', + }, }) .expect(200); diff --git a/test/api_integration/apis/workspace/index.ts b/test/api_integration/apis/workspace/index.ts index 94138bb47f00..9d4919b852bf 100644 --- a/test/api_integration/apis/workspace/index.ts +++ b/test/api_integration/apis/workspace/index.ts @@ -123,6 +123,17 @@ export default function ({ getService }: FtrProviderContext) { .set('osd-xsrf', 'opensearch-dashboards') .expect(200); + await supertest + .post(`/api/workspaces`) + .send({ + attributes: { + ...omitId(testWorkspace), + name: 'another test workspace', + }, + }) + .set('osd-xsrf', 'opensearch-dashboards') + .expect(200); + const listResult = await supertest .post(`/api/workspaces/_list`) .send({ @@ -130,7 +141,7 @@ export default function ({ getService }: FtrProviderContext) { }) .set('osd-xsrf', 'opensearch-dashboards') .expect(200); - expect(listResult.body.result.total).equal(1); + expect(listResult.body.result.total).equal(2); }); - }).tags('is:workspace'); + }); }