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.
35 lines (25 loc) • 1.43 kB
text/typescript
import { Configuration, FileCacheAdapter } from '@mikro-orm/core';
import { MySqlDriver } from '@mikro-orm/mysql';
import { CLIHelper } from '@mikro-orm/cli';
(global as any).console.log = jest.fn();
const getConfigurationMock = jest.spyOn(CLIHelper, 'getConfiguration');
getConfigurationMock.mockResolvedValue(new Configuration({ driver: MySqlDriver, metadataCache: { enabled: true }, getDriver: () => ({ getPlatform: jest.fn() }) } as any, false));
const clearMock = jest.spyOn(FileCacheAdapter.prototype, 'clear');
import { ClearCacheCommand } from '../../../packages/cli/src/commands/ClearCacheCommand';
describe('ClearCacheCommand', () => {
test('handler', async () => {
const cmd = new ClearCacheCommand();
expect(clearMock.mock.calls.length).toBe(0);
await expect(cmd.handler({} as any)).resolves.toBeUndefined();
expect(clearMock.mock.calls.length).toBe(1);
});
test('handler warns when cache is disabled', async () => {
clearMock.mockClear();
getConfigurationMock.mockClear();
getConfigurationMock.mockResolvedValue(new Configuration({ driver: MySqlDriver, metadataCache: { enabled: false }, getDriver: () => ({ getPlatform: jest.fn() }) } as any, false));
const cmd = new ClearCacheCommand();
expect(clearMock.mock.calls.length).toBe(0);
await expect(cmd.handler({} as any)).resolves.toBeUndefined();
expect(clearMock.mock.calls.length).toBe(0);
});
});