From ecf5e2dacdad692ab0b6d0ff2437803058127298 Mon Sep 17 00:00:00 2001 From: martmull Date: Mon, 2 Dec 2024 11:03:43 +0100 Subject: [PATCH] Fix test --- .../hooks/__tests__/useCreateStep.test.ts | 35 ++-------- .../hooks/__tests__/useDeleteStep.test.ts | 55 +++++++++++++++ .../hooks/__tests__/useUpdateStep.test.ts | 69 +++++++++++++++++++ 3 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts create mode 100644 packages/twenty-front/src/modules/workflow/hooks/__tests__/useUpdateStep.test.ts diff --git a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useCreateStep.test.ts b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useCreateStep.test.ts index 896dde10d653..78ea61435f1a 100644 --- a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useCreateStep.test.ts +++ b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useCreateStep.test.ts @@ -3,10 +3,9 @@ import { renderHook } from '@testing-library/react'; import { useCreateStep } from '../useCreateStep'; const mockOpenRightDrawer = jest.fn(); -const mockUpdateOneWorkflowVersion = jest.fn(); const mockCreateNewWorkflowVersion = jest.fn(); -const mockComputeStepOutputSchema = jest.fn().mockResolvedValue({ - data: { computeStepOutputSchema: { type: 'object' } }, +const mockCreateWorkflowVersionStep = jest.fn().mockResolvedValue({ + data: { createWorkflowVersionStep: { id: '1' } }, }); jest.mock('recoil', () => ({ @@ -15,19 +14,15 @@ jest.mock('recoil', () => ({ atom: (params: any) => params, })); -jest.mock('@/workflow/states/workflowCreateStepFromParentStepIdState', () => ({ - workflowCreateStepFromParentStepIdState: 'mockAtomState', -})); - jest.mock('@/ui/layout/right-drawer/hooks/useRightDrawer', () => ({ useRightDrawer: () => ({ openRightDrawer: mockOpenRightDrawer, }), })); -jest.mock('@/object-record/hooks/useUpdateOneRecord', () => ({ - useUpdateOneRecord: () => ({ - updateOneRecord: mockUpdateOneWorkflowVersion, +jest.mock('@/workflow/hooks/useCreateWorkflowVersionStep', () => ({ + useCreateWorkflowVersionStep: () => ({ + createWorkflowVersionStep: mockCreateWorkflowVersionStep, }), })); @@ -37,24 +32,6 @@ jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ }), })); -jest.mock('@/workflow/hooks/useComputeStepOutputSchema', () => ({ - useComputeStepOutputSchema: () => ({ - computeStepOutputSchema: mockComputeStepOutputSchema, - }), -})); - -jest.mock('@/object-metadata/hooks/useFilteredObjectMetadataItems', () => ({ - useFilteredObjectMetadataItems: () => ({ - activeObjectMetadataItems: [], - }), -})); - -jest.mock('@/workflow/utils/insertStep', () => ({ - insertStep: jest - .fn() - .mockImplementation(({ steps, stepToAdd }) => [...steps, stepToAdd]), -})); - describe('useCreateStep', () => { const mockWorkflow = { id: '123', @@ -75,7 +52,7 @@ describe('useCreateStep', () => { ); await result.current.createStep('CODE'); - expect(mockUpdateOneWorkflowVersion).toHaveBeenCalled(); + expect(mockCreateWorkflowVersionStep).toHaveBeenCalled(); expect(mockOpenRightDrawer).toHaveBeenCalled(); }); }); diff --git a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts new file mode 100644 index 000000000000..c2fb315bbd90 --- /dev/null +++ b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts @@ -0,0 +1,55 @@ +import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; +import { renderHook } from '@testing-library/react'; +import { useDeleteStep } from '@/workflow/hooks/useDeleteStep'; + +const mockCloseRightDrawer = jest.fn(); +const mockCreateNewWorkflowVersion = jest.fn(); +const mockDeleteWorkflowVersionStep = jest.fn(); + +jest.mock('recoil', () => ({ + useRecoilValue: () => 'parent-step-id', + useSetRecoilState: () => jest.fn(), + atom: (params: any) => params, +})); + +jest.mock('@/ui/layout/right-drawer/hooks/useRightDrawer', () => ({ + useRightDrawer: () => ({ + closeRightDrawer: mockCloseRightDrawer, + }), +})); + +jest.mock('@/workflow/hooks/useDeleteWorkflowVersionStep', () => ({ + useDeleteWorkflowVersionStep: () => ({ + deleteWorkflowVersionStep: mockDeleteWorkflowVersionStep, + }), +})); + +jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ + useCreateNewWorkflowVersion: () => ({ + createNewWorkflowVersion: mockCreateNewWorkflowVersion, + }), +})); + +describe('useDeleteStep', () => { + const mockWorkflow = { + id: '123', + currentVersion: { + id: '456', + status: 'DRAFT', + steps: [], + trigger: { type: 'manual' }, + }, + versions: [], + }; + + it('should delete step in draft version', async () => { + const { result } = renderHook(() => + useDeleteStep({ + workflow: mockWorkflow as unknown as WorkflowWithCurrentVersion, + }), + ); + await result.current.deleteStep('1'); + + expect(mockDeleteWorkflowVersionStep).toHaveBeenCalled(); + }); +}); diff --git a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useUpdateStep.test.ts b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useUpdateStep.test.ts new file mode 100644 index 000000000000..1f23cb309430 --- /dev/null +++ b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useUpdateStep.test.ts @@ -0,0 +1,69 @@ +import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; +import { renderHook } from '@testing-library/react'; +import { useUpdateStep } from '@/workflow/hooks/useUpdateStep'; + +const mockCreateNewWorkflowVersion = jest.fn(); +const mockUpdateWorkflowVersionStep = jest.fn(); + +jest.mock('recoil', () => ({ + useRecoilValue: () => 'parent-step-id', + useSetRecoilState: () => jest.fn(), + atom: (params: any) => params, +})); + +jest.mock('@/workflow/hooks/useUpdateWorkflowVersionStep', () => ({ + useUpdateWorkflowVersionStep: () => ({ + updateWorkflowVersionStep: mockUpdateWorkflowVersionStep, + }), +})); + +jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ + useCreateNewWorkflowVersion: () => ({ + createNewWorkflowVersion: mockCreateNewWorkflowVersion, + }), +})); + +describe('useUpdateStep', () => { + const mockWorkflow = { + id: '123', + currentVersion: { + id: '456', + status: 'DRAFT', + steps: [], + trigger: { type: 'manual' }, + }, + versions: [], + }; + + it('should update step in draft version', async () => { + const { result } = renderHook(() => + useUpdateStep({ + workflow: mockWorkflow as unknown as WorkflowWithCurrentVersion, + }), + ); + await result.current.updateStep({ + id: '1', + name: 'name', + valid: true, + type: 'CODE', + settings: { + input: { + serverlessFunctionId: 'id', + serverlessFunctionVersion: '1', + serverlessFunctionInput: {}, + }, + outputSchema: {}, + errorHandlingOptions: { + retryOnFailure: { + value: true, + }, + continueOnFailure: { + value: true, + }, + }, + }, + }); + + expect(mockUpdateWorkflowVersionStep).toHaveBeenCalled(); + }); +});