From 6109bf28d36bd295dccfdd6cdf47916d934e64fc Mon Sep 17 00:00:00 2001 From: Demetriad Sinzeanu <demetriad.sinzeanu@thinslices.com> Date: Thu, 15 Nov 2018 11:52:23 +0200 Subject: [PATCH] test(authsome-helpers.test): Added tests for stripeCollectionByRole + minor changes --- .../src/ManuscriptCard.js | 2 +- .../xpub-faraday/config/authsome-helpers.js | 22 +++-- .../tests/config/authsome-helpers.test.js | 85 +++++++++++++++++++ 3 files changed, 99 insertions(+), 10 deletions(-) diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index 252281852..fb471ea96 100644 --- a/packages/component-faraday-ui/src/ManuscriptCard.js +++ b/packages/component-faraday-ui/src/ManuscriptCard.js @@ -76,7 +76,7 @@ const ManuscriptCard = ({ <Row alignItems="center" justify="flex-start" mb={1}> <H4>Handling editor</H4> <Text ml={1} mr={3} whiteSpace="nowrap"> - {get(handlingEditor, 'name', 'Assigned')} + {get(handlingEditor, 'name', 'Undefined')} </Text> {canViewReports && ( <Fragment> diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index 81f646632..08e583c72 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -80,7 +80,7 @@ const stripeCollectionByRole = ({ collection = {}, role = '' }) => { return { ...collection, handlingEditor: handlingEditor && - handlingEditor.isAccepted && { + !handlingEditor.isAccepted && { ...omit(handlingEditor, keysToOmit), name: 'Assigned', }, @@ -161,23 +161,23 @@ const getCollections = async ({ user, models }) => { const userPermisssions = await getUserPermissions({ user, Team: models.Team }) const collections = (await Promise.all( - userPermisssions.map(async up => { + userPermisssions.map(async userPermission => { let fragment = {} let collection = {} try { - if (up.objectType === 'collection') { - collection = await models.Collection.find(up.objectId) + if (userPermission.objectType === 'collection') { + collection = await models.Collection.find(userPermission.objectId) const latestFragmentId = collection.fragments[collection.fragments.length - 1] collection.currentVersion = await models.Fragment.find( latestFragmentId, ) } else { - fragment = await models.Fragment.find(up.objectId) + fragment = await models.Fragment.find(userPermission.objectId) collection = await models.Collection.find(fragment.collectionId) collection.currentVersion = stripeFragmentByRole({ fragment, - role: up.role, + role: userPermission.role, user, }) } @@ -186,9 +186,12 @@ const getCollections = async ({ user, models }) => { return null } const status = get(collection, 'status', 'draft') - collection.visibleStatus = get(statuses, `${status}.${up.role}.label`) + collection.visibleStatus = get( + statuses, + `${status}.${userPermission.role}.label`, + ) - const role = get(up, 'role', 'author') + const role = get(userPermission, 'role', 'author') const parsedStatuses = await setCollectionStatus({ role, user, @@ -197,7 +200,7 @@ const getCollections = async ({ user, models }) => { }) const stripedColl = stripeCollectionByRole({ collection, - role: up.role, + role: userPermission.role, }) return { @@ -299,5 +302,6 @@ module.exports = { setCollectionStatus, stripeFragmentByRole, getTeamsByPermissions, + stripeCollectionByRole, hasPermissionForObject, } diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index a15e1f985..c5634168f 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -10,6 +10,91 @@ describe('Authsome Helpers', () => { models = fixturesService.Model.build(testFixtures) }) + describe('stripeCollectionByRole', () => { + it('should return a collection', () => { + const { collection } = testFixtures.collections + const newCollection = ah.stripeCollectionByRole({ + collection, + }) + expect(newCollection).toBeTruthy() + }) + + it('Author should not see HE name on dashboard before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + + expect(handlingEditor.email).toBeFalsy() + expect(handlingEditor.name).toEqual('Assigned') + }) + + it('EIC and Admin should see HE name before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('EIC and Admin should see HE name after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('Atuhor should see HE name on dashboard after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.name).not.toEqual('Assigned') + }) + it('stripeCollection - returns if collection does not have HE', () => { + const { collection } = testFixtures.collections + delete collection.handlingEditor + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ collection, role }) + expect(newCollection.handlingEditor).toBeFalsy() + }) + }) + describe('stripeFragmentByRole', () => { it('reviewer should not see authors email', () => { const { fragment } = testFixtures.fragments -- GitLab