-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/plugins/data/public/data_views/saved_objects_client_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,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper'; | ||
import { savedObjectsServiceMock } from 'src/core/public/mocks'; | ||
|
||
import { DataViewSavedObjectConflictError } from '../../common/data_views'; | ||
|
||
describe('SavedObjectsClientPublicToCommon', () => { | ||
const soClient = savedObjectsServiceMock.createStartContract().client; | ||
|
||
test('get saved object - exactMatch', async () => { | ||
const mockedSavedObject = { | ||
version: 'abc', | ||
}; | ||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'exactMatch', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientPublicToCommon(soClient); | ||
const result = await service.get('index-pattern', '1'); | ||
expect(result).toStrictEqual(mockedSavedObject); | ||
}); | ||
|
||
test('get saved object - aliasMatch', async () => { | ||
const mockedSavedObject = { | ||
version: 'def', | ||
}; | ||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'aliasMatch', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientPublicToCommon(soClient); | ||
const result = await service.get('index-pattern', '1'); | ||
expect(result).toStrictEqual(mockedSavedObject); | ||
}); | ||
|
||
test('get saved object - conflict', async () => { | ||
const mockedSavedObject = { | ||
version: 'ghi', | ||
}; | ||
|
||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'conflict', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientPublicToCommon(soClient); | ||
|
||
await expect(service.get('index-pattern', '1')).rejects.toThrow( | ||
DataViewSavedObjectConflictError | ||
); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
src/plugins/data/server/data_views/saved_objects_client_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,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper'; | ||
import { SavedObjectsClientContract } from 'src/core/server'; | ||
|
||
import { DataViewSavedObjectConflictError } from '../../common/data_views'; | ||
|
||
describe('SavedObjectsClientPublicToCommon', () => { | ||
const soClient = ({ resolve: jest.fn() } as unknown) as SavedObjectsClientContract; | ||
|
||
test('get saved object - exactMatch', async () => { | ||
const mockedSavedObject = { | ||
version: 'abc', | ||
}; | ||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'exactMatch', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientServerToCommon(soClient); | ||
const result = await service.get('index-pattern', '1'); | ||
expect(result).toStrictEqual(mockedSavedObject); | ||
}); | ||
|
||
test('get saved object - aliasMatch', async () => { | ||
const mockedSavedObject = { | ||
version: 'def', | ||
}; | ||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'aliasMatch', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientServerToCommon(soClient); | ||
const result = await service.get('index-pattern', '1'); | ||
expect(result).toStrictEqual(mockedSavedObject); | ||
}); | ||
|
||
test('get saved object - conflict', async () => { | ||
const mockedSavedObject = { | ||
version: 'ghi', | ||
}; | ||
|
||
soClient.resolve = jest | ||
.fn() | ||
.mockResolvedValue({ outcome: 'conflict', saved_object: mockedSavedObject }); | ||
const service = new SavedObjectsClientServerToCommon(soClient); | ||
|
||
await expect(service.get('index-pattern', '1')).rejects.toThrow( | ||
DataViewSavedObjectConflictError | ||
); | ||
}); | ||
}); |