From 29c7d9c149f2e9bc59b53256b22d685b0b2269c7 Mon Sep 17 00:00:00 2001 From: Mihail Hagiu <mihail.hagiu@thinslices.com> Date: Thu, 18 Oct 2018 16:41:27 +0300 Subject: [PATCH] feat(ReviewerCanSeeEditorialComments): Filtering private comments and fixed tests --- .../src/fixtures/fragments.js | 22 +++++++++++++++++++ .../src/tests/collections/get.test.js | 12 +++++++--- .../xpub-faraday/config/authsome-helpers.js | 15 ++++++++----- .../tests/config/authsome-helpers.test.js | 2 +- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/packages/component-fixture-manager/src/fixtures/fragments.js b/packages/component-fixture-manager/src/fixtures/fragments.js index 3f149caf0..c8931dd9b 100644 --- a/packages/component-fixture-manager/src/fixtures/fragments.js +++ b/packages/component-fixture-manager/src/fixtures/fragments.js @@ -46,6 +46,28 @@ const fragments = { updatedOn: chance.timestamp(), submittedOn: chance.timestamp(), }, + { + recommendation: 'reject', + recommendationType: 'review', + comments: [ + { + content: chance.paragraph(), + public: chance.bool(), + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: '1231njfsdknfkjs23', + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + submittedOn: chance.timestamp(), + }, { recommendation: 'minor', recommendationType: 'editorRecommendation', diff --git a/packages/component-manuscript-manager/src/tests/collections/get.test.js b/packages/component-manuscript-manager/src/tests/collections/get.test.js index 0862779b6..6ee20a468 100644 --- a/packages/component-manuscript-manager/src/tests/collections/get.test.js +++ b/packages/component-manuscript-manager/src/tests/collections/get.test.js @@ -24,6 +24,7 @@ describe('Get collections route handler', () => { it('should return collections with the latest fragments if the request user is HE', async () => { const { handlingEditor } = testFixtures.users + const { recommendations } = testFixtures.fragments.fragment const res = await requests.sendRequest({ userId: handlingEditor.id, @@ -40,7 +41,9 @@ describe('Get collections route handler', () => { expect(data[0]).toHaveProperty('currentVersion') expect(data[0]).toHaveProperty('visibleStatus') expect(data[0].currentVersion.type).toEqual('fragment') - expect(data[0].currentVersion.recommendations).toHaveLength(3) + expect(data[0].currentVersion.recommendations).toHaveLength( + recommendations.length, + ) }) it('should return collections with the latest fragments if the request user is reviewer', async () => { @@ -58,7 +61,7 @@ describe('Get collections route handler', () => { expect(data).toHaveLength(2) expect(data[0].type).toEqual('collection') - expect(data[0].currentVersion.recommendations).toHaveLength(1) + expect(data[0].currentVersion.recommendations).toHaveLength(3) expect(data[0].currentVersion.authors[0]).not.toHaveProperty('email') }) @@ -77,6 +80,7 @@ describe('Get collections route handler', () => { it('should return all collections with the latest fragments if the request user is admin/EiC', async () => { const { editorInChief } = testFixtures.users + const { recommendations } = testFixtures.fragments.fragment const res = await requests.sendRequest({ userId: editorInChief.id, @@ -91,6 +95,8 @@ describe('Get collections route handler', () => { expect(data).toHaveLength(size(testFixtures.collections)) expect(data[0].type).toEqual('collection') expect(data[0]).toHaveProperty('visibleStatus') - expect(data[0].currentVersion.recommendations).toHaveLength(3) + expect(data[0].currentVersion.recommendations).toHaveLength( + recommendations.length, + ) }) }) diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index a8518a054..c962ebd7c 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -178,11 +178,16 @@ const stripeFragmentByRole = ({ files: omit(files, ['coverLetter']), authors: authors.map(a => omit(a, ['email'])), recommendations: recommendations - ? recommendations.filter( - r => - r.userId === user.id || - r.recommendationType === 'editorRecommendation', - ) + ? recommendations + .filter( + r => + r.userId === user.id || + r.recommendationType === 'editorRecommendation', + ) + .map(r => ({ + ...r, + comments: r.comments.filter(c => c.public === true), + })) : [], } case 'handlingEditor': diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index 606bb6664..cd0da4941 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -119,7 +119,7 @@ describe('Authsome Helpers', () => { const { fragment } = testFixtures.fragments const result = ah.stripeFragmentByRole({ fragment, role: 'reviewer' }) const { recommendations } = result - expect(recommendations).toEqual([]) + expect(recommendations).toHaveLength(2) }) it('author should not see recommendations if a decision has not been made', () => { -- GitLab