n8n/packages/cli/test/unit/repositories/execution.repository.test.ts
कारतोफ्फेलस्क्रिप्ट™ ff77ef4b62
ci: Delete some duplicate code in cli tests (no-changelog) (#9049)
2024-04-05 13:47:49 +02:00

47 lines
1.3 KiB
TypeScript

import Container from 'typedi';
import { Not, LessThanOrEqual } from '@n8n/typeorm';
import config from '@/config';
import { ExecutionEntity } from '@db/entities/ExecutionEntity';
import { ExecutionRepository } from '@db/repositories/execution.repository';
import { mockEntityManager } from '../../shared/mocking';
describe('ExecutionRepository', () => {
const entityManager = mockEntityManager(ExecutionEntity);
const executionRepository = Container.get(ExecutionRepository);
const mockDate = new Date('2023-12-28 12:34:56.789Z');
beforeAll(() => {
jest.clearAllMocks();
jest.useFakeTimers().setSystemTime(mockDate);
});
afterAll(() => jest.useRealTimers());
describe('getWaitingExecutions()', () => {
test.each(['sqlite', 'postgres'])(
'on %s, should be called with expected args',
async (dbType) => {
jest.spyOn(config, 'getEnv').mockReturnValueOnce(dbType);
entityManager.find.mockResolvedValueOnce([]);
await executionRepository.getWaitingExecutions();
expect(entityManager.find).toHaveBeenCalledWith(ExecutionEntity, {
order: { waitTill: 'ASC' },
select: ['id', 'waitTill'],
where: {
status: Not('crashed'),
waitTill: LessThanOrEqual(
dbType === 'sqlite'
? '2023-12-28 12:36:06.789'
: new Date('2023-12-28T12:36:06.789Z'),
),
},
});
},
);
});
});