Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Dec 2, 2024
1 parent be26ee6 commit ecf5e2d
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand All @@ -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,
}),
}));

Expand All @@ -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',
Expand All @@ -75,7 +52,7 @@ describe('useCreateStep', () => {
);
await result.current.createStep('CODE');

expect(mockUpdateOneWorkflowVersion).toHaveBeenCalled();
expect(mockCreateWorkflowVersionStep).toHaveBeenCalled();
expect(mockOpenRightDrawer).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit ecf5e2d

Please sign in to comment.