From c750d6677a36970742057ecdf711ede66a44f3d1 Mon Sep 17 00:00:00 2001 From: Amrita <54478846+amrita-shrestha@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:59:45 +0545 Subject: [PATCH] Add tests for space notification (#6372) --- .../apiNotification/notification.feature | 1 - .../apiNotification/spaceNotification.feature | 472 ++++++++++++++++++ .../features/apiSpaces/notification.feature | 180 ------- .../bootstrap/NotificationContext.php | 22 + .../acceptance/features/bootstrap/Sharing.php | 3 +- .../features/bootstrap/SpacesContext.php | 42 ++ 6 files changed, 538 insertions(+), 182 deletions(-) create mode 100644 tests/acceptance/features/apiNotification/spaceNotification.feature delete mode 100644 tests/acceptance/features/apiSpaces/notification.feature diff --git a/tests/acceptance/features/apiNotification/notification.feature b/tests/acceptance/features/apiNotification/notification.feature index 4734f2da04a..4d522b33f8c 100644 --- a/tests/acceptance/features/apiNotification/notification.feature +++ b/tests/acceptance/features/apiNotification/notification.feature @@ -267,7 +267,6 @@ Feature: Notification Examples: | language | subject | message | | de | Neue Freigabe | Alice Hansen hat textfile1.txt mit Ihnen geteilt | - | en | Resource shared | Alice Hansen shared textfile1.txt with you | | es | Recurso compartido | Alice Hansen compartió textfile1.txt contigo | diff --git a/tests/acceptance/features/apiNotification/spaceNotification.feature b/tests/acceptance/features/apiNotification/spaceNotification.feature new file mode 100644 index 00000000000..8e03466d15f --- /dev/null +++ b/tests/acceptance/features/apiNotification/spaceNotification.feature @@ -0,0 +1,472 @@ +@api +Feature: Notification + As a user + I want to be notified of actions related to space + So that I can stay updated about the spaces + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + | Carol | + And the administrator has given "Alice" the role "Space Admin" using the settings api + And user "Alice" has created a space "notification checking" with the default quota using the GraphApi + + + Scenario: get a notification of space shared + Given user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And the JSON response should contain a notification message with the subject "Space shared" and the message-details should match + """ + { + "type": "object", + "required": [ + "app", + "datetime", + "message", + "messageRich", + "messageRichParameters", + "notification_id", + "object_id", + "object_type", + "subject", + "subjectRich", + "user" + ], + "properties": { + "app": { + "type": "string", + "enum": [ + "userlog" + ] + }, + "message": { + "type": "string", + "enum": [ + "Alice Hansen added you to Space notification checking" + ] + }, + "messageRich": { + "type": "string", + "enum": [ + "{user} added you to Space {space}" + ] + }, + "messageRichParameters": { + "type": "object", + "required": [ + "space", + "user" + ], + "properties": { + "space": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + }, + "name": { + "type": "string", + "enum": [ + "notification checking" + ] + } + } + }, + "user": { + "type": "object", + "required": [ + "displayname", + "id", + "name" + ], + "properties": { + "displayname": { + "type": "string", + "enum": [ + "Alice Hansen" + ] + }, + "id": { + "type": "string", + "enim": [ + "%user_id%" + ] + }, + "name": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + } + }, + "notification_id": { + "type": "string" + }, + "object_id": { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "object_type": { + "type": "string", + "enum": [ + "storagespace" + ] + }, + "subject": { + "type": "string", + "enum": [ + "Space shared" + ] + }, + "subjectRich": { + "type": "string", + "enum": [ + "Space shared" + ] + }, + "user": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + """ + + + Scenario: get a notification of space unshared + Given user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + And user "Alice" has unshared a space "notification checking" shared with "Brian" + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And the JSON response should contain a notification message with the subject "Removed from Space" and the message-details should match + """ + { + "type": "object", + "required": [ + "app", + "datetime", + "message", + "messageRich", + "messageRichParameters", + "notification_id", + "object_id", + "object_type", + "subject", + "subjectRich", + "user" + ], + "properties": { + "app": { + "type": "string", + "enum": [ + "userlog" + ] + }, + "message": { + "type": "string", + "enum": [ + "Alice Hansen removed you from Space notification checking" + ] + }, + "messageRich": { + "type": "string", + "enum": [ + "{user} removed you from Space {space}" + ] + }, + "messageRichParameters": { + "type": "object", + "required": [ + "space", + "user" + ], + "properties": { + "space": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + }, + "name": { + "type": "string", + "enum": [ + "notification checking" + ] + } + } + }, + "user": { + "type": "object", + "required": [ + "displayname", + "id", + "name" + ], + "properties": { + "displayname": { + "type": "string", + "enum": [ + "Alice Hansen" + ] + }, + "id": { + "type": "string", + "enim": [ + "%user_id%" + ] + }, + "name": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + } + }, + "notification_id": { + "type": "string" + }, + "object_id": { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "object_type": { + "type": "string", + "enum": [ + "storagespace" + ] + }, + "subject": { + "type": "string", + "enum": [ + "Removed from Space" + ] + }, + "subjectRich": { + "type": "string", + "enum": [ + "Removed from Space" + ] + }, + "user": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + """ + + + Scenario: get a notification of space disabled + Given user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + And user "Alice" has disabled a space "notification checking" + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And user "Brian" should have "2" notifications + And the JSON response should contain a notification message with the subject "Space disabled" and the message-details should match + """ + { + "type": "object", + "required": [ + "app", + "datetime", + "message", + "messageRich", + "messageRichParameters", + "notification_id", + "object_id", + "object_type", + "subject", + "subjectRich", + "user" + ], + "properties": { + "app": { + "type": "string", + "enum": [ + "userlog" + ] + }, + "message": { + "type": "string", + "enum": [ + "Alice Hansen disabled Space notification checking" + ] + }, + "messageRich": { + "type": "string", + "enum": [ + "{user} disabled Space {space}" + ] + }, + "messageRichParameters": { + "type": "object", + "required": [ + "space", + "user" + ], + "properties": { + "space": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + }, + "name": { + "type": "string", + "enum": [ + "notification checking" + ] + } + } + }, + "user": { + "type": "object", + "required": [ + "displayname", + "id", + "name" + ], + "properties": { + "displayname": { + "type": "string", + "enum": [ + "Alice Hansen" + ] + }, + "id": { + "type": "string", + "enim": [ + "%user_id%" + ] + }, + "name": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + } + }, + "notification_id": { + "type": "string" + }, + "object_id": { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "object_type": { + "type": "string", + "enum": [ + "storagespace" + ] + }, + "subject": { + "type": "string", + "enum": [ + "Space disabled" + ] + }, + "subjectRich": { + "type": "string", + "enum": [ + "Space disabled" + ] + }, + "user": { + "type": "string", + "enum": [ + "Alice" + ] + } + } + } + """ + + + Scenario Outline: get a notification about a space share in various languages + Given user "Brian" has switched the system language to "" + And user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And the JSON response should contain a notification message with the subject "" and the message-details should match + """ + { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string", + "enum": [ + "" + ] + } + } + } + """ + Examples: + | language | subject | message | + | de | Space freigegeben | Alice Hansen hat Sie zu Space notification checking hinzugefügt | + | es | Space compartido | Alice Hansen te añadió al Space notification checking | + + + Scenario: all notification related to space get deleted when the sharer deletes that resource + Given user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + And user "Alice" has unshared a space "notification checking" shared with "Brian" + And user "Alice" has disabled a space "notification checking" + And user "Alice" has deleted a space "notification checking" + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And the notifications should be empty + + + Scenario: user doesn't get any notification after being removed from space + Given user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + And user "Alice" has unshared a space "notification checking" shared with "Brian" + And user "Alice" has disabled a space "notification checking" + When user "Brian" lists all notifications + Then the HTTP status code should be "200" + And user "Brian" should have "2" notifications diff --git a/tests/acceptance/features/apiSpaces/notification.feature b/tests/acceptance/features/apiSpaces/notification.feature deleted file mode 100644 index 763f8fe2602..00000000000 --- a/tests/acceptance/features/apiSpaces/notification.feature +++ /dev/null @@ -1,180 +0,0 @@ -@api -Feature: Notification - As a user - I want to be notified of actions related to me - So that I can stay updated about the information - - Background: - Given these users have been created with default attributes and without skeleton files: - | username | - | Alice | - | Brian | - | Carol | - And the administrator has given "Alice" the role "Space Admin" using the settings api - - - Scenario: user gets a notification of space sharing - Given user "Alice" has created a space "notification checking" with the default quota using the GraphApi - And user "Alice" has shared a space "notification checking" with settings: - | shareWith | Brian | - | role | editor | - When user "Brian" lists all notifications - Then the HTTP status code should be "200" - And the JSON response should contain a notification message with the subject "Space shared" and the message-details should match - """ - { - "type": "object", - "required": [ - "app", - "datetime", - "message", - "messageRich", - "messageRichParameters", - "notification_id", - "object_id", - "object_type", - "subject", - "subjectRich", - "user" - ], - "properties": { - "app": { - "type": "string", - "enum": [ - "userlog" - ] - }, - "message": { - "type": "string", - "enum": [ - "Alice Hansen added you to Space notification checking" - ] - }, - "messageRich": { - "type": "string", - "enum": [ - "{user} added you to Space {space}" - ] - }, - "messageRichParameters": { - "type": "object", - "required": [ - "space", - "user" - ], - "properties": { - "space": { - "type": "object", - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "string", - "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" - }, - "name": { - "type": "string", - "enum": [ - "notification checking" - ] - } - } - }, - "user": { - "type": "object", - "required": [ - "displayname", - "id", - "name" - ], - "properties": { - "displayname": { - "type": "string", - "enum": [ - "Alice Hansen" - ] - }, - "id": { - "type": "string", - "enim": [ - "%user_id%" - ] - }, - "name": { - "type": "string", - "enum": [ - "Alice" - ] - } - } - } - } - }, - "notification_id": { - "type": "string" - }, - "object_id": { - "type": "string", - "pattern": "^%space_id_pattern%$" - }, - "object_type": { - "type": "string", - "enum": [ - "storagespace" - ] - }, - "subject": { - "type": "string", - "enum": [ - "Space shared" - ] - }, - "subjectRich": { - "type": "string", - "enum": [ - "Space shared" - ] - }, - "user": { - "type": "string", - "enum": [ - "Alice" - ] - } - } - } - """ - - - Scenario Outline: user gets a notification of space sharing in different languages - Given user "Alice" has created a space "notification checking" with the default quota using the GraphApi - And user "Brian" has switched the system language to "" - And user "Alice" has shared a space "notification checking" with settings: - | shareWith | Brian | - | role | editor | - When user "Brian" lists all notifications - Then the HTTP status code should be "200" - And the JSON response should contain a notification message with the subject "" and the message-details should match - """ - { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string", - "enum": [ - "" - ] - } - } - } - """ - Examples: - | language | subject | message | - | de | Space freigegeben | Alice Hansen hat Sie zu Space notification checking hinzugefügt | - | en | Space shared | Alice Hansen added you to Space notification checking | - | es | Space compartido | Alice Hansen te añadió al Space notification checking | diff --git a/tests/acceptance/features/bootstrap/NotificationContext.php b/tests/acceptance/features/bootstrap/NotificationContext.php index 251ca52d357..fda104f3e89 100644 --- a/tests/acceptance/features/bootstrap/NotificationContext.php +++ b/tests/acceptance/features/bootstrap/NotificationContext.php @@ -115,6 +115,28 @@ public function theNotificationsShouldBeEmpty(): void { Assert::assertNull($notifications, "response should not contain any notification"); } + /** + * @Then /^user "([^"]*)" should have "([^"]*)" notifications$/ + * + * @param string $user + * @param int $numberOfNotification + * + * @return void + * @throws Exception + */ + public function userShouldHaveNotifications(string $user, int $numberOfNotification): void { + if (!isset($this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data)) { + throw new Exception("Notification is empty"); + } + $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data; + $actualNumber = \count($responseBody); + Assert::assertEquals( + $numberOfNotification, + $actualNumber, + "Expected number of notification was '$numberOfNotification', but got '$actualNumber'" + ); + } + /** * @Then /^the JSON response should contain a notification message with the subject "([^"]*)" and the message-details should match$/ * diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 013099414fc..0742ec5c22a 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -26,6 +26,7 @@ use Behat\Gherkin\Node\TableNode; use Psr\Http\Message\ResponseInterface; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\ExpectationFailedException; use TestHelpers\OcsApiHelper; use TestHelpers\SharingHelper; use TestHelpers\HttpRequestHelper; @@ -3449,7 +3450,7 @@ public function assertSharesOfUserAreInState(string $user, string $state, TableN Assert::assertEquals($row['path'], $share['path']); $found = true; break; - } catch (PHPUnit\Framework\ExpectationFailedException $e) { + } catch (ExpectationFailedException $e) { } } if (!$found) { diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 4918c9e46a9..499170bf138 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2132,6 +2132,28 @@ public function userHasSharedSpace( $this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus"); } + /** + * @Given user :user has unshared a space :spaceName shared with :recipient + * + * @param string $user + * @param string $spaceName + * @param string $recipient + * + * @return void + * @throws GuzzleException + */ + public function userHasUnsharedASpaceSharedWith( + string $user, + string $spaceName, + string $recipient + ): void { + $this->sendUnshareSpaceRequest($user, $spaceName, $recipient); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200" + ); + } + /** * @When /^user "([^"]*)" unshares a space "([^"]*)" to (?:user|group) "([^"]*)"$/ * @@ -2187,6 +2209,26 @@ public function sendRemoveObjectFromSpaceRequest( ); } + /** + * @Given /^user "([^"]*)" has deleted a space "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function userHasDeletedASpaceOwnedByUser( + string $user, + string $spaceName + ):void { + $this->sendDeleteSpaceRequest($user, $spaceName); + $this->featureContext->theHTTPStatusCodeShouldBe( + 204, + "Expected response status code should be 200" + ); + } + /** * @When /^user "([^"]*)" disables a space "([^"]*)"$/ * @When /^user "([^"]*)" (?:disables|tries to disable) a space "([^"]*)" owned by user "([^"]*)"$/