Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
banders committed Sep 27, 2024
1 parent 9eeb264 commit 5063c05
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backend/src/v1/routes/admin-report-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import bodyParser from 'body-parser';
import express, { Application } from 'express';
import request from 'supertest';
import { PayTransparencyUserError } from '../services/file-upload-service';
import { UserInputError } from '../types/errors';
import router from './admin-report-routes';

jest.mock('../services/utils-service', () => ({
Expand Down Expand Up @@ -50,13 +51,16 @@ const mockReport = {

const mockSearchReport = jest.fn().mockResolvedValue({ reports: [mockReport] });
const mockChangeReportLockStatus = jest.fn();
const mockGetReportAdminActionHistory = jest.fn();
jest.mock('../services/admin-report-service', () => ({
adminReportService: {
...jest.requireActual('../services/admin-report-service')
.adminReportService,
searchReport: (...args) => mockSearchReport(...args),
changeReportLockStatus: (...args) => mockChangeReportLockStatus(...args),
getReportPdf: (...args) => mockGetReportPdf(...args),
getReportAdminActionHistory: (...args) =>
mockGetReportAdminActionHistory(...args),
},
}));
const mockGetReportPdf = jest
Expand Down Expand Up @@ -229,4 +233,29 @@ describe('admin-report-routes', () => {
});
});
});

describe('GET /:id/admin-action-history', () => {
describe('if reportId is invalid', () => {
it('should return 404', async () => {
const mockReportId = 'invalid';
mockGetReportAdminActionHistory.mockRejectedValue(new UserInputError());
await request(app)
.get(`/${mockReportId}/admin-action-history`)
.expect(404);
});
});
describe('if reportId is valid', () => {
it('should return 200', async () => {
const mockReportId = 'invalid';
const mockResults = [{}];
mockGetReportAdminActionHistory.mockResolvedValue(mockResults);
await request(app)
.get(`/${mockReportId}/admin-action-history`)
.expect(200)
.expect(({ body }) => {
expect(body).toEqual(mockResults);
});
});
});
});
});

0 comments on commit 5063c05

Please sign in to comment.