Skip to content

Commit

Permalink
add collect test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 1, 2021
1 parent 88027ee commit 1e8f092
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1019,4 +1019,77 @@ describe('collectExportedObjects', () => {
);
});
});

describe('exporting multi-namespaced objects from multiple namespaces', () => {
it(`uses the object's namespaces to fetch the references`, async () => {
registerType('multi', { namespaceType: 'multiple' });
registerType('ref', { namespaceType: 'multiple' });

const obj1 = createObject({
type: 'single',
id: '1',
namespaces: ['ns1', 'ns2', 'ns3'],
references: [
{
id: '1',
type: 'ref',
name: 'ref-ns1',
},
],
});
const obj2 = createObject({
type: 'single',
id: '1',
namespaces: ['*'],
references: [
{
id: '2',
type: 'ref',
name: 'ref-ns2',
},
],
});

const ref1 = createObject({
type: 'ref',
id: '1',
namespaces: ['ns1', 'ns2'],
});
const ref2 = createObject({
type: 'ref',
id: '2',
namespaces: ['*'],
});

savedObjectsClient.bulkGet.mockResolvedValueOnce({
saved_objects: [ref1, ref2],
});

const { objects } = await collectExportedObjects({
objects: [obj1, obj2],
savedObjectsClient,
request,
typeRegistry,
includeReferences: true,
logger,
});

expect(objects.map(toIdTypeNsTuple)).toEqual([obj1, obj2, ref1, ref2].map(toIdTypeNsTuple));
expect(savedObjectsClient.bulkGet).toHaveBeenCalledWith(
[
{
type: 'ref',
id: '1',
namespaces: ['ns1', 'ns2', 'ns3'],
},
{
type: 'ref',
id: '2',
namespaces: ['*'],
},
],
expect.any(Object)
);
});
});
});

0 comments on commit 1e8f092

Please sign in to comment.