2023-12-28 10:22:09 -08:00
|
|
|
import Container from 'typedi';
|
2024-04-05 04:47:49 -07:00
|
|
|
import { Not, LessThanOrEqual } from '@n8n/typeorm';
|
2023-12-28 10:22:09 -08:00
|
|
|
|
|
|
|
import config from '@/config';
|
|
|
|
import { ExecutionEntity } from '@db/entities/ExecutionEntity';
|
|
|
|
import { ExecutionRepository } from '@db/repositories/execution.repository';
|
|
|
|
|
2024-04-05 04:47:49 -07:00
|
|
|
import { mockEntityManager } from '../../shared/mocking';
|
2023-12-28 10:22:09 -08:00
|
|
|
|
|
|
|
describe('ExecutionRepository', () => {
|
2024-04-05 04:47:49 -07:00
|
|
|
const entityManager = mockEntityManager(ExecutionEntity);
|
2023-12-28 10:22:09 -08:00
|
|
|
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'),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|