Skip to content

Commit

Permalink
#596 add tests to get one classification summary route
Browse files Browse the repository at this point in the history
  • Loading branch information
grindarius committed Apr 29, 2024
1 parent 478b613 commit 21e4615
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 27 additions & 3 deletions core/classifier-jobs/summary-classification.int.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,33 @@ describe('GET /classifier-jobs/{id}/summary/{value}', () => {
expect(response.body.unreviewed).toEqual(0)
})

test.todo('returns 404 on invalid classifier id')
test('returns 404 on invalid classifier id', async () => {
await models.ClassifierJobSummary.bulkCreate([
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_1.id, total: 1, confirmed: 1, rejected: 0, uncertain: 0 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_2.id, total: 1, confirmed: 0, rejected: 1, uncertain: 0 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_3.id, total: 1, confirmed: 0, rejected: 0, uncertain: 1 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_4.id, total: 0, confirmed: 0, rejected: 0, uncertain: 0 },
{ classifierJobId: JOB_2.id, classificationId: CLASSIFICATION_1.id, total: 1, confirmed: 1, rejected: 0, uncertain: 1 }
])

test.todo('returns 404 on classification value outside the classifier')
const response = await request(app).get(`/1928943/summary/${CLASSIFICATION_2.id}`)

test.todo('returns 404 on classification value that does not have any value')
expect(response.statusCode).toEqual(404)
expect(response.body.message).toEqual('Classifier job or classification value in the job cannot be found.')
})

test('returns 404 on classification value outside the classifier', async () => {
await models.ClassifierJobSummary.bulkCreate([
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_1.id, total: 1, confirmed: 1, rejected: 0, uncertain: 0 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_2.id, total: 1, confirmed: 0, rejected: 1, uncertain: 0 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_3.id, total: 1, confirmed: 0, rejected: 0, uncertain: 1 },
{ classifierJobId: JOB_1.id, classificationId: CLASSIFICATION_4.id, total: 0, confirmed: 0, rejected: 0, uncertain: 0 },
{ classifierJobId: JOB_2.id, classificationId: CLASSIFICATION_1.id, total: 1, confirmed: 1, rejected: 0, uncertain: 1 }
])

const response = await request(app).get(`/${JOB_2.id}/summary/${CLASSIFICATION_4.id}`)

expect(response.statusCode).toEqual(404)
expect(response.body.message).toEqual('Classifier job or classification value in the job cannot be found.')
})
})
4 changes: 3 additions & 1 deletion core/classifier-jobs/summary-classification.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const { getSummary } = require('./bl/summary')
* description: Insufficient priviledges
* 404:
* description: Classifier job not found or classification value not found.
* 5XX:
* description: Other unrecoverable errors.
*
*/
module.exports = async (req, res) => {
Expand All @@ -45,7 +47,7 @@ module.exports = async (req, res) => {
try {
const result = await getSummary(req.params.id, { classificationValue: req.params.value }, { readableBy })
if (result.total === 0 || result.results.classificationsSummary.length === 0) {
throw EmptyResultError('Classifier job summary with given `value` not found.')
throw new EmptyResultError('Classifier job or classification value in the job cannot be found.')
}
return res.json(result.results.classificationsSummary[0])
} catch (e) {
Expand Down

0 comments on commit 21e4615

Please sign in to comment.