From 9c1e6eab1d381a28d93fe65995e77b4e8f49b2a1 Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Fri, 3 Nov 2023 04:13:30 +0000 Subject: [PATCH] fix(checker): 404 if inactive --- src/server/checker/CheckerController.ts | 2 +- .../__test__/CheckerController.spec.ts | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/server/checker/CheckerController.ts b/src/server/checker/CheckerController.ts index 1dfe06594..7775bea48 100644 --- a/src/server/checker/CheckerController.ts +++ b/src/server/checker/CheckerController.ts @@ -121,7 +121,7 @@ export class CheckerController { const { id } = req.params try { const checker = await this.service.retrievePublished(id) - if (!checker) { + if (!checker || !checker.isActive) { res.status(404).json({ message: 'Not Found' }) } else { res.json(checker) diff --git a/src/server/checker/__test__/CheckerController.spec.ts b/src/server/checker/__test__/CheckerController.spec.ts index cbb6fdaac..895cca96b 100644 --- a/src/server/checker/__test__/CheckerController.spec.ts +++ b/src/server/checker/__test__/CheckerController.spec.ts @@ -324,15 +324,32 @@ describe('CheckerController', () => { service.retrievePublished.mockReset() }) - it('accepts non-authenticated getPublished', async () => { + it('accepts non-authenticated getPublished, but returns 404 if inactive', async () => { const app = express() app.use(bodyParser.json()) app.use(sessionMiddleware({})) app.get('/c/:id', controller.getPublished) - service.retrievePublished.mockResolvedValue(checker) + service.retrievePublished.mockResolvedValue({ + ...checker, + isActive: false, + }) + await request(app).get(`/c/${checker.id}`).expect(404) + expect(service.retrievePublished).toHaveBeenCalledWith(checker.id) + }) + + it('accepts non-authenticated getPublished, and returns 200 if active', async () => { + const app = express() + app.use(bodyParser.json()) + app.use(sessionMiddleware({})) + app.get('/c/:id', controller.getPublished) + + service.retrievePublished.mockResolvedValue({ + ...checker, + isActive: true, + }) const response = await request(app).get(`/c/${checker.id}`).expect(200) - expect(response.body).toStrictEqual(checker) + expect(response.body).toStrictEqual({ ...checker, isActive: true }) expect(service.retrievePublished).toHaveBeenCalledWith(checker.id) })