Skip to content

Commit 8aa91b3

Browse files
authored
Merge pull request #1820 from CVEProject/af-1819
Resolves issue #1819: Return object for GET requests of non existent reviews
2 parents 9ac3214 + be6f248 commit 8aa91b3

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/controller/review-object.controller/review-object.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function getReviewObjectByOrgIdentifier (req, res, next) {
3737
value = await repo.getOrgReviewObjectByOrgShortname(identifier, isSecretariat, {})
3838
}
3939
if (!value) {
40-
return res.status(404).json({ message: 'No pending review object exists for this organization' })
40+
return res.status(200).json({ pendingReview: null })
4141
}
4242
return res.status(200).json(value)
4343
}

test/integration-tests/review-object/reviewObjectTest.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,18 @@ describe('Review Object Controller Integration Tests', () => {
585585
.send({})
586586
expect(rejectRes).to.have.status(200)
587587
})
588-
})
589588

590-
context('Negative Tests', () => {
591-
it('Returns 404 for non-existent review object GET', async () => {
589+
it('Returns 200 with pendingReview set to null for non-existent review object GET', async () => {
592590
const res = await chai
593591
.request(app)
594592
.get('/api/review/org/nonexistent-org')
595593
.set({ ...constants.headers })
596-
expect(res).to.have.status(404)
597-
expect(res.body.message).to.contain('No pending review object exists for this organization')
594+
expect(res).to.have.status(200)
595+
expect(res.body).to.have.property('pendingReview', null)
598596
})
597+
})
599598

599+
context('Negative Tests', () => {
600600
it('Returns 404 when approving non-existent review object', async () => {
601601
const fakeUUID = '00000000-0000-0000-0000-000000000000'
602602
const res = await chai

test/unit-tests/review-object/review-object.controller.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ describe('Review Object Controller', function () {
7777
expect(res.json.calledWith({ name: short })).to.be.true
7878
})
7979

80-
it('should return 404 if no pending review object exists for UUID', async () => {
80+
it('should return 200 with pendingReview set to null if no pending review object exists for UUID', async () => {
8181
const uuid = '123e4567-e89b-12d3-a456-426614174000'
8282
req.params.identifier = uuid
8383
repoStub.getOrgReviewObjectByOrgUUID = sinon.stub().resolves(null)
8484
await controller.getReviewObjectByOrgIdentifier(req, res, next)
85-
expect(res.status.calledWith(404)).to.be.true
86-
expect(res.json.calledWith({ message: 'No pending review object exists for this organization' })).to.be.true
85+
expect(res.status.calledWith(200)).to.be.true
86+
expect(res.json.calledWith({ pendingReview: null })).to.be.true
8787
})
8888

89-
it('should return 404 if no pending review object exists for short_name', async () => {
89+
it('should return 200 with pendingReview set to null if no pending review object exists for short_name', async () => {
9090
const short = 'myorg'
9191
req.params.identifier = short
9292
repoStub.getOrgReviewObjectByOrgShortname = sinon.stub().resolves(null)
9393
await controller.getReviewObjectByOrgIdentifier(req, res, next)
94-
expect(res.status.calledWith(404)).to.be.true
95-
expect(res.json.calledWith({ message: 'No pending review object exists for this organization' })).to.be.true
94+
expect(res.status.calledWith(200)).to.be.true
95+
expect(res.json.calledWith({ pendingReview: null })).to.be.true
9696
})
9797
})
9898

0 commit comments

Comments
 (0)