-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: write tests for complex workflows business functions
- Loading branch information
Showing
5 changed files
with
155 additions
and
11 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
packages/twenty-front/src/modules/workflow/utils/__tests__/addCreateStepNodes.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,63 @@ | ||
import { WorkflowStep, WorkflowTrigger } from '@/workflow/types/Workflow'; | ||
import { generateWorkflowDiagram } from '@/workflow/utils/generateWorkflowDiagram'; | ||
import { addCreateStepNodes } from '../addCreateStepNodes'; | ||
|
||
describe('addCreateStepNodes', () => { | ||
it("adds a create step node to the end of a single-branch flow and doesn't change the shape of other nodes", () => { | ||
const trigger: WorkflowTrigger = { | ||
type: 'DATABASE_EVENT', | ||
settings: { | ||
eventName: 'company.created', | ||
}, | ||
}; | ||
const steps: WorkflowStep[] = [ | ||
{ | ||
id: 'step1', | ||
name: 'Step 1', | ||
type: 'CODE_ACTION', | ||
valid: true, | ||
settings: { | ||
errorHandlingOptions: { | ||
retryOnFailure: { value: true }, | ||
continueOnFailure: { value: false }, | ||
}, | ||
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', | ||
}, | ||
}, | ||
{ | ||
id: 'step2', | ||
name: 'Step 2', | ||
type: 'CODE_ACTION', | ||
valid: true, | ||
settings: { | ||
errorHandlingOptions: { | ||
retryOnFailure: { value: true }, | ||
continueOnFailure: { value: false }, | ||
}, | ||
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', | ||
}, | ||
}, | ||
]; | ||
|
||
const diagramInitial = generateWorkflowDiagram({ trigger, steps }); | ||
|
||
expect(diagramInitial.nodes).toHaveLength(3); | ||
expect(diagramInitial.edges).toHaveLength(2); | ||
|
||
const diagramWithCreateStepNodes = addCreateStepNodes(diagramInitial); | ||
|
||
expect(diagramWithCreateStepNodes.nodes).toHaveLength(4); | ||
expect(diagramWithCreateStepNodes.edges).toHaveLength(3); | ||
|
||
expect(diagramWithCreateStepNodes.nodes[0].type).toBe(undefined); | ||
expect(diagramWithCreateStepNodes.nodes[0].data.nodeType).toBe('trigger'); | ||
|
||
expect(diagramWithCreateStepNodes.nodes[1].type).toBe(undefined); | ||
expect(diagramWithCreateStepNodes.nodes[1].data.nodeType).toBe('action'); | ||
|
||
expect(diagramWithCreateStepNodes.nodes[2].type).toBe(undefined); | ||
expect(diagramWithCreateStepNodes.nodes[2].data.nodeType).toBe('action'); | ||
|
||
expect(diagramWithCreateStepNodes.nodes[3].type).toBe('create-step'); | ||
}); | ||
}); |
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
81 changes: 81 additions & 0 deletions
81
...s/twenty-front/src/modules/workflow/utils/__tests__/getWorkflowLastDiagramVersion.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,81 @@ | ||
import { Workflow } from '@/workflow/types/Workflow'; | ||
import { getWorkflowLastDiagramVersion } from '../getWorkflowLastDiagramVersion'; | ||
|
||
describe('getWorkflowLastDiagramVersion', () => { | ||
it('returns an empty diagram if the provided workflow is undefined', () => { | ||
const result = getWorkflowLastDiagramVersion(undefined); | ||
|
||
expect(result).toEqual({ nodes: [], edges: [] }); | ||
}); | ||
|
||
it('returns an empty diagram if the provided workflow has no versions', () => { | ||
const result = getWorkflowLastDiagramVersion({ | ||
__typename: 'Workflow', | ||
id: 'aa', | ||
name: 'aa', | ||
publishedVersionId: '', | ||
versions: [], | ||
}); | ||
|
||
expect(result).toEqual({ nodes: [], edges: [] }); | ||
}); | ||
|
||
it('returns the diagram for the last version', () => { | ||
const workflow: Workflow = { | ||
__typename: 'Workflow', | ||
id: 'aa', | ||
name: 'aa', | ||
publishedVersionId: '', | ||
versions: [ | ||
{ | ||
__typename: 'WorkflowVersion', | ||
createdAt: '', | ||
id: '1', | ||
name: '', | ||
steps: [], | ||
trigger: { | ||
settings: { eventName: 'company.created' }, | ||
type: 'DATABASE_EVENT', | ||
}, | ||
updatedAt: '', | ||
workflowId: '', | ||
}, | ||
{ | ||
__typename: 'WorkflowVersion', | ||
createdAt: '', | ||
id: '1', | ||
name: '', | ||
steps: [ | ||
{ | ||
id: 'step-1', | ||
name: '', | ||
settings: { | ||
errorHandlingOptions: { | ||
retryOnFailure: { value: true }, | ||
continueOnFailure: { value: false }, | ||
}, | ||
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', | ||
}, | ||
type: 'CODE_ACTION', | ||
valid: true, | ||
}, | ||
], | ||
trigger: { | ||
settings: { eventName: 'company.created' }, | ||
type: 'DATABASE_EVENT', | ||
}, | ||
updatedAt: '', | ||
workflowId: '', | ||
}, | ||
], | ||
}; | ||
|
||
const result = getWorkflowLastDiagramVersion(workflow); | ||
|
||
// Corresponds to the trigger + 1 step | ||
expect(result.nodes).toHaveLength(2); | ||
expect(result.edges).toHaveLength(1); | ||
}); | ||
|
||
|
||
}); |
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