Skip to content
Snippets Groups Projects
Commit 1d2f901a authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

update post tests

parent 572c7b70
No related branches found
No related tags found
1 merge request!8Sprint #10
......@@ -20,14 +20,12 @@ module.exports = models => async (req, res) => {
collection = await models.Collection.find(collectionId)
if (!collection.fragments.includes(fragmentId))
return res.status(400).json({
error: `collection ${
collection.id
} does not contain fragment ${fragmentId}.`,
error: `Collection and fragment do not match.`,
})
fragment = await models.Fragment.find(fragmentId)
} catch (e) {
const notFoundError = await helpers.handleNotFoundError(e, 'item')
const notFoundError = await helpers.handleNotFoundError(e, 'Item')
return res.status(notFoundError.status).json({
error: notFoundError.message,
})
......
......@@ -36,7 +36,7 @@ describe('Post collections invitations route handler', () => {
body = cloneDeep(reqBody)
models = Model.build(testFixtures)
})
it('should return an error params are missing', async () => {
it('should return an error when params are missing', async () => {
const { reviewer } = testFixtures.users
delete body.comments
const res = await requests.sendRequest({
......@@ -70,4 +70,42 @@ describe('Post collections invitations route handler', () => {
const data = JSON.parse(res._getData())
expect(data.userId).toEqual(reviewer.id)
})
it('should return an error when the fragmentId does not match the collectionId', async () => {
const { reviewer } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
collection.fragments.length = 0
const res = await requests.sendRequest({
body,
userId: reviewer.id,
models,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Collection and fragment do not match.')
})
it('should return an error when the collection does not exist', async () => {
const { reviewer } = testFixtures.users
const { fragment } = testFixtures.fragments
const res = await requests.sendRequest({
body,
userId: reviewer.id,
models,
path,
params: {
collectionId: 'invalid-id',
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(404)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Item not found')
})
})
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