-
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.
…#108637) (#112670) * Data views - saved object client use `resolve` instead of `get` (#108637) * so client - use resolve instead of get Co-authored-by: Kibana Machine <[email protected]> * lint fix Co-authored-by: Matthew Kime <[email protected]>
- Loading branch information
1 parent
9092ed7
commit 167fa4b
Showing
7 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/plugins/data/common/data_views/errors/data_view_saved_object_conflict.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,14 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export class DataViewSavedObjectConflictError extends Error { | ||
constructor(savedObjectId: string) { | ||
super(`Conflict loading DataView saved object, id: ${savedObjectId}`); | ||
this.name = 'DataViewSavedObjectConflictError'; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
export * from './duplicate_index_pattern'; | ||
export * from './data_view_saved_object_conflict'; |
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 | ||
); | ||
}); | ||
}); |
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
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 | ||
); | ||
}); | ||
}); |
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