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) => {
|
2023-05-08 10:23:28 +00:00
|
|
|
const migrations: Array<Migration<Date, string, string>> = [
|
2022-03-03 13:40:38 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
});
|