fix(core): Prevent multiple values in the execution metadata for the same key and executionId (#9953)

This commit is contained in:
Danny Martini
2024-07-10 12:47:43 +02:00
committed by GitHub
parent 3a179439c7
commit 2e6b03b2cb
9 changed files with 203 additions and 15 deletions

View File

@@ -0,0 +1,55 @@
import * as testDb from '../shared/testDb';
import Container from 'typedi';
import { ExecutionMetadataRepository } from '@/databases/repositories/executionMetadata.repository';
import { ExecutionMetadataService } from '@/services/executionMetadata.service';
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);
});
});
});

View File

@@ -15,20 +15,26 @@ describe('ExecutionMetadataService', () => {
await Container.get(ExecutionMetadataService).save(executionId, toSave);
expect(repository.save).toHaveBeenCalledTimes(1);
expect(repository.save.mock.calls[0]).toEqual([
expect(repository.upsert).toHaveBeenCalledTimes(1);
expect(repository.upsert.mock.calls[0]).toEqual([
[
{
execution: { id: executionId },
executionId,
key: 'test1',
value: 'value1',
},
{
execution: { id: executionId },
executionId,
key: 'test2',
value: 'value2',
},
],
{
conflictPaths: {
executionId: true,
key: true,
},
},
]);
});
});