From dbb0a91f0e0442b817ae96510e322783f637df11 Mon Sep 17 00:00:00 2001 From: Anca Ursachi <anca.ursachi@thinslices.com> Date: Thu, 15 Nov 2018 17:15:13 +0200 Subject: [PATCH] test(component-fixture-manager): Add tests for submitting a he recommendation on first version or af --- .../src/fixtures/fragments.js | 138 ++++++++++++++++++ .../src/fixtures/teamIDs.js | 1 - .../src/fixtures/teams.js | 20 +-- .../src/fixtures/users.js | 3 +- .../fragmentsRecommendations/post.test.js | 101 ++++++++++++- 5 files changed, 237 insertions(+), 26 deletions(-) diff --git a/packages/component-fixture-manager/src/fixtures/fragments.js b/packages/component-fixture-manager/src/fixtures/fragments.js index a9717e4cd..8ba4f7159 100644 --- a/packages/component-fixture-manager/src/fixtures/fragments.js +++ b/packages/component-fixture-manager/src/fixtures/fragments.js @@ -423,5 +423,143 @@ fragments.noInvitesFragment = { invites: [], id: chance.guid(), } +fragments.noInvitesFragment = { + ...fragments.fragment1, + recommendations: [], + invites: [], + id: chance.guid(), +} + +fragments.noInvitesFragment1 = { + ...fragments.fragment, + recommendations: [], + invites: [], + id: chance.guid(), +} +fragments.minorRevisionWithoutReview = { + ...fragments.fragment, + recommendations: [ + { + recommendation: 'minor', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditor.id, + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + }, + ], + id: chance.guid(), +} +fragments.minorRevisionWithReview = { + ...fragments.fragment, + recommendations: [ + { + recommendation: 'minor', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditor.id, + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + }, + { + recommendation: 'publish', + recommendationType: 'review', + comments: [ + { + content: chance.paragraph(), + public: chance.bool(), + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: reviewer1.id, + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + submittedOn: chance.timestamp(), + }, + ], + id: chance.guid(), +} +fragments.majorRevisionWithReview = { + ...fragments.fragment, + recommendations: [ + { + recommendation: 'major', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditor.id, + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + }, + { + recommendation: 'publish', + recommendationType: 'review', + comments: [ + { + content: chance.paragraph(), + public: chance.bool(), + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: reviewer1.id, + createdOn: chance.timestamp(), + updatedOn: chance.timestamp(), + submittedOn: chance.timestamp(), + }, + ], + id: chance.guid(), +} module.exports = fragments diff --git a/packages/component-fixture-manager/src/fixtures/teamIDs.js b/packages/component-fixture-manager/src/fixtures/teamIDs.js index 506ba0160..ab1eae109 100644 --- a/packages/component-fixture-manager/src/fixtures/teamIDs.js +++ b/packages/component-fixture-manager/src/fixtures/teamIDs.js @@ -8,5 +8,4 @@ module.exports = { authorTeamID: chance.guid(), revRecommendationTeamID: chance.guid(), rev1TeamID: chance.guid(), - heTeamMinorRevisionCollectionTeamID: chance.guid(), } diff --git a/packages/component-fixture-manager/src/fixtures/teams.js b/packages/component-fixture-manager/src/fixtures/teams.js index 8cdf3c1d8..370a9c0e9 100644 --- a/packages/component-fixture-manager/src/fixtures/teams.js +++ b/packages/component-fixture-manager/src/fixtures/teams.js @@ -8,11 +8,10 @@ const { authorTeamID, revRecommendationTeamID, rev1TeamID, - heTeamMinorRevisionCollectionTeamID, } = require('./teamIDs') const { submittingAuthor } = require('./userData') -const { collection, collection2 } = collections +const { collection } = collections const { fragment, reviewCompletedFragment, fragment1 } = fragments const { handlingEditor, @@ -40,23 +39,6 @@ const teams = { updateProperties: jest.fn(() => teams.heTeam), id: heTeamID, }, - heTeamMinorRevisionCollection: { - teamType: { - name: 'handlingEditor', - permissions: 'handlingEditor', - }, - group: 'handlingEditor', - name: 'HandlingEditor', - object: { - type: 'collection', - id: collection2.id, - }, - members: [handlingEditor.id], - save: jest.fn(() => teams.heTeam), - delete: jest.fn(), - updateProperties: jest.fn(() => teams.heTeam), - id: heTeamMinorRevisionCollectionTeamID, - }, revTeam: { teamType: { name: 'reviewer', diff --git a/packages/component-fixture-manager/src/fixtures/users.js b/packages/component-fixture-manager/src/fixtures/users.js index 11dfb4438..f0a6737c3 100644 --- a/packages/component-fixture-manager/src/fixtures/users.js +++ b/packages/component-fixture-manager/src/fixtures/users.js @@ -8,7 +8,6 @@ const { authorTeamID, revRecommendationTeamID, rev1TeamID, - heTeamMinorRevisionCollectionTeamID, } = require('./teamIDs') const keys = Object.keys(usersData) @@ -19,7 +18,7 @@ users = keys.reduce((obj, item) => { let teams = [] if (isHE) { - teams = [heTeamID, heTeamMinorRevisionCollectionTeamID] + teams = [heTeamID] } if (item === 'author') { teams = [authorTeamID] diff --git a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js index 71d3e562a..9d2d2c4b5 100644 --- a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js +++ b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js @@ -130,9 +130,13 @@ describe('Post fragments recommendations route handler', () => { it('should return success when creating a recommendation as a HE after minor revision and we have at least one review on collection.', async () => { const { handlingEditor } = testFixtures.users - const { collection2 } = testFixtures.collections - const { noInvitesFragment } = testFixtures.fragments + const { collection } = testFixtures.collections + const { + minorRevisionWithReview, + noInvitesFragment1, + } = testFixtures.fragments + collection.fragments = [minorRevisionWithReview.id, noInvitesFragment1.id] const res = await requests.sendRequest({ body, userId: handlingEditor.id, @@ -140,8 +144,8 @@ describe('Post fragments recommendations route handler', () => { route, path, params: { - collectionId: collection2.id, - fragmentId: noInvitesFragment.id, + collectionId: collection.id, + fragmentId: noInvitesFragment1.id, }, }) @@ -150,6 +154,95 @@ describe('Post fragments recommendations route handler', () => { expect(data.userId).toEqual(handlingEditor.id) }) + it('should return error when creating a recommendation as a HE after minor revision and there are no reviews.', async () => { + const { handlingEditor } = testFixtures.users + const { collection } = testFixtures.collections + const { + minorRevisionWithoutReview, + noInvitesFragment1, + } = testFixtures.fragments + + collection.fragments = [ + minorRevisionWithoutReview.id, + noInvitesFragment1.id, + ] + const res = await requests.sendRequest({ + body, + userId: handlingEditor.id, + models, + route, + path, + params: { + collectionId: collection.id, + fragmentId: noInvitesFragment1.id, + }, + }) + + expect(res.statusCode).toBe(400) + const data = JSON.parse(res._getData()) + expect(data.error).toEqual( + 'Cannot publish without at least one reviewer report.', + ) + }) + + it('should return success when creating a recommendation as a HE after major revision and there are least one review on fragment.', async () => { + const { handlingEditor } = testFixtures.users + const { collection } = testFixtures.collections + const { + majorRevisionWithReview, + reviewCompletedFragment, + } = testFixtures.fragments + + reviewCompletedFragment.collectionId = collection.id + collection.fragments = [ + majorRevisionWithReview.id, + reviewCompletedFragment.id, + ] + const res = await requests.sendRequest({ + body, + userId: handlingEditor.id, + models, + route, + path, + params: { + collectionId: collection.id, + fragmentId: reviewCompletedFragment.id, + }, + }) + + expect(res.statusCode).toBe(200) + const data = JSON.parse(res._getData()) + expect(data.userId).toEqual(handlingEditor.id) + }) + + it('should return error when creating a recommendation as a HE after major revision there are no reviews on fragment.', async () => { + const { handlingEditor } = testFixtures.users + const { collection } = testFixtures.collections + const { + majorRevisionWithReview, + noInvitesFragment1, + } = testFixtures.fragments + + collection.fragments = [majorRevisionWithReview.id, noInvitesFragment1.id] + const res = await requests.sendRequest({ + body, + userId: handlingEditor.id, + models, + route, + path, + params: { + collectionId: collection.id, + fragmentId: noInvitesFragment1.id, + }, + }) + + expect(res.statusCode).toBe(400) + const data = JSON.parse(res._getData()) + expect(data.error).toEqual( + 'Cannot publish without at least one reviewer report.', + ) + }) + it('should return an error when the fragmentId does not match the collectionId', async () => { const { reviewer } = testFixtures.users const { collection } = testFixtures.collections -- GitLab