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

23 lines
605 B
TypeScript
Raw Normal View History

2022-03-03 13:40:38 +00:00
import test from 'ava';
import {migrate, Migration} from '../source/migration-helper.js';
test('migrate<Date>', async (t) => {
const migrations: Array<Migration<Date>> = [
{
version: new Date('2022-01-01'),
migrate: async (data: string) => `${data} migrated`,
},
];
function offsetDate(offset: number): Date {
const d = new Date(migrations[0].version);
d.setDate(d.getDate() + offset);
return d;
}
const data = 'data';
t.is(await migrate(data, offsetDate(-1), migrations), 'data migrated');
t.is(await migrate(data, offsetDate(1), migrations), data);
});