260323:0954 fix CI : Run Tests frontend #01
This commit is contained in:
@@ -18,7 +18,7 @@ import { toast } from 'sonner';
|
||||
vi.mock('@/lib/services/correspondence.service', () => ({
|
||||
correspondenceService: {
|
||||
getAll: vi.fn(),
|
||||
getById: vi.fn(),
|
||||
getByUuid: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
@@ -38,7 +38,7 @@ describe('use-correspondence hooks', () => {
|
||||
expect(correspondenceKeys.lists()).toEqual(['correspondences', 'list']);
|
||||
expect(correspondenceKeys.list({ projectId: 1 })).toEqual(['correspondences', 'list', { projectId: 1 }]);
|
||||
expect(correspondenceKeys.details()).toEqual(['correspondences', 'detail']);
|
||||
expect(correspondenceKeys.detail(1)).toEqual(['correspondences', 'detail', 1]);
|
||||
expect(correspondenceKeys.detail('uuid-1')).toEqual(['correspondences', 'detail', 'uuid-1']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,27 +81,27 @@ describe('use-correspondence hooks', () => {
|
||||
});
|
||||
|
||||
describe('useCorrespondence', () => {
|
||||
it('should fetch single correspondence by id', async () => {
|
||||
const mockData = { id: 1, title: 'Test Correspondence' };
|
||||
vi.mocked(correspondenceService.getById).mockResolvedValue(mockData);
|
||||
it('should fetch single correspondence by uuid', async () => {
|
||||
const mockData = { id: 1, uuid: 'uuid-1', title: 'Test Correspondence' };
|
||||
vi.mocked(correspondenceService.getByUuid).mockResolvedValue(mockData);
|
||||
|
||||
const { wrapper } = createTestQueryClient();
|
||||
const { result } = renderHook(() => useCorrespondence(1), { wrapper });
|
||||
const { result } = renderHook(() => useCorrespondence('uuid-1'), { wrapper });
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
});
|
||||
|
||||
expect(result.current.data).toEqual(mockData);
|
||||
expect(correspondenceService.getById).toHaveBeenCalledWith(1);
|
||||
expect(correspondenceService.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(() => useCorrespondence(0), { wrapper });
|
||||
const { result } = renderHook(() => useCorrespondence(''), { wrapper });
|
||||
|
||||
expect(result.current.isFetching).toBe(false);
|
||||
expect(correspondenceService.getById).not.toHaveBeenCalled();
|
||||
expect(correspondenceService.getByUuid).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -173,12 +173,12 @@ describe('use-correspondence hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { subject: 'Updated Correspondence' },
|
||||
});
|
||||
});
|
||||
|
||||
expect(correspondenceService.update).toHaveBeenCalledWith(1, {
|
||||
expect(correspondenceService.update).toHaveBeenCalledWith('uuid-1', {
|
||||
subject: 'Updated Correspondence',
|
||||
});
|
||||
expect(toast.success).toHaveBeenCalledWith('Correspondence updated successfully');
|
||||
@@ -193,10 +193,10 @@ describe('use-correspondence hooks', () => {
|
||||
const { result } = renderHook(() => useDeleteCorrespondence(), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync(1);
|
||||
await result.current.mutateAsync('uuid-1');
|
||||
});
|
||||
|
||||
expect(correspondenceService.delete).toHaveBeenCalledWith(1);
|
||||
expect(correspondenceService.delete).toHaveBeenCalledWith('uuid-1');
|
||||
expect(toast.success).toHaveBeenCalledWith('Correspondence deleted successfully');
|
||||
});
|
||||
});
|
||||
@@ -211,12 +211,12 @@ describe('use-correspondence hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { note: 'Ready for review' },
|
||||
});
|
||||
});
|
||||
|
||||
expect(correspondenceService.submit).toHaveBeenCalledWith(1, { note: 'Ready for review' });
|
||||
expect(correspondenceService.submit).toHaveBeenCalledWith('uuid-1', { note: 'Ready for review' });
|
||||
expect(toast.success).toHaveBeenCalledWith('Correspondence submitted successfully');
|
||||
});
|
||||
});
|
||||
@@ -231,12 +231,12 @@ describe('use-correspondence hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { action: 'APPROVE', comments: 'LGTM' },
|
||||
});
|
||||
});
|
||||
|
||||
expect(correspondenceService.processWorkflow).toHaveBeenCalledWith(1, {
|
||||
expect(correspondenceService.processWorkflow).toHaveBeenCalledWith('uuid-1', {
|
||||
action: 'APPROVE',
|
||||
comments: 'LGTM',
|
||||
});
|
||||
@@ -256,7 +256,7 @@ describe('use-correspondence hooks', () => {
|
||||
await act(async () => {
|
||||
try {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { action: 'APPROVE' },
|
||||
});
|
||||
} catch {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { toast } from 'sonner';
|
||||
vi.mock('@/lib/services/contract-drawing.service', () => ({
|
||||
contractDrawingService: {
|
||||
getAll: vi.fn(),
|
||||
getById: vi.fn(),
|
||||
getByUuid: vi.fn(),
|
||||
create: vi.fn(),
|
||||
},
|
||||
}));
|
||||
@@ -18,7 +18,7 @@ vi.mock('@/lib/services/contract-drawing.service', () => ({
|
||||
vi.mock('@/lib/services/shop-drawing.service', () => ({
|
||||
shopDrawingService: {
|
||||
getAll: vi.fn(),
|
||||
getById: vi.fn(),
|
||||
getByUuid: vi.fn(),
|
||||
create: vi.fn(),
|
||||
},
|
||||
}));
|
||||
@@ -38,7 +38,7 @@ describe('use-drawing hooks', () => {
|
||||
'CONTRACT',
|
||||
{ projectId: 1 },
|
||||
]);
|
||||
expect(drawingKeys.detail('SHOP', 1)).toEqual(['drawings', 'detail', 'SHOP', 1]);
|
||||
expect(drawingKeys.detail('SHOP', 'uuid-1')).toEqual(['drawings', 'detail', 'SHOP', 'uuid-1']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,8 +46,8 @@ describe('use-drawing hooks', () => {
|
||||
it('should fetch CONTRACT drawings successfully', async () => {
|
||||
const mockData = {
|
||||
data: [
|
||||
{ id: 1, drawingNumber: 'CD-001' },
|
||||
{ id: 2, drawingNumber: 'CD-002' },
|
||||
{ id: 1, uuid: 'uuid-1', contractDrawingNo: 'CD-001' },
|
||||
{ id: 2, uuid: 'uuid-2', contractDrawingNo: 'CD-002' },
|
||||
],
|
||||
meta: { total: 2, page: 1, limit: 10 },
|
||||
};
|
||||
@@ -61,14 +61,18 @@ describe('use-drawing hooks', () => {
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
});
|
||||
|
||||
expect(result.current.data).toEqual(mockData);
|
||||
expect(result.current.data.data[0]).toMatchObject({
|
||||
uuid: 'uuid-1',
|
||||
drawingNumber: 'CD-001',
|
||||
type: 'CONTRACT',
|
||||
});
|
||||
expect(contractDrawingService.getAll).toHaveBeenCalledWith({ projectId: 1 });
|
||||
expect(shopDrawingService.getAll).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fetch SHOP drawings successfully', async () => {
|
||||
const mockData = {
|
||||
data: [{ id: 1, drawingNumber: 'SD-001' }],
|
||||
data: [{ id: 1, uuid: 'uuid-1' }],
|
||||
meta: { total: 1, page: 1, limit: 10 },
|
||||
};
|
||||
|
||||
@@ -81,7 +85,11 @@ describe('use-drawing hooks', () => {
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
});
|
||||
|
||||
expect(result.current.data).toEqual(mockData);
|
||||
expect(result.current.data.data[0]).toMatchObject({
|
||||
uuid: 'uuid-1',
|
||||
type: 'SHOP',
|
||||
title: 'Untitled',
|
||||
});
|
||||
expect(shopDrawingService.getAll).toHaveBeenCalledWith({ projectId: 1 });
|
||||
expect(contractDrawingService.getAll).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -100,42 +108,42 @@ describe('use-drawing hooks', () => {
|
||||
});
|
||||
|
||||
describe('useDrawing', () => {
|
||||
it('should fetch single CONTRACT drawing by id', async () => {
|
||||
const mockData = { id: 1, drawingNumber: 'CD-001' };
|
||||
vi.mocked(contractDrawingService.getById).mockResolvedValue(mockData);
|
||||
it('should fetch single CONTRACT drawing by uuid', async () => {
|
||||
const mockData = { id: 1, uuid: 'uuid-1', contractDrawingNo: 'CD-001' };
|
||||
vi.mocked(contractDrawingService.getByUuid).mockResolvedValue(mockData);
|
||||
|
||||
const { wrapper } = createTestQueryClient();
|
||||
const { result } = renderHook(() => useDrawing('CONTRACT', 1), { wrapper });
|
||||
const { result } = renderHook(() => useDrawing('CONTRACT', 'uuid-1'), { wrapper });
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
});
|
||||
|
||||
expect(result.current.data).toEqual(mockData);
|
||||
expect(contractDrawingService.getById).toHaveBeenCalledWith(1);
|
||||
expect(contractDrawingService.getByUuid).toHaveBeenCalledWith('uuid-1');
|
||||
});
|
||||
|
||||
it('should fetch single SHOP drawing by id', async () => {
|
||||
const mockData = { id: 1, drawingNumber: 'SD-001' };
|
||||
vi.mocked(shopDrawingService.getById).mockResolvedValue(mockData);
|
||||
it('should fetch single SHOP drawing by uuid', async () => {
|
||||
const mockData = { id: 1, uuid: 'uuid-1', title: 'SD-001' };
|
||||
vi.mocked(shopDrawingService.getByUuid).mockResolvedValue(mockData);
|
||||
|
||||
const { wrapper } = createTestQueryClient();
|
||||
const { result } = renderHook(() => useDrawing('SHOP', 1), { wrapper });
|
||||
const { result } = renderHook(() => useDrawing('SHOP', 'uuid-1'), { wrapper });
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.isSuccess).toBe(true);
|
||||
});
|
||||
|
||||
expect(result.current.data).toEqual(mockData);
|
||||
expect(shopDrawingService.getById).toHaveBeenCalledWith(1);
|
||||
expect(shopDrawingService.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(() => useDrawing('CONTRACT', 0), { wrapper });
|
||||
const { result } = renderHook(() => useDrawing('CONTRACT', ''), { wrapper });
|
||||
|
||||
expect(result.current.isFetching).toBe(false);
|
||||
expect(contractDrawingService.getById).not.toHaveBeenCalled();
|
||||
expect(contractDrawingService.getByUuid).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { toast } from 'sonner';
|
||||
vi.mock('@/lib/services/project.service', () => ({
|
||||
projectService: {
|
||||
getAll: vi.fn(),
|
||||
getById: vi.fn(),
|
||||
getByUuid: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
@@ -25,7 +25,7 @@ describe('use-projects hooks', () => {
|
||||
it('should generate correct cache keys', () => {
|
||||
expect(projectKeys.all).toEqual(['projects']);
|
||||
expect(projectKeys.list({ search: 'test' })).toEqual(['projects', 'list', { search: 'test' }]);
|
||||
expect(projectKeys.detail(1)).toEqual(['projects', 'detail', 1]);
|
||||
expect(projectKeys.detail('uuid-1')).toEqual(['projects', 'detail', 'uuid-1']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -136,12 +136,12 @@ describe('use-projects hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { name: 'Updated Project' },
|
||||
});
|
||||
});
|
||||
|
||||
expect(projectService.update).toHaveBeenCalledWith(1, { name: 'Updated Project' });
|
||||
expect(projectService.update).toHaveBeenCalledWith('uuid-1', { name: 'Updated Project' });
|
||||
expect(toast.success).toHaveBeenCalledWith('Project updated successfully');
|
||||
});
|
||||
|
||||
@@ -158,7 +158,7 @@ describe('use-projects hooks', () => {
|
||||
await act(async () => {
|
||||
try {
|
||||
await result.current.mutateAsync({
|
||||
id: 999,
|
||||
uuid: 'uuid-999',
|
||||
data: { name: 'Test' },
|
||||
});
|
||||
} catch {
|
||||
@@ -180,10 +180,10 @@ describe('use-projects hooks', () => {
|
||||
const { result } = renderHook(() => useDeleteProject(), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync(1);
|
||||
await result.current.mutateAsync('uuid-1');
|
||||
});
|
||||
|
||||
expect(projectService.delete).toHaveBeenCalledWith(1);
|
||||
expect(projectService.delete).toHaveBeenCalledWith('uuid-1');
|
||||
expect(toast.success).toHaveBeenCalledWith('Project deleted successfully');
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ describe('use-projects hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
try {
|
||||
await result.current.mutateAsync(1);
|
||||
await result.current.mutateAsync('uuid-1');
|
||||
} catch {
|
||||
// Expected
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import { toast } from 'sonner';
|
||||
vi.mock('@/lib/services/user.service', () => ({
|
||||
userService: {
|
||||
getAll: vi.fn(),
|
||||
getById: vi.fn(),
|
||||
getByUuid: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
@@ -26,7 +26,7 @@ describe('use-users hooks', () => {
|
||||
it('should generate correct cache keys', () => {
|
||||
expect(userKeys.all).toEqual(['users']);
|
||||
expect(userKeys.list({ search: 'john' })).toEqual(['users', 'list', { search: 'john' }]);
|
||||
expect(userKeys.detail(1)).toEqual(['users', 'detail', 1]);
|
||||
expect(userKeys.detail('uuid-1')).toEqual(['users', 'detail', 'uuid-1']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -146,12 +146,12 @@ describe('use-users hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync({
|
||||
id: 1,
|
||||
uuid: 'uuid-1',
|
||||
data: { email: 'updated@example.com' },
|
||||
});
|
||||
});
|
||||
|
||||
expect(userService.update).toHaveBeenCalledWith(1, { email: 'updated@example.com' });
|
||||
expect(userService.update).toHaveBeenCalledWith('uuid-1', { email: 'updated@example.com' });
|
||||
expect(toast.success).toHaveBeenCalledWith('User updated successfully');
|
||||
});
|
||||
|
||||
@@ -168,7 +168,7 @@ describe('use-users hooks', () => {
|
||||
await act(async () => {
|
||||
try {
|
||||
await result.current.mutateAsync({
|
||||
id: 999,
|
||||
uuid: 'uuid-999',
|
||||
data: { email: 'test@example.com' },
|
||||
});
|
||||
} catch {
|
||||
@@ -190,10 +190,10 @@ describe('use-users hooks', () => {
|
||||
const { result } = renderHook(() => useDeleteUser(), { wrapper });
|
||||
|
||||
await act(async () => {
|
||||
await result.current.mutateAsync(1);
|
||||
await result.current.mutateAsync('uuid-1');
|
||||
});
|
||||
|
||||
expect(userService.delete).toHaveBeenCalledWith(1);
|
||||
expect(userService.delete).toHaveBeenCalledWith('uuid-1');
|
||||
expect(toast.success).toHaveBeenCalledWith('User deleted successfully');
|
||||
});
|
||||
|
||||
@@ -209,7 +209,7 @@ describe('use-users hooks', () => {
|
||||
|
||||
await act(async () => {
|
||||
try {
|
||||
await result.current.mutateAsync(1);
|
||||
await result.current.mutateAsync('uuid-1');
|
||||
} catch {
|
||||
// Expected
|
||||
}
|
||||
|
||||
@@ -38,26 +38,17 @@ describe('correspondenceService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getById', () => {
|
||||
it('should call GET /correspondences/:id', async () => {
|
||||
const mockData = { id: 1, subject: 'Test' };
|
||||
describe('getByUuid', () => {
|
||||
it('should call GET /correspondences/:uuid', async () => {
|
||||
const mockData = { id: 1, uuid: 'uuid-1', subject: 'Test' };
|
||||
// Service expects response.data.data (NestJS interceptor wrapper)
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ data: { data: mockData } });
|
||||
|
||||
const result = await correspondenceService.getById(1);
|
||||
const result = await correspondenceService.getByUuid('uuid-1');
|
||||
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/correspondences/1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/correspondences/uuid-1');
|
||||
expect(result).toEqual(mockData);
|
||||
});
|
||||
|
||||
it('should work with string id', async () => {
|
||||
const mockData = { id: 1 };
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ data: { data: mockData } });
|
||||
|
||||
await correspondenceService.getById('123');
|
||||
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/correspondences/123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', () => {
|
||||
@@ -78,76 +69,76 @@ describe('correspondenceService', () => {
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('should call PUT /correspondences/:id with data', async () => {
|
||||
it('should call PUT /correspondences/:uuid with data', async () => {
|
||||
const updateData = { subject: 'Updated Title' };
|
||||
const mockResponse = { id: 1, subject: 'Updated Title' };
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1', subject: 'Updated Title' };
|
||||
vi.mocked(apiClient.put).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await correspondenceService.update(1, updateData);
|
||||
const result = await correspondenceService.update('uuid-1', updateData);
|
||||
|
||||
expect(apiClient.put).toHaveBeenCalledWith('/correspondences/1', updateData);
|
||||
expect(apiClient.put).toHaveBeenCalledWith('/correspondences/uuid-1', updateData);
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete', () => {
|
||||
it('should call DELETE /correspondences/:id', async () => {
|
||||
it('should call DELETE /correspondences/:uuid', async () => {
|
||||
vi.mocked(apiClient.delete).mockResolvedValue({ data: {} });
|
||||
|
||||
const result = await correspondenceService.delete(1);
|
||||
const result = await correspondenceService.delete('uuid-1');
|
||||
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/correspondences/1');
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/correspondences/uuid-1');
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('submit', () => {
|
||||
it('should call POST /correspondences/:id/submit', async () => {
|
||||
it('should call POST /correspondences/:uuid/submit', async () => {
|
||||
const submitDto = { note: 'Ready for review' };
|
||||
const mockResponse = { id: 1, status: 'submitted' };
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1', status: 'submitted' };
|
||||
vi.mocked(apiClient.post).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await correspondenceService.submit(1, submitDto);
|
||||
const result = await correspondenceService.submit('uuid-1', submitDto);
|
||||
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/1/submit', submitDto);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/uuid-1/submit', submitDto);
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('processWorkflow', () => {
|
||||
it('should call POST /correspondences/:id/workflow', async () => {
|
||||
it('should call POST /correspondences/:uuid/workflow', async () => {
|
||||
const workflowDto: WorkflowActionDto = { action: 'APPROVE', comments: 'LGTM' };
|
||||
const mockResponse = { id: 1, status: 'approved' };
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1', status: 'approved' };
|
||||
vi.mocked(apiClient.post).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await correspondenceService.processWorkflow(1, workflowDto);
|
||||
const result = await correspondenceService.processWorkflow('uuid-1', workflowDto);
|
||||
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/1/workflow', workflowDto);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/uuid-1/workflow', workflowDto);
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addReference', () => {
|
||||
it('should call POST /correspondences/:id/references', async () => {
|
||||
it('should call POST /correspondences/:uuid/references', async () => {
|
||||
const referenceDto = { targetId: 2, referenceType: 'reply_to' };
|
||||
const mockResponse = { id: 1 };
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1' };
|
||||
vi.mocked(apiClient.post).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await correspondenceService.addReference(1, referenceDto);
|
||||
const result = await correspondenceService.addReference('uuid-1', referenceDto);
|
||||
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/1/references', referenceDto);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/correspondences/uuid-1/references', referenceDto);
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeReference', () => {
|
||||
it('should call DELETE /correspondences/:id/references with body', async () => {
|
||||
it('should call DELETE /correspondences/:uuid/references with body', async () => {
|
||||
const referenceDto = { targetId: 2 };
|
||||
vi.mocked(apiClient.delete).mockResolvedValue({ data: {} });
|
||||
|
||||
const result = await correspondenceService.removeReference(1, referenceDto);
|
||||
const result = await correspondenceService.removeReference('uuid-1', referenceDto);
|
||||
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/correspondences/1/references', {
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/correspondences/uuid-1/references', {
|
||||
data: referenceDto,
|
||||
});
|
||||
expect(result).toEqual({});
|
||||
|
||||
@@ -34,24 +34,16 @@ describe('projectService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getById', () => {
|
||||
it('should call GET /projects/:id', async () => {
|
||||
const mockResponse = { id: 1, name: 'Project Alpha', code: 'P-001' };
|
||||
describe('getByUuid', () => {
|
||||
it('should call GET /projects/:uuid', async () => {
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1', name: 'Project Alpha', code: 'P-001' };
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await projectService.getById(1);
|
||||
const result = await projectService.getByUuid('uuid-1');
|
||||
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/projects/1');
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/projects/uuid-1');
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should work with string id', async () => {
|
||||
vi.mocked(apiClient.get).mockResolvedValue({ data: {} });
|
||||
|
||||
await projectService.getById('123');
|
||||
|
||||
expect(apiClient.get).toHaveBeenCalledWith('/projects/123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', () => {
|
||||
@@ -68,25 +60,25 @@ describe('projectService', () => {
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('should call PUT /projects/:id with data', async () => {
|
||||
it('should call PUT /projects/:uuid with data', async () => {
|
||||
const updateData = { projectName: 'Updated Project' };
|
||||
const mockResponse = { id: 1, projectName: 'Updated Project' };
|
||||
const mockResponse = { id: 1, uuid: 'uuid-1', projectName: 'Updated Project' };
|
||||
vi.mocked(apiClient.put).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await projectService.update(1, updateData);
|
||||
const result = await projectService.update('uuid-1', updateData);
|
||||
|
||||
expect(apiClient.put).toHaveBeenCalledWith('/projects/1', updateData);
|
||||
expect(apiClient.put).toHaveBeenCalledWith('/projects/uuid-1', updateData);
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete', () => {
|
||||
it('should call DELETE /projects/:id', async () => {
|
||||
it('should call DELETE /projects/:uuid', async () => {
|
||||
vi.mocked(apiClient.delete).mockResolvedValue({ data: {} });
|
||||
|
||||
const result = await projectService.delete(1);
|
||||
const result = await projectService.delete('uuid-1');
|
||||
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/projects/1');
|
||||
expect(apiClient.delete).toHaveBeenCalledWith('/projects/uuid-1');
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user