diff --git a/packages/component-helper-service/src/tests/fragment.test.js b/packages/component-helper-service/src/tests/fragment.test.js index 26598cfe8bd73fc40a8966a03ab51aa3552f3668..c5623dc18a8d7cf4812d3695189319f48b7e2202 100644 --- a/packages/component-helper-service/src/tests/fragment.test.js +++ b/packages/component-helper-service/src/tests/fragment.test.js @@ -15,6 +15,8 @@ const { recommendations: configRecommendations } = config const acceptedReviewerId = chance.guid() const submittedReviewerId1 = chance.guid() const submittedReviewerId2 = chance.guid() +const handlingEditorId = chance.guid() +const editorInChiefId = chance.guid() const fragment = { invitations: [ { @@ -281,4 +283,93 @@ describe('Fragment helper', () => { } }) }) + describe('canHEMakeAnotherRecommendation', () => { + it('should return true when He makes a recommendation after EIC decision was to return to HE', async () => { + testFragment.recommendations = [ + { + recommendation: 'publish', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditorId, + createdOn: 1542361074012, + updatedOn: chance.timestamp(), + }, + { + recommendation: 'return-to-handling-editor', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: editorInChiefId, + createdOn: 1542361115749, + updatedOn: chance.timestamp(), + }, + ] + const currentUserRecommendations = testFragment.recommendations.filter( + r => r.userId === handlingEditorId, + ) + const fragmentHelper = new Fragment({ fragment: testFragment }) + const canHEMakeAnotherRecommendation = await fragmentHelper.canHEMakeAnotherRecommendation( + currentUserRecommendations, + ) + expect(canHEMakeAnotherRecommendation).toBe(true) + }) + it('should return false when He makes another recommendation', async () => { + testFragment.recommendations = [ + { + recommendation: 'publish', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditorId, + createdOn: 1542361074012, + updatedOn: chance.timestamp(), + }, + ] + const currentUserRecommendations = testFragment.recommendations.filter( + r => r.userId === handlingEditorId, + ) + const fragmentHelper = new Fragment({ fragment: testFragment }) + const canHEMakeAnotherRecommendation = await fragmentHelper.canHEMakeAnotherRecommendation( + currentUserRecommendations, + ) + expect(canHEMakeAnotherRecommendation).toBe(false) + }) + }) })