From 5063c05f8cd89b28ca22a8a63c37270d1159cbcd Mon Sep 17 00:00:00 2001 From: Brock Anderson Date: Fri, 27 Sep 2024 10:13:31 -0700 Subject: [PATCH] added unit tests --- .../src/v1/routes/admin-report-routes.spec.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/backend/src/v1/routes/admin-report-routes.spec.ts b/backend/src/v1/routes/admin-report-routes.spec.ts index 8c2f3cbe4..38ee48d0b 100644 --- a/backend/src/v1/routes/admin-report-routes.spec.ts +++ b/backend/src/v1/routes/admin-report-routes.spec.ts @@ -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', () => ({ @@ -50,6 +51,7 @@ 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') @@ -57,6 +59,8 @@ jest.mock('../services/admin-report-service', () => ({ searchReport: (...args) => mockSearchReport(...args), changeReportLockStatus: (...args) => mockChangeReportLockStatus(...args), getReportPdf: (...args) => mockGetReportPdf(...args), + getReportAdminActionHistory: (...args) => + mockGetReportAdminActionHistory(...args), }, })); const mockGetReportPdf = jest @@ -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); + }); + }); + }); + }); });