Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken usages of bulkCreate #75597

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ describe('importDashboards(req)', () => {
savedObjectClient.bulkCreate.mockResolvedValue({ saved_objects: [] });

importedObjects = [
{ id: 'dashboard-01', type: 'dashboard', attributes: { panelJSON: '{}' }, references: [] },
{
id: 'dashboard-01',
type: 'dashboard',
attributes: { panelJSON: '{}' },
references: [],
version: 'foo',
},
{ id: 'panel-01', type: 'visualization', attributes: { visState: '{}' }, references: [] },
];
});

test('should call bulkCreate with each asset', async () => {
test('should call bulkCreate with each asset, filtering out any version if present', async () => {
await importDashboards(savedObjectClient, importedObjects, { overwrite: false, exclude: [] });

expect(savedObjectClient.bulkCreate).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export async function importDashboards(
// docs are not seen as automatically up-to-date.
const docs = objects
.filter((item) => !exclude.includes(item.type))
.map((doc) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
// filter out any document version, if present
.map(({ version, ...doc }) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));

const results = await savedObjectsClient.bulkCreate(docs, { overwrite });
return { objects: results.saved_objects };
Expand Down