Skip to content
Snippets Groups Projects
Commit e3f5c5ac authored by Andrei Cioromila's avatar Andrei Cioromila
Browse files

test(component-invite): Update body object when testing user invites for review

parent a9f58873
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!150Develop,!89Hin 1036
const logger = require('@pubsweet/logger')
const { const {
Team, Team,
User, User,
......
...@@ -21,6 +21,7 @@ const reqBody = { ...@@ -21,6 +21,7 @@ const reqBody = {
title: 'Mr', title: 'Mr',
affiliation: chance.company(), affiliation: chance.company(),
admin: false, admin: false,
country: chance.country(),
} }
const route = { const route = {
path: '/api/collections/:collectionId/fragments/:fragmentId/invitations', path: '/api/collections/:collectionId/fragments/:fragmentId/invitations',
...@@ -49,17 +50,18 @@ describe('Post fragments invitations route handler', () => { ...@@ -49,17 +50,18 @@ describe('Post fragments invitations route handler', () => {
expect(res.statusCode).toBe(400) expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.error).toEqual('Email and role are required.') expect(data.error).toEqual('Missing parameters.')
}) })
it('should return success when a reviewer is invited', async () => { it('should return success when a reviewer is invited', async () => {
const { user, editorInChief } = testFixtures.users const { user, editorInChief } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
body = { body = Object.assign(body, {
email: user.email, email: user.email,
role: 'reviewer', role: 'reviewer',
} })
const res = await requests.sendRequest({ const res = await requests.sendRequest({
body, body,
userId: editorInChief.id, userId: editorInChief.id,
...@@ -109,10 +111,12 @@ describe('Post fragments invitations route handler', () => { ...@@ -109,10 +111,12 @@ describe('Post fragments invitations route handler', () => {
const { answerReviewer, handlingEditor } = testFixtures.users const { answerReviewer, handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
body = {
body = Object.assign(body, {
email: answerReviewer.email, email: answerReviewer.email,
role: 'reviewer', role: 'reviewer',
} })
const res = await requests.sendRequest({ const res = await requests.sendRequest({
body, body,
userId: handlingEditor.id, userId: handlingEditor.id,
...@@ -155,10 +159,12 @@ describe('Post fragments invitations route handler', () => { ...@@ -155,10 +159,12 @@ describe('Post fragments invitations route handler', () => {
const { inactiveUser, handlingEditor } = testFixtures.users const { inactiveUser, handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
body = {
body = Object.assign(body, {
email: inactiveUser.email, email: inactiveUser.email,
role: 'reviewer', role: 'reviewer',
} })
const res = await requests.sendRequest({ const res = await requests.sendRequest({
body, body,
userId: handlingEditor.id, userId: handlingEditor.id,
......
...@@ -164,9 +164,7 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ...@@ -164,9 +164,7 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
if (get(object, 'path', '') === '/teams') { if (get(object, 'path', '') === '/teams') {
return { return {
filter: teams => { filter: teams => teams.filter(t => user.teams.includes(t.id)),
return teams.filter(t => user.teams.includes(t.id))
},
} }
} }
} }
......
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