From 1217f90517fb004263fcae6fb40fedb3b8502787 Mon Sep 17 00:00:00 2001
From: Kiran Parajuli <kiranparajuli589@gmail.com>
Date: Fri, 6 Mar 2020 16:44:42 +0545
Subject: [PATCH] Added acceptance test for enforced expiration date on a user
 share

---
 .../shareWithUsers.feature                      | 17 +++++++++++++++++
 tests/acceptance/helpers/sharingHelper.js       | 15 +++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature
index 4c7b8fd97d9..4264c5cd4fc 100644
--- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature
+++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature
@@ -605,3 +605,20 @@ Feature: Sharing files and folders with internal users
       | uid_owner  | user1      |
       | share_with | user2      |
       | expiration | +7         |
+
+  Scenario Outline: enforced expiration date on collaborators share
+    Given the setting "shareapi_default_expire_date" of app "core" has been set to "yes"
+    And the setting "shareapi_expire_after_n_days" of app "core" has been set to "42"
+    And user "user1" has logged in using the webUI
+    When the user shares file "<shared-resource>" with user "User Two" using the webUI
+    Then user "user1" should have a share with these details:
+      | field      | value              |
+      | path       | /<shared-resource> |
+      | share_type | user               |
+      | uid_owner  | user1              |
+      | share_with | user2              |
+      | expiration | null               |
+    Examples:
+      | shared-resource |
+      | lorem.txt       |
+      | simple-folder   |
diff --git a/tests/acceptance/helpers/sharingHelper.js b/tests/acceptance/helpers/sharingHelper.js
index ce9888b2bfa..638b265abef 100644
--- a/tests/acceptance/helpers/sharingHelper.js
+++ b/tests/acceptance/helpers/sharingHelper.js
@@ -107,10 +107,17 @@ module.exports = {
             } else if (expectedDetail.field === 'expiration') {
               expectedDetail.value = sharingHelper.calculateDate(expectedDetail.value)
             }
-
-            if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) {
-              found = false
-              break
+            if (share[expectedDetail.field] === null) {
+              // assertion for null values
+              if (!(expectedDetail.field in share) || expectedDetail.value !== 'null') {
+                found = false
+                break
+              }
+            } else {
+              if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) {
+                found = false
+                break
+              }
             }
           }
           if (found) {