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
@@ -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({});
});
});