Skip to content
Snippets Groups Projects
Commit ecb92f82 authored by Tania Fecheta's avatar Tania Fecheta
Browse files

test(collections/patch.test): add test to handle collection not found case

parent 4f4d8efa
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!198Hin 1166 admin delete manuscript
......@@ -15,6 +15,11 @@ module.exports = models => async (req, res) => {
}
const canArchive = await authsome.can(req.user, 'PATCH', target)
if (!collection)
return res.status(404).json({
error: `Collection not found`,
})
if (!canArchive)
return res.status(403).json({
error: 'Unauthorized',
......
......@@ -26,6 +26,26 @@ describe('Patch colection route handler', () => {
models = Model.build(testFixtures)
})
it('should return an error if the manuscript does not exist', async () => {
const { admin } = testFixtures.users
const { collection } = testFixtures.collections
collection.status = 'underReview'
const res = await requests.sendRequest({
userId: admin.id,
body,
models,
route,
path,
params: {
collectionId: '123',
},
})
expect(res.statusCode).toBe(404)
const data = JSON.parse(res._getData())
expect(data.error).toBe('Collection not found')
})
it('should return success when deleting a manuscript as admin', async () => {
const { admin } = testFixtures.users
const { collection } = testFixtures.collections
......@@ -64,6 +84,7 @@ describe('Patch colection route handler', () => {
const data = JSON.parse(res._getData())
expect(data.error).toBe('Unauthorized')
})
it('should return an error when deleting a manuscript as author', async () => {
const { author } = testFixtures.users
const { collection } = testFixtures.collections
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment