260323:0954 fix CI : Run Tests frontend #01
CI / CD Pipeline / build (push) Failing after 15m27s
CI / CD Pipeline / release (push) Has been skipped
CI / CD Pipeline / deploy (push) Has been skipped

This commit is contained in:
admin
2026-03-23 09:54:31 +07:00
parent 4422c68894
commit 32141f519a
8 changed files with 563 additions and 1073 deletions
+14 -14
View File
@@ -9,7 +9,7 @@ import { toast } from 'sonner';
vi.mock('@/lib/services/rfa.service', () => ({
rfaService: {
getAll: vi.fn(),
getById: vi.fn(),
getByUuid: vi.fn(),
create: vi.fn(),
update: vi.fn(),
processWorkflow: vi.fn(),
@@ -27,7 +27,7 @@ describe('use-rfa hooks', () => {
expect(rfaKeys.lists()).toEqual(['rfas', 'list']);
expect(rfaKeys.list({ projectId: 1 })).toEqual(['rfas', 'list', { projectId: 1 }]);
expect(rfaKeys.details()).toEqual(['rfas', 'detail']);
expect(rfaKeys.detail(1)).toEqual(['rfas', 'detail', 1]);
expect(rfaKeys.detail('uuid-1')).toEqual(['rfas', 'detail', 'uuid-1']);
});
});
@@ -67,27 +67,27 @@ describe('use-rfa hooks', () => {
});
describe('useRFA', () => {
it('should fetch single RFA by id', async () => {
const mockData = { id: 1, rfaNumber: 'RFA-001', status: 'pending' };
vi.mocked(rfaService.getById).mockResolvedValue(mockData);
it('should fetch single RFA by uuid', async () => {
const mockData = { id: 1, uuid: 'uuid-1', rfaNumber: 'RFA-001', status: 'pending' };
vi.mocked(rfaService.getByUuid).mockResolvedValue(mockData);
const { wrapper } = createTestQueryClient();
const { result } = renderHook(() => useRFA(1), { wrapper });
const { result } = renderHook(() => useRFA('uuid-1'), { wrapper });
await waitFor(() => {
expect(result.current.isSuccess).toBe(true);
});
expect(result.current.data).toEqual(mockData);
expect(rfaService.getById).toHaveBeenCalledWith(1);
expect(rfaService.getByUuid).toHaveBeenCalledWith('uuid-1');
});
it('should not fetch when id is falsy', () => {
it('should not fetch when uuid is falsy', () => {
const { wrapper } = createTestQueryClient();
const { result } = renderHook(() => useRFA(0), { wrapper });
const { result } = renderHook(() => useRFA(''), { wrapper });
expect(result.current.isFetching).toBe(false);
expect(rfaService.getById).not.toHaveBeenCalled();
expect(rfaService.getByUuid).not.toHaveBeenCalled();
});
});
@@ -151,12 +151,12 @@ describe('use-rfa hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
uuid: 'uuid-1',
data: { subject: 'Updated RFA' },
});
});
expect(rfaService.update).toHaveBeenCalledWith(1, { subject: 'Updated RFA' });
expect(rfaService.update).toHaveBeenCalledWith('uuid-1', { subject: 'Updated RFA' });
expect(toast.success).toHaveBeenCalledWith('RFA updated successfully');
});
});
@@ -171,12 +171,12 @@ describe('use-rfa hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
uuid: 'uuid-1',
data: { action: 'APPROVE', comments: 'Approved' },
});
});
expect(rfaService.processWorkflow).toHaveBeenCalledWith(1, {
expect(rfaService.processWorkflow).toHaveBeenCalledWith('uuid-1', {
action: 'APPROVE',
comments: 'Approved',
});