First batch of modules/activities tests (#4446)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useCompleteTask } from '@/activities/tasks/hooks/useCompleteTask';
|
||||
|
||||
const mockUpdateOneRecord = jest.fn();
|
||||
jest.mock('@/object-record/hooks/useUpdateOneRecord', () => ({
|
||||
useUpdateOneRecord: () => ({
|
||||
updateOneRecord: mockUpdateOneRecord,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('useCompleteTask', () => {
|
||||
it('should complete the task when called with true', async () => {
|
||||
const taskId = 'test-task-id';
|
||||
const { result } = renderHook(() =>
|
||||
useCompleteTask({ id: taskId, completedAt: null }),
|
||||
);
|
||||
|
||||
const { completeTask } = result.current;
|
||||
completeTask(true);
|
||||
|
||||
expect(mockUpdateOneRecord).toHaveBeenCalledWith({
|
||||
idToUpdate: taskId,
|
||||
updateOneRecordInput: {
|
||||
completedAt: expect.any(String),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should uncomplete the task when called with false', async () => {
|
||||
const taskId = 'test-task-id';
|
||||
const { result } = renderHook(() =>
|
||||
useCompleteTask({ id: taskId, completedAt: '2021-01-01T00:00:00' }),
|
||||
);
|
||||
|
||||
const { completeTask } = result.current;
|
||||
|
||||
completeTask(false);
|
||||
|
||||
expect(mockUpdateOneRecord).toHaveBeenCalledWith({
|
||||
idToUpdate: taskId,
|
||||
updateOneRecordInput: {
|
||||
completedAt: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user