forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
639ede0
commit 1325e2a
Showing
6 changed files
with
221 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { httpServerMock } from '../mocks'; | ||
import { getWorkspaceState, updateWorkspaceState } from './workspace'; | ||
|
||
describe('updateWorkspaceState', () => { | ||
it('update with payload', () => { | ||
const requestMock = httpServerMock.createOpenSearchDashboardsRequest(); | ||
updateWorkspaceState(requestMock, { | ||
id: 'foo', | ||
}); | ||
expect(getWorkspaceState(requestMock)).toEqual({ | ||
id: 'foo', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { updateWorkspaceState } from '../../../../core/server/utils'; | ||
import { SavedObject } from '../../../../core/public'; | ||
import { httpServerMock, savedObjectsClientMock, coreMock } from '../../../../core/server/mocks'; | ||
import { WorkspaceIdConsumerWrapper } from './workspace_id_consumer_wrapper'; | ||
|
||
describe('WorkspaceIdConsumerWrapper', () => { | ||
const requestHandlerContext = coreMock.createRequestHandlerContext(); | ||
const wrapperInstance = new WorkspaceIdConsumerWrapper(); | ||
const mockedClient = savedObjectsClientMock.create(); | ||
const workspaceEnabledMockRequest = httpServerMock.createOpenSearchDashboardsRequest(); | ||
updateWorkspaceState(workspaceEnabledMockRequest, { | ||
id: 'foo', | ||
}); | ||
const wrapperClient = wrapperInstance.wrapperFactory({ | ||
client: mockedClient, | ||
typeRegistry: requestHandlerContext.savedObjects.typeRegistry, | ||
request: workspaceEnabledMockRequest, | ||
}); | ||
const getSavedObject = (savedObject: Partial<SavedObject>) => { | ||
const payload: SavedObject = { | ||
references: [], | ||
id: '', | ||
type: 'dashboard', | ||
attributes: {}, | ||
...savedObject, | ||
}; | ||
|
||
return payload; | ||
}; | ||
describe('create', () => { | ||
beforeEach(() => { | ||
mockedClient.create.mockClear(); | ||
}); | ||
it(`Should add workspaces parameters when create`, async () => { | ||
await wrapperClient.create('dashboard', { | ||
name: 'foo', | ||
}); | ||
|
||
expect(mockedClient.create).toBeCalledWith( | ||
expect.anything(), | ||
expect.anything(), | ||
expect.objectContaining({ | ||
workspaces: ['foo'], | ||
}) | ||
); | ||
}); | ||
|
||
it(`Should use options.workspaces there is workspaces inside options`, async () => { | ||
await wrapperClient.create( | ||
'dashboard', | ||
{ | ||
name: 'foo', | ||
}, | ||
{ | ||
id: 'dashboard:foo', | ||
overwrite: true, | ||
workspaces: undefined, | ||
} | ||
); | ||
|
||
expect(mockedClient.create.mock.calls[0][2]?.hasOwnProperty('workspaces')).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('bulkCreate', () => { | ||
beforeEach(() => { | ||
mockedClient.bulkCreate.mockClear(); | ||
}); | ||
it(`Should add workspaces parameters when bulk create`, async () => { | ||
await wrapperClient.bulkCreate([ | ||
getSavedObject({ | ||
id: 'foo', | ||
}), | ||
]); | ||
|
||
expect(mockedClient.bulkCreate).toBeCalledWith( | ||
[{ attributes: {}, id: 'foo', references: [], type: 'dashboard' }], | ||
{ | ||
workspaces: ['foo'], | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe('checkConflict', () => { | ||
beforeEach(() => { | ||
mockedClient.checkConflicts.mockClear(); | ||
}); | ||
|
||
it(`Should add workspaces parameters when checkConflict`, async () => { | ||
await wrapperClient.checkConflicts([]); | ||
expect(mockedClient.checkConflicts).toBeCalledWith([], { | ||
workspaces: ['foo'], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('find', () => { | ||
beforeEach(() => { | ||
mockedClient.find.mockClear(); | ||
}); | ||
|
||
it(`Should add workspaces parameters when find`, async () => { | ||
await wrapperClient.find({ | ||
type: 'dashboard', | ||
}); | ||
expect(mockedClient.find).toBeCalledWith({ | ||
type: 'dashboard', | ||
workspaces: ['foo'], | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters