Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Feb 29, 2024
1 parent fe3c3f7 commit 758a358
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 81 deletions.
11 changes: 0 additions & 11 deletions src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ export async function importSavedObjectsFromStream({
// randomly generated id
importIdMap = regenerateIds(collectSavedObjectsResult.collectedObjects, dataSourceId);
} else {
// in check conclict and override mode

if (workspaces) {
importIdMap = await regenerateIdsWithReference({
savedObjects: collectSavedObjectsResult.collectedObjects,
savedObjectsClient,
workspaces,
objectLimit,
importIdMap,
});
}
// Check single-namespace objects for conflicts in this namespace, and check multi-namespace objects for conflicts across all namespaces
const checkConflictsParams = {
objects: collectSavedObjectsResult.collectedObjects,
Expand Down
71 changes: 1 addition & 70 deletions src/core/server/saved_objects/import/regenerate_ids.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
*/

import { mockUuidv4 } from './__mocks__';
import { regenerateIds, regenerateIdsWithReference } from './regenerate_ids';
import { regenerateIds } from './regenerate_ids';
import { SavedObject } from '../types';
import { savedObjectsClientMock } from '../service/saved_objects_client.mock';
import { SavedObjectsBulkResponse } from '../service';

describe('#regenerateIds', () => {
const objects = ([
Expand Down Expand Up @@ -70,70 +68,3 @@ describe('#regenerateIds', () => {
`);
});
});

describe('#regenerateIdsWithReference', () => {
const objects = ([
{ type: 'foo', id: '1' },
{ type: 'bar', id: '2' },
{ type: 'baz', id: '3' },
] as any) as SavedObject[];

test('returns expected values', async () => {
const mockedSavedObjectsClient = savedObjectsClientMock.create();
mockUuidv4.mockReturnValueOnce('uuidv4 #1');
const result: SavedObjectsBulkResponse<unknown> = {
saved_objects: [
{
error: {
statusCode: 404,
error: '',
message: '',
},
id: '1',
type: 'foo',
attributes: {},
references: [],
},
{
id: '2',
type: 'bar',
attributes: {},
references: [],
workspaces: ['bar'],
},
{
id: '3',
type: 'baz',
attributes: {},
references: [],
workspaces: ['foo'],
},
],
};
mockedSavedObjectsClient.bulkGet.mockResolvedValue(result);
expect(
await regenerateIdsWithReference({
savedObjects: objects,
savedObjectsClient: mockedSavedObjectsClient,
workspaces: ['bar'],
objectLimit: 1000,
importIdMap: new Map(),
})
).toMatchInlineSnapshot(`
Map {
"foo:1" => Object {
"id": "1",
"omitOriginId": true,
},
"bar:2" => Object {
"id": "2",
"omitOriginId": false,
},
"baz:3" => Object {
"id": "uuidv4 #1",
"omitOriginId": true,
},
}
`);
});
});

0 comments on commit 758a358

Please sign in to comment.