2024-08-28 04:59:27 -07:00
|
|
|
import * as testDb from '../shared/test-db';
|
2024-07-10 03:47:43 -07:00
|
|
|
import Container from 'typedi';
|
2024-08-27 07:44:32 -07:00
|
|
|
import { ExecutionMetadataRepository } from '@/databases/repositories/execution-metadata.repository';
|
2024-08-28 04:59:27 -07:00
|
|
|
import { ExecutionMetadataService } from '@/services/execution-metadata.service';
|
2024-07-10 03:47:43 -07:00
|
|
|
import { createExecution } from '@test-integration/db/executions';
|
|
|
|
import { createWorkflow } from '@test-integration/db/workflows';
|
|
|
|
|
|
|
|
let executionMetadataRepository: ExecutionMetadataRepository;
|
|
|
|
let executionMetadataService: ExecutionMetadataService;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await testDb.init();
|
|
|
|
|
|
|
|
executionMetadataRepository = Container.get(ExecutionMetadataRepository);
|
|
|
|
executionMetadataService = Container.get(ExecutionMetadataService);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await testDb.terminate();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await testDb.truncate(['User']);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('ProjectService', () => {
|
|
|
|
describe('save', () => {
|
|
|
|
it('should deduplicate entries by exeuctionId and key, keeping the latest one', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const workflow = await createWorkflow();
|
|
|
|
const execution = await createExecution({}, workflow);
|
|
|
|
const key = 'key';
|
|
|
|
const value1 = 'value1';
|
|
|
|
const value2 = 'value2';
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
await executionMetadataService.save(execution.id, { [key]: value1 });
|
|
|
|
await executionMetadataService.save(execution.id, { [key]: value2 });
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
const rows = await executionMetadataRepository.find({
|
|
|
|
where: { executionId: execution.id, key },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(rows).toHaveLength(1);
|
|
|
|
expect(rows[0]).toHaveProperty('value', value2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|