mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Prevent multiple values in the execution metadata for the same key and executionId (#9953)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user