-
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.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
.../twenty-front/src/modules/workflow/hooks/__tests__/useGetUpdatableWorkflowVersion.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,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'); | ||
}); | ||
}); |
File renamed without changes.