From d5b86768cac5691c433a3d065c14ff867351dfdb Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 10 Apr 2024 16:29:27 +0800 Subject: [PATCH] feat: add unit test Signed-off-by: SuZhou-Joe --- .../workspace_id_consumer_wrapper.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts index b8d1b93f2686..28c9aad535af 100644 --- a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts +++ b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts @@ -8,6 +8,7 @@ import { SavedObject } from '../../../../core/public'; import { httpServerMock, savedObjectsClientMock, coreMock } from '../../../../core/server/mocks'; import { WorkspaceIdConsumerWrapper } from './workspace_id_consumer_wrapper'; import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../../../../plugins/data_source/common'; +import { UI_SETTINGS_SAVED_OBJECTS_TYPE } from '../../../../core/server'; describe('WorkspaceIdConsumerWrapper', () => { const requestHandlerContext = coreMock.createRequestHandlerContext(); @@ -86,6 +87,30 @@ describe('WorkspaceIdConsumerWrapper', () => { } ); }); + + it(`Should throw error when trying to create unallowed type within a workspace`, async () => { + expect(() => + wrapperClient.bulkCreate([ + getSavedObject({ + type: DATA_SOURCE_SAVED_OBJECT_TYPE, + id: 'foo', + }), + ]) + ).toThrow('type: data-source is not allowed to create within a workspace.'); + + expect(() => + wrapperClient.bulkCreate([ + getSavedObject({ + type: DATA_SOURCE_SAVED_OBJECT_TYPE, + id: 'foo', + }), + getSavedObject({ + type: UI_SETTINGS_SAVED_OBJECTS_TYPE, + id: 'bar', + }), + ]) + ).toThrow('type: data-source, type: config are not allowed to create within a workspace.'); + }); }); describe('checkConflict', () => {