From da2c4ebef15dcc56ea4336324062dca6d7ec4a83 Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache <sebi.mihalache@gmail.com> Date: Fri, 12 Oct 2018 13:52:35 +0300 Subject: [PATCH] fix(authsome): remove unsubmitted recommendations when user is HE --- .../xpub-faraday/config/authsome-helpers.js | 7 + .../tests/config/authsome-helpers.test.js | 190 +++++++++++------- 2 files changed, 126 insertions(+), 71 deletions(-) diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index f44cf2249..718190c44 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -180,6 +180,13 @@ const stripeFragmentByRole = ({ ? recommendations.filter(r => r.userId === user.id) : [], } + case 'handlingEditor': + return { + ...fragment, + recommendations: recommendations + ? recommendations.filter(r => r.submittedOn) + : [], + } default: return fragment } diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index 82e6978c4..58aa8b2b7 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -88,81 +88,129 @@ describe('Authsome Helpers', () => { expect(result.handlingEditor).toBeFalsy() }) - it('stripeFragment - reviewer should not see authors email', () => { - const { fragment } = testFixtures.fragments - const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) - const { authors = [] } = result - expect(authors[0].email).toBeFalsy() - }) - it('stripeFragment - other roles than reviewer should see authors emails', () => { - const { fragment } = testFixtures.fragments - const result = ah.stripeFragmentByRole({ fragment, role: 'author' }) - const { authors = [] } = result + describe('stripeFragmentByRole', () => { + it('reviewer should not see authors email', () => { + const { fragment } = testFixtures.fragments + const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) + const { authors = [] } = result + expect(authors[0].email).toBeFalsy() + }) + it('other roles than reviewer should see authors emails', () => { + const { fragment } = testFixtures.fragments + const result = ah.stripeFragmentByRole({ fragment, role: 'author' }) + const { authors = [] } = result - expect(authors[0].email).toBeTruthy() - }) + expect(authors[0].email).toBeTruthy() + }) - it('stripeFragment - reviewer should not see cover letter', () => { - const { fragment } = testFixtures.fragments - const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) - const { files = {} } = result - expect(files.coverLetter).toBeFalsy() - }) - it('stripeFragment - reviewer should not see others reviews', () => { - const { fragment } = testFixtures.fragments - const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) - const { recommendations } = result - expect(recommendations).toEqual([]) - }) + it('reviewer should not see cover letter', () => { + const { fragment } = testFixtures.fragments + const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) + const { files = {} } = result + expect(files.coverLetter).toBeFalsy() + }) + it('reviewer should not see others reviews', () => { + const { fragment } = testFixtures.fragments + const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) + const { recommendations } = result + expect(recommendations).toEqual([]) + }) - it('stripeFragment - author should not see recommendations if a decision has not been made', () => { - const { fragment } = testFixtures.fragments - fragment.recommendations = [ - { - comments: [ - { - content: 'private', - public: false, - }, - { - content: 'public', - public: true, - }, - ], - }, - ] - const { recommendations } = ah.stripeFragmentByRole({ - fragment, - role: 'author', - status: 'underReview', - isLast: true, - }) - expect(recommendations).toHaveLength(0) - }) - it('stripeFragment - author should see reviews only if recommendation has been made and only public ones', () => { - const { fragment } = testFixtures.fragments - fragment.recommendations = [ - { - comments: [ - { - content: 'private', - public: false, - }, - { - content: 'public', - public: true, - }, - ], - }, - ] - const result = ah.stripeFragmentByRole({ - fragment, - role: 'author', - status: 'revisionRequested', - }) - const publicComments = get(result, 'recommendations[0].comments') - expect(publicComments).toHaveLength(1) + it('author should not see recommendations if a decision has not been made', () => { + const { fragment } = testFixtures.fragments + fragment.recommendations = [ + { + comments: [ + { + content: 'private', + public: false, + }, + { + content: 'public', + public: true, + }, + ], + }, + ] + const { recommendations } = ah.stripeFragmentByRole({ + fragment, + role: 'author', + status: 'underReview', + isLast: true, + }) + expect(recommendations).toHaveLength(0) + }) + it('author should see reviews only if recommendation has been made and only public ones', () => { + const { fragment } = testFixtures.fragments + fragment.recommendations = [ + { + comments: [ + { + content: 'private', + public: false, + }, + { + content: 'public', + public: true, + }, + ], + }, + ] + const result = ah.stripeFragmentByRole({ + fragment, + role: 'author', + status: 'revisionRequested', + }) + const publicComments = get(result, 'recommendations[0].comments') + expect(publicComments).toHaveLength(1) + }) + it('HE should not see unsubmitted recommendations', () => { + const { fragment } = testFixtures.fragments + fragment.recommendations = [ + { + comments: [ + { + content: 'private', + public: false, + }, + { + content: 'public', + public: true, + }, + ], + }, + ] + const { recommendations } = ah.stripeFragmentByRole({ + fragment, + role: 'handlingEditor', + }) + expect(recommendations).toHaveLength(0) + }) + it('HE should see submitted recommendations', () => { + const { fragment } = testFixtures.fragments + fragment.recommendations = [ + { + comments: [ + { + content: 'private', + public: false, + }, + { + content: 'public', + public: true, + }, + ], + submittedOn: 1122333, + }, + ] + const { recommendations } = ah.stripeFragmentByRole({ + fragment, + role: 'handlingEditor', + }) + expect(recommendations).toHaveLength(1) + }) }) + it('getUsersList - should return parsed users when the user is admin', async () => { const { admin } = testFixtures.users const parsedUsers = await ah.getUsersList({ -- GitLab