From e3f5c5acddb574c23e690f6c86d45fc14f1a3cb5 Mon Sep 17 00:00:00 2001
From: Andrei Cioromila <andrei.cioromila@thinslices.com>
Date: Mon, 15 Oct 2018 18:41:57 +0300
Subject: [PATCH] test(component-invite): Update body object when testing user
 invites for review

---
 .../src/routes/fragmentsInvitations/post.js   |  1 -
 .../tests/fragmentsInvitations/post.test.js   | 20 ++++++++++++-------
 packages/xpub-faraday/config/authsome-mode.js |  4 +---
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/packages/component-invite/src/routes/fragmentsInvitations/post.js b/packages/component-invite/src/routes/fragmentsInvitations/post.js
index 6616cb0ba..fada049c6 100644
--- a/packages/component-invite/src/routes/fragmentsInvitations/post.js
+++ b/packages/component-invite/src/routes/fragmentsInvitations/post.js
@@ -1,4 +1,3 @@
-const logger = require('@pubsweet/logger')
 const {
   Team,
   User,
diff --git a/packages/component-invite/src/tests/fragmentsInvitations/post.test.js b/packages/component-invite/src/tests/fragmentsInvitations/post.test.js
index ce8719050..0683f0aaf 100644
--- a/packages/component-invite/src/tests/fragmentsInvitations/post.test.js
+++ b/packages/component-invite/src/tests/fragmentsInvitations/post.test.js
@@ -21,6 +21,7 @@ const reqBody = {
   title: 'Mr',
   affiliation: chance.company(),
   admin: false,
+  country: chance.country(),
 }
 const route = {
   path: '/api/collections/:collectionId/fragments/:fragmentId/invitations',
@@ -49,17 +50,18 @@ describe('Post fragments invitations route handler', () => {
 
     expect(res.statusCode).toBe(400)
     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 () => {
     const { user, editorInChief } = testFixtures.users
     const { collection } = testFixtures.collections
     const { fragment } = testFixtures.fragments
 
-    body = {
+    body = Object.assign(body, {
       email: user.email,
       role: 'reviewer',
-    }
+    })
+
     const res = await requests.sendRequest({
       body,
       userId: editorInChief.id,
@@ -109,10 +111,12 @@ describe('Post fragments invitations route handler', () => {
     const { answerReviewer, handlingEditor } = testFixtures.users
     const { collection } = testFixtures.collections
     const { fragment } = testFixtures.fragments
-    body = {
+
+    body = Object.assign(body, {
       email: answerReviewer.email,
       role: 'reviewer',
-    }
+    })
+
     const res = await requests.sendRequest({
       body,
       userId: handlingEditor.id,
@@ -155,10 +159,12 @@ describe('Post fragments invitations route handler', () => {
     const { inactiveUser, handlingEditor } = testFixtures.users
     const { collection } = testFixtures.collections
     const { fragment } = testFixtures.fragments
-    body = {
+
+    body = Object.assign(body, {
       email: inactiveUser.email,
       role: 'reviewer',
-    }
+    })
+
     const res = await requests.sendRequest({
       body,
       userId: handlingEditor.id,
diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js
index 5df5dcb14..4e4625b97 100644
--- a/packages/xpub-faraday/config/authsome-mode.js
+++ b/packages/xpub-faraday/config/authsome-mode.js
@@ -164,9 +164,7 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
 
     if (get(object, 'path', '') === '/teams') {
       return {
-        filter: teams => {
-          return teams.filter(t => user.teams.includes(t.id))
-        },
+        filter: teams => teams.filter(t => user.teams.includes(t.id)),
       }
     }
   }
-- 
GitLab