Skip to content

Commit

Permalink
add test for indexMigrator
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 9, 2020
1 parent ec08e99 commit 364545d
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,30 @@ describe('IndexMigrator', () => {
],
});
});

test('rejects when the migration function throws an error', async () => {
const { client } = testOpts;
const migrateDoc = jest.fn((doc: SavedObjectUnsanitizedDoc) => {
throw new Error('error migrating document');
});

testOpts.documentMigrator = {
migrationVersion: { foo: '1.2.3' },
migrate: migrateDoc,
};

withIndex(client, {
numOutOfDate: 1,
docs: [
[{ _id: 'foo:1', _source: { type: 'foo', foo: { name: 'Bar' } } }],
[{ _id: 'foo:2', _source: { type: 'foo', foo: { name: 'Baz' } } }],
],
});

await expect(new IndexMigrator(testOpts).migrate()).rejects.toThrowErrorMatchingInlineSnapshot(
`"error migrating document"`
);
});
});

function withIndex(
Expand Down

0 comments on commit 364545d

Please sign in to comment.