Skip to content

Commit

Permalink
fix(checker): 404 if inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneRifle committed Nov 3, 2023
1 parent 542d6b9 commit 9c1e6ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/checker/CheckerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 20 additions & 3 deletions src/server/checker/__test__/CheckerController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down

0 comments on commit 9c1e6ea

Please sign in to comment.