-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Fix workflow tagging failure due to unique constraint check (
- Loading branch information
Showing
3 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/cli/test/integration/workflow-tag-mapping.repository.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import Container from 'typedi'; | ||
|
||
import * as testDb from './shared/testDb'; | ||
import { WorkflowTagMappingRepository } from '@/databases/repositories/workflowTagMapping.repository'; | ||
import { createWorkflow } from './shared/db/workflows'; | ||
import { TagRepository } from '@/databases/repositories/tag.repository'; | ||
|
||
describe('WorkflowTagMappingRepository', () => { | ||
let taggingRepository: WorkflowTagMappingRepository; | ||
let tagRepository: TagRepository; | ||
|
||
beforeAll(async () => { | ||
await testDb.init(); | ||
|
||
taggingRepository = Container.get(WorkflowTagMappingRepository); | ||
tagRepository = Container.get(TagRepository); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testDb.truncate(['WorkflowTagMapping', 'Workflow', 'Tag']); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testDb.terminate(); | ||
}); | ||
|
||
describe('overwriteTaggings', () => { | ||
test('should overwrite taggings in a workflow', async () => { | ||
const workflow = await createWorkflow(); | ||
|
||
const oldTags = await tagRepository.save( | ||
['tag1', 'tag2'].map((name) => tagRepository.create({ name })), | ||
); | ||
|
||
const oldTaggings = oldTags.map((tag) => | ||
taggingRepository.create({ | ||
tagId: tag.id, | ||
workflowId: workflow.id, | ||
}), | ||
); | ||
|
||
await taggingRepository.save(oldTaggings); | ||
|
||
const newTags = await tagRepository.save( | ||
['tag3', 'tag4'].map((name) => tagRepository.create({ name })), | ||
); | ||
|
||
await taggingRepository.overwriteTaggings( | ||
workflow.id, | ||
newTags.map((t) => t.id), | ||
); | ||
|
||
const taggings = await taggingRepository.findBy({ workflowId: workflow.id }); | ||
|
||
expect(taggings).toHaveLength(2); | ||
|
||
const [firstNewTag, secondNewTag] = newTags; | ||
|
||
expect(taggings).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ tagId: firstNewTag.id, workflowId: workflow.id }), | ||
expect.objectContaining({ tagId: secondNewTag.id, workflowId: workflow.id }), | ||
]), | ||
); | ||
}); | ||
|
||
test('should delete taggings if no tags are provided', async () => { | ||
const workflow = await createWorkflow(); | ||
|
||
const oldTags = await tagRepository.save( | ||
['tag1', 'tag2'].map((name) => tagRepository.create({ name })), | ||
); | ||
|
||
const oldTaggings = oldTags.map((tag) => | ||
taggingRepository.create({ | ||
tagId: tag.id, | ||
workflowId: workflow.id, | ||
}), | ||
); | ||
|
||
await taggingRepository.save(oldTaggings); | ||
|
||
await taggingRepository.overwriteTaggings(workflow.id, []); | ||
|
||
const taggings = await taggingRepository.findBy({ workflowId: workflow.id }); | ||
|
||
expect(taggings).toHaveLength(0); | ||
}); | ||
}); | ||
}); |