From da9a54a6353169e03d8cf1fd97bd179cea55288a Mon Sep 17 00:00:00 2001
From: Tania Fecheta <tania.fecheta@thinslices.com>
Date: Tue, 20 Nov 2018 09:47:37 +0200
Subject: [PATCH] test(canHeMakeAnotherRecommendation): add unit tests for
 canHEMakeAnotherRecommendation

---
 .../src/tests/fragment.test.js                | 91 +++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/packages/component-helper-service/src/tests/fragment.test.js b/packages/component-helper-service/src/tests/fragment.test.js
index 26598cfe8..c5623dc18 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)
+    })
+  })
 })
-- 
GitLab