Skip to content

Commit

Permalink
feat: backend unit tests (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
banders committed Jun 20, 2024
1 parent e1f7719 commit a39434d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions backend/src/v1/routes/admin-report-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('admin-report-routes', () => {
const mockReportId = '4492feff-99d7-4b2b-8896-12a59a75d4e3';
await request(app)
.get(`/${mockReportId}`)
.set('accepts', 'application/pdf')
.set('Accept', 'application/pdf')
.expect(200);
expect(mockGetReportPdf.mock.calls[0][1]).toBe(mockReportId);
});
Expand All @@ -97,11 +97,21 @@ describe('admin-report-routes', () => {
mockGetReportPdf.mockResolvedValueOnce(null);
await request(app)
.get(`/${mockReportId}`)
.set('accepts', 'application/pdf')
.set('Accept', 'application/pdf')
.expect(404);
expect(mockGetReportPdf.mock.calls[0][1]).toBe(mockReportId);
});
});
describe('if accept header is invalid', () => {
it('return an error', async () => {
const mockReportId = '4492feff-99d7-4b2b-8896-12a59a75d4e3';
mockGetReportPdf.mockResolvedValueOnce(null);
await request(app)
.get(`/${mockReportId}`)
.set('Accept', 'application/json')
.expect(400);
});
});
});

describe('PATCH /:id', () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/v1/routes/admin-report-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ router.get(
// if not enough information provided, then it is a bad request
logger.error(BAD_REQUEST);
return res
.status(404)
.status(400)
.json({ error: 'Unsupported format in accept header' });
},
),
Expand Down
16 changes: 16 additions & 0 deletions backend/src/v1/services/report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,22 @@ describe('getReportPdf', () => {
expect(result).toBeInstanceOf(Buffer);
});
});
describe('when an invalid report id and/or bceidBusinessGuid are provided', () => {
it('throws an error ', async () => {
const mockReq = {
session: {
correlationID: 'mockCorrelationId',
},
};
const invalidReportId = '1';

jest.spyOn(reportService, 'getReportData').mockResolvedValueOnce(null);
jest.spyOn(utils, 'postDataToDocGenService').mockResolvedValueOnce(null);
await expect(
reportService.getReportPdf(mockReq, invalidReportId),
).rejects.toThrow();
});
});
});

describe('genderCodeToGenderChartInfo', () => {
Expand Down

0 comments on commit a39434d

Please sign in to comment.