Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Dec 2, 2024
1 parent 4fc5f58 commit 11b0ea1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 11b0ea1

Please sign in to comment.