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.
51 lines (39 loc) • 1.95 kB
text/typescript
(global as any).process.env.FORCE_COLOR = 0;
import { MikroORM } from '@mikro-orm/core';
import { SchemaGenerator, SqliteDriver } from '@mikro-orm/sqlite';
import { CLIHelper } from '@mikro-orm/cli';
import { SchemaCommandFactory } from '../../../packages/cli/src/commands/SchemaCommandFactory';
import { initORMSqlite } from '../../bootstrap';
const closeSpy = jest.spyOn(MikroORM.prototype, 'close');
const showHelpMock = jest.spyOn(CLIHelper, 'showHelp');
showHelpMock.mockImplementation(() => void 0);
const updateSchema = jest.spyOn(SchemaGenerator.prototype, 'updateSchema');
updateSchema.mockImplementation(async () => void 0);
const getUpdateSchemaSQL = jest.spyOn(SchemaGenerator.prototype, 'getUpdateSchemaSQL');
getUpdateSchemaSQL.mockImplementation(async () => '');
const dumpMock = jest.spyOn(CLIHelper, 'dump');
dumpMock.mockImplementation(() => void 0);
describe('UpdateSchemaCommand', () => {
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('handler', async () => {
const cmd = SchemaCommandFactory.create('update');
expect(showHelpMock.mock.calls.length).toBe(0);
await expect(cmd.handler({} as any)).resolves.toBeUndefined();
expect(showHelpMock.mock.calls.length).toBe(1);
expect(updateSchema.mock.calls.length).toBe(0);
expect(closeSpy).toHaveBeenCalledTimes(0);
await expect(cmd.handler({ run: true } as any)).resolves.toBeUndefined();
expect(updateSchema.mock.calls.length).toBe(1);
expect(closeSpy).toHaveBeenCalledTimes(1);
expect(getUpdateSchemaSQL.mock.calls.length).toBe(0);
await expect(cmd.handler({ dump: true } as any)).resolves.toBeUndefined();
expect(getUpdateSchemaSQL.mock.calls.length).toBe(1);
expect(closeSpy).toHaveBeenCalledTimes(2);
});
});