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 index c2fb315bbd90..d866c9aef535 100644 --- a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts +++ b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts @@ -5,6 +5,13 @@ import { useDeleteStep } from '@/workflow/hooks/useDeleteStep'; const mockCloseRightDrawer = jest.fn(); const mockCreateNewWorkflowVersion = jest.fn(); const mockDeleteWorkflowVersionStep = jest.fn(); +const updateOneRecordMock = jest.fn(); + +jest.mock('@/object-record/hooks/useUpdateOneRecord', () => ({ + useUpdateOneRecord: () => ({ + updateOneRecord: updateOneRecordMock, + }), +})); jest.mock('recoil', () => ({ useRecoilValue: () => 'parent-step-id', diff --git a/packages/twenty-front/src/modules/workflow/hooks/__tests__/useGetUpdatableWorkflowVersion.test.ts b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useGetUpdatableWorkflowVersion.test.ts new file mode 100644 index 000000000000..295de8110b32 --- /dev/null +++ b/packages/twenty-front/src/modules/workflow/hooks/__tests__/useGetUpdatableWorkflowVersion.test.ts @@ -0,0 +1,62 @@ +import { renderHook } from '@testing-library/react'; +import { useGetUpdatableWorkflowVersion } from '@/workflow/hooks/useGetUpdatableWorkflowVersion'; +import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; + +const mockCreateNewWorkflowVersion = jest.fn().mockResolvedValue({ + id: '457', + name: 'toto', + createdAt: '2024-07-03T20:03:35.064Z', + updatedAt: '2024-07-03T20:03:35.064Z', + workflowId: '123', + __typename: 'WorkflowVersion', + status: 'DRAFT', + steps: [], + trigger: null, +}); + +jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ + useCreateNewWorkflowVersion: () => ({ + createNewWorkflowVersion: mockCreateNewWorkflowVersion, + }), +})); + +describe('useGetUpdatableWorkflowVersion', () => { + const mockWorkflow = (status: 'ACTIVE' | 'DRAFT') => + ({ + id: '123', + __typename: 'Workflow', + statuses: [], + lastPublishedVersionId: '1', + name: 'toto', + versions: [], + currentVersion: { + id: '456', + name: 'toto', + createdAt: '2024-07-03T20:03:35.064Z', + updatedAt: '2024-07-03T20:03:35.064Z', + workflowId: '123', + __typename: 'WorkflowVersion', + status, + steps: [], + trigger: null, + }, + }) as WorkflowWithCurrentVersion; + + it('should not create workflow version if draft version exists', async () => { + const { result } = renderHook(() => useGetUpdatableWorkflowVersion()); + const workflowVersion = await result.current.getUpdatableWorkflowVersion( + mockWorkflow('DRAFT'), + ); + expect(mockCreateNewWorkflowVersion).not.toHaveBeenCalled(); + expect(workflowVersion.id === '456'); + }); + + it('should create workflow version if no draft version exists', async () => { + const { result } = renderHook(() => useGetUpdatableWorkflowVersion()); + const workflowVersion = await result.current.getUpdatableWorkflowVersion( + mockWorkflow('ACTIVE'), + ); + expect(mockCreateNewWorkflowVersion).toHaveBeenCalled(); + expect(workflowVersion.id === '457'); + }); +}); diff --git a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.tsx b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.ts similarity index 100% rename from packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.tsx rename to packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.ts