mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(core): Print the name of the migration that cannot be reverted when using n8n db:revert (#9473)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user