From 1e8f0922d62c1529bd63af2e427c4097f650dd3e Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Wed, 1 Sep 2021 19:06:10 +0200 Subject: [PATCH] add collect test --- .../export/collect_exported_objects.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/core/server/saved_objects/export/collect_exported_objects.test.ts b/src/core/server/saved_objects/export/collect_exported_objects.test.ts index 7cf4087146c91..0f4e341230e18 100644 --- a/src/core/server/saved_objects/export/collect_exported_objects.test.ts +++ b/src/core/server/saved_objects/export/collect_exported_objects.test.ts @@ -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) + ); + }); + }); });