1
Fork 0
migration-helper/tests/object.test.ts

26 lines
623 B
TypeScript
Raw Normal View History

2022-03-03 13:40:38 +00:00
import test from 'ava';
import {
migrate,
Migration,
SkipMigrationFn,
} from '../source/migration-helper.js';
test('migrate<{custom: number}>', async (t) => {
type Custom = {
custom: number;
};
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
2023-05-08 10:23:28 +00:00
const migrations: Array<Migration<Custom, string, string>> = [
2022-03-03 13:40:38 +00:00
{
version: {custom: 5},
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
t.is(await migrate(data, {custom: 4}, migrations, skip), data);
t.is(await migrate(data, {custom: 6}, migrations, skip), 'data migrated');
});