undeexcepturi
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
45 lines (34 loc) • 1.57 kB
text/typescript
(global as any).process.env.FORCE_COLOR = 0;
import { Migrator } from '@mikro-orm/migrations';
import { MikroORM } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
import { CLIHelper } from '@mikro-orm/cli';
import { MigrationCommandFactory } from '../../../packages/cli/src/commands/MigrationCommandFactory';
import { initORMSqlite } from '../../bootstrap';
const closeSpy = jest.spyOn(MikroORM.prototype, 'close');
jest.spyOn(CLIHelper, 'showHelp').mockImplementation(() => void 0);
const getExecutedMigrations = jest.spyOn(Migrator.prototype, 'getExecutedMigrations');
getExecutedMigrations.mockResolvedValue([{ name: '1', executed_at: new Date() }]);
const dumpMock = jest.spyOn(CLIHelper, 'dump');
dumpMock.mockImplementation(() => void 0);
jest.spyOn(CLIHelper, 'dumpTable').mockImplementation(() => void 0);
describe('ListMigrationsCommand', () => {
let orm: MikroORM<SqliteDriver>;
beforeAll(async () => {
orm = await initORMSqlite();
const getORMMock = jest.spyOn(CLIHelper, 'getORM');
getORMMock.mockResolvedValue(orm);
});
afterAll(async () => await orm.close(true));
test('builder', async () => {
const cmd = MigrationCommandFactory.create('list');
const args = { option: jest.fn() };
cmd.builder(args as any);
});
test('handler', async () => {
const cmd = MigrationCommandFactory.create('list');
await expect(cmd.handler({} as any)).resolves.toBeUndefined();
expect(getExecutedMigrations.mock.calls.length).toBe(1);
expect(closeSpy).toHaveBeenCalledTimes(1);
});
});