|
| 1 | +import { WorkflowStep, WorkflowVersion } from '@/workflow/types/Workflow'; |
| 2 | +import { removeStep } from '../removeStep'; |
| 3 | + |
| 4 | +it('returns a deep copy of the provided steps array instead of mutating it', () => { |
| 5 | + const stepToBeRemoved = { |
| 6 | + id: 'step-1', |
| 7 | + name: '', |
| 8 | + settings: { |
| 9 | + errorHandlingOptions: { |
| 10 | + retryOnFailure: { value: true }, |
| 11 | + continueOnFailure: { value: false }, |
| 12 | + }, |
| 13 | + serverlessFunctionId: 'first', |
| 14 | + }, |
| 15 | + type: 'CODE', |
| 16 | + valid: true, |
| 17 | + } satisfies WorkflowStep; |
| 18 | + const workflowVersionInitial = { |
| 19 | + __typename: 'WorkflowVersion', |
| 20 | + status: 'ACTIVE', |
| 21 | + createdAt: '', |
| 22 | + id: '1', |
| 23 | + name: '', |
| 24 | + steps: [stepToBeRemoved], |
| 25 | + trigger: { |
| 26 | + settings: { eventName: 'company.created' }, |
| 27 | + type: 'DATABASE_EVENT', |
| 28 | + }, |
| 29 | + updatedAt: '', |
| 30 | + workflowId: '', |
| 31 | + } satisfies WorkflowVersion; |
| 32 | + |
| 33 | + const stepsUpdated = removeStep({ |
| 34 | + steps: workflowVersionInitial.steps, |
| 35 | + stepId: stepToBeRemoved.id, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(workflowVersionInitial.steps).not.toBe(stepsUpdated); |
| 39 | +}); |
| 40 | + |
| 41 | +it('removes a step in a non-empty steps array', () => { |
| 42 | + const stepToBeRemoved: WorkflowStep = { |
| 43 | + id: 'step-2', |
| 44 | + name: '', |
| 45 | + settings: { |
| 46 | + errorHandlingOptions: { |
| 47 | + retryOnFailure: { value: true }, |
| 48 | + continueOnFailure: { value: false }, |
| 49 | + }, |
| 50 | + serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', |
| 51 | + }, |
| 52 | + type: 'CODE', |
| 53 | + valid: true, |
| 54 | + }; |
| 55 | + const workflowVersionInitial = { |
| 56 | + __typename: 'WorkflowVersion', |
| 57 | + status: 'ACTIVE', |
| 58 | + createdAt: '', |
| 59 | + id: '1', |
| 60 | + name: '', |
| 61 | + steps: [ |
| 62 | + { |
| 63 | + id: 'step-1', |
| 64 | + name: '', |
| 65 | + settings: { |
| 66 | + errorHandlingOptions: { |
| 67 | + retryOnFailure: { value: true }, |
| 68 | + continueOnFailure: { value: false }, |
| 69 | + }, |
| 70 | + serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', |
| 71 | + }, |
| 72 | + type: 'CODE', |
| 73 | + valid: true, |
| 74 | + }, |
| 75 | + stepToBeRemoved, |
| 76 | + { |
| 77 | + id: 'step-3', |
| 78 | + name: '', |
| 79 | + settings: { |
| 80 | + errorHandlingOptions: { |
| 81 | + retryOnFailure: { value: true }, |
| 82 | + continueOnFailure: { value: false }, |
| 83 | + }, |
| 84 | + serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997', |
| 85 | + }, |
| 86 | + type: 'CODE', |
| 87 | + valid: true, |
| 88 | + }, |
| 89 | + ], |
| 90 | + trigger: { |
| 91 | + settings: { eventName: 'company.created' }, |
| 92 | + type: 'DATABASE_EVENT', |
| 93 | + }, |
| 94 | + updatedAt: '', |
| 95 | + workflowId: '', |
| 96 | + } satisfies WorkflowVersion; |
| 97 | + |
| 98 | + const stepsUpdated = removeStep({ |
| 99 | + steps: workflowVersionInitial.steps, |
| 100 | + stepId: stepToBeRemoved.id, |
| 101 | + }); |
| 102 | + |
| 103 | + const expectedUpdatedSteps: Array<WorkflowStep> = [ |
| 104 | + workflowVersionInitial.steps[0], |
| 105 | + workflowVersionInitial.steps[2], |
| 106 | + ]; |
| 107 | + expect(stepsUpdated).toEqual(expectedUpdatedSteps); |
| 108 | +}); |
0 commit comments