Skip to content

Commit

Permalink
Update jsdocs; add UT
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler committed Jul 21, 2023
1 parent e313330 commit b391212
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class SavedObjectLoader {
* @param search
* @param size
* @param fields
* @param hasReference Optional field to specify a reference
* @param searchFields Optional field to specify the search fields in the query
* @returns {Promise}
*/
findAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export class SavedObjectLoaderAugmentVis extends SavedObjectLoader {
* @param search
* @param size
* @param fields
* @param hasReference Optional field to specify a reference
* @param searchFields Optional field to specify the search fields in the query
* @returns {Promise}
*/
findAll(
Expand Down
70 changes: 70 additions & 0 deletions src/plugins/vis_augmenter/public/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,76 @@ describe('utils', () => {
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
expect((await getAugmentVisSavedObjs(visId1, loader)).length).toEqual(2);
});
it('undefined plugin resource list has no effect', async () => {
const loader = createSavedAugmentVisLoader({
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]),
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
expect((await getAugmentVisSavedObjs(visId1, loader, undefined, undefined)).length).toEqual(
2
);
});
it('empty plugin resource list has no effect', async () => {
const loader = createSavedAugmentVisLoader({
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]),
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
expect((await getAugmentVisSavedObjs(visId1, loader, undefined, [])).length).toEqual(2);
});
it('empty / undefined plugin resource list passes correct findAll() params', async () => {
const loader = createSavedAugmentVisLoader({
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]),
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
loader.findAll = jest.fn().mockImplementation(loader.findAll);
expect((await getAugmentVisSavedObjs(visId1, loader, undefined, [])).length).toEqual(2);
expect(loader.findAll).toHaveBeenCalledWith(
'',
100,
[],
{
type: 'visualization',
id: visId1 as string,
},
[]
);
});
it('single plugin resource is propagated to findAll()', async () => {
const loader = createSavedAugmentVisLoader({
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]),
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
loader.findAll = jest.fn().mockImplementation(loader.findAll);
expect(
(await getAugmentVisSavedObjs(visId1, loader, undefined, ['resource-1'])).length
).toEqual(2);
expect(loader.findAll).toHaveBeenCalledWith(
'resource-1',
100,
[],
{
type: 'visualization',
id: visId1 as string,
},
['pluginResource.id']
);
});
it('multiple plugin resources are propagated to findAll()', async () => {
const loader = createSavedAugmentVisLoader({
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]),
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis);
loader.findAll = jest.fn().mockImplementation(loader.findAll);
expect(
(await getAugmentVisSavedObjs(visId1, loader, undefined, ['resource-1', 'resource-2']))
.length
).toEqual(2);
expect(loader.findAll).toHaveBeenCalledWith(
'resource-1|resource-2',
100,
[],
{
type: 'visualization',
id: visId1 as string,
},
['pluginResource.id']
);
});
});

describe('buildPipelineFromAugmentVisSavedObjs', () => {
Expand Down

0 comments on commit b391212

Please sign in to comment.