From 7a4f94bc60843fbc81baeae1f92fa335d3c7083e Mon Sep 17 00:00:00 2001 From: amrita-shrestha Date: Tue, 28 Jan 2025 13:42:33 +0545 Subject: [PATCH] add tests for share exipry --- .../acceptance/bootstrap/SharingNgContext.php | 46 +++++++++++++++++++ .../apiSettings/notificationSetting.feature | 18 ++++++++ 2 files changed, 64 insertions(+) diff --git a/tests/acceptance/bootstrap/SharingNgContext.php b/tests/acceptance/bootstrap/SharingNgContext.php index 47d618d3186..2d98df3d013 100644 --- a/tests/acceptance/bootstrap/SharingNgContext.php +++ b/tests/acceptance/bootstrap/SharingNgContext.php @@ -2160,4 +2160,50 @@ public function userListsPermissionsWithFollowingFiltersForFileOrFolderOfTheSpac $this->getPermissionsList($user, $fileOrFolder, $space, $resource, $query) ); } + + /** + * @When user :user expires the last created share: + * + * @param string $user + * @param TableNode $table + * + * @return void + */ + public function userExpiresTheLastCreatedShare(string $user, TableNode $table): void { + $permissionID = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); + $bodyRows = $table->getRowsHash(); + if ($bodyRows['space'] === 'Personal' || $bodyRows['space'] === 'Shares') { + $space = $this->spacesContext->getSpaceByName($user, $bodyRows['space']); + } else { + $space = $this->spacesContext->getCreatedSpace($bodyRows['space']); + } + $spaceId = $space["id"]; + // for updating role of project space shared, we do not need to provide resource + $resource = $bodyRows['resource'] ?? ''; + if ($resource === '' && !\in_array($bodyRows['space'], ['Personal', 'Shares'])) { + $itemId = $space['fileId']; + } else { + $itemId = $this->spacesContext->getResourceId($user, $bodyRows['space'], $resource); + } + $body = []; + $dateTime = new DateTime("now", new DateTimeZone("UTC")); + $body['expirationDateTime'] = $dateTime->modify('-5 minutes')->format('Y-m-d\TH:i:s\Z'); + + $response = GraphHelper::updateShare( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $spaceId, + $itemId, + \json_encode($body), + $permissionID + ); + + $this->featureContext->theHttpStatusCodeShouldBe( + 200, + "Failed to update shared permissions for user '$user'.", + $response + ); + } } diff --git a/tests/acceptance/features/apiSettings/notificationSetting.feature b/tests/acceptance/features/apiSettings/notificationSetting.feature index 6d7a077a313..d0651f0eb5f 100644 --- a/tests/acceptance/features/apiSettings/notificationSetting.feature +++ b/tests/acceptance/features/apiSettings/notificationSetting.feature @@ -607,3 +607,21 @@ Feature: Notification Settings | message | | Alice Hansen added you to Space new-space | But user "Brian" should not have a notification related to space "new-space" with subject "Space disabled" + + + Scenario: check share expired in-app and mail notification for Personal space resource + Given user "Alice" has uploaded file with content "hello world" to "testfile.txt" + And user "Alice" has sent the following resource share invitation: + | resource | testfile.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + | expirationDateTime | 2025-07-15T14:00:00Z | + When user "Alice" expires the last created share: + | space | Personal | + | resource | testfile.txt | + Then user "Brian" should get a notification with subject "Membership expired" and message: + | message | + | Access to Space Alice Hansen lost | + And user "Brian" should have "2" emails