forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Print the name of the migration that cannot be reverted w…
…hen using `n8n db:revert` (n8n-io#9473)
- Loading branch information
1 parent
9367907
commit 3b93aae
Showing
4 changed files
with
199 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/cli/test/unit/databases/utils/migrationHelpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |