feat(core): Print the name of the migration that cannot be reverted when using n8n db:revert (#9473)

This commit is contained in:
Danny Martini
2024-05-23 18:16:26 +02:00
committed by GitHub
parent 93679076b4
commit 3b93aae6dc
4 changed files with 207 additions and 79 deletions

View File

@@ -0,0 +1,66 @@
import type { IrreversibleMigration, ReversibleMigration } from '@/databases/types';
import { wrapMigration } from '@/databases/utils/migrationHelpers';
describe('migrationHelpers.wrapMigration', () => {
test('throws if passed a migration without up method', async () => {
//
// ARRANGE
//
class TestMigration {}
//
// ACT & ASSERT
//
expect(() => wrapMigration(TestMigration as never)).toThrow(
'Migration "TestMigration" is missing the method `up`.',
);
});
test('wraps up method', async () => {
//
// ARRANGE
//
class TestMigration implements IrreversibleMigration {
async up() {}
}
const originalUp = jest.fn();
TestMigration.prototype.up = originalUp;
//
// ACT
//
wrapMigration(TestMigration);
await new TestMigration().up();
//
// ASSERT
//
expect(TestMigration.prototype.up).not.toBe(originalUp);
expect(originalUp).toHaveBeenCalledTimes(1);
});
test('wraps down method', async () => {
//
// ARRANGE
//
class TestMigration implements ReversibleMigration {
async up() {}
async down() {}
}
const originalDown = jest.fn();
TestMigration.prototype.down = originalDown;
//
// ACT
//
wrapMigration(TestMigration);
await new TestMigration().down();
//
// ASSERT
//
expect(TestMigration.prototype.down).not.toBe(originalDown);
expect(originalDown).toHaveBeenCalledTimes(1);
});
});