Skip to content

Commit

Permalink
Added migration failure unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Sep 3, 2020
1 parent af752ac commit 6cca8ec
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions x-pack/plugins/alerts/server/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ describe('7.10.0', () => {
});
});

describe('7.10.0 migrates with failure', () => {
beforeEach(() => {
jest.resetAllMocks();
encryptedSavedObjectsSetup.createMigration.mockRejectedValueOnce(
new Error(`Can't migrate!`) as never
);
});

test('should show the proper exception', () => {
const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0'];
const alert = getMockData({
consumer: 'alerting',
});
const res = migration710(alert, { log });
expect(res).toMatchObject({
...alert,
attributes: {
...alert.attributes,
},
});
expect(log.error).toHaveBeenCalledWith(
`encryptedSavedObject migration failed for alert ${alert.id} with error: migrationFunc is not a function`,
{
alertDocument: {
...alert,
attributes: {
...alert.attributes,
},
},
}
);
});
});

function getMockData(
overwrites: Record<string, unknown> = {}
): SavedObjectUnsanitizedDoc<RawAlert> {
Expand Down

0 comments on commit 6cca8ec

Please sign in to comment.