Skip to content

Commit

Permalink
adding test for disabling mail and in-app notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
nirajacharya2 committed Jan 2, 2025
1 parent c0772c0 commit 112ab53
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 9 deletions.
112 changes: 103 additions & 9 deletions tests/acceptance/bootstrap/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use TestHelpers\GraphHelper;
use TestHelpers\SettingsHelper;
use TestHelpers\BehatHelper;
use TestHelpers\HttpRequestHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -533,9 +534,10 @@ public function userShouldHaveReceivedTheFollowingEmailFromUserAboutTheShareOfPr
}

/**
* @Then user :user should have received the following email from user :sender
* @Then /^user "([^"]*)" should (not|)\s?have received the following email from user "([^"]*)"$/
*
* @param string $user
* @param string $shouldOrNot
* @param string $sender
* @param PyStringNode $content
*
Expand All @@ -544,6 +546,7 @@ public function userShouldHaveReceivedTheFollowingEmailFromUserAboutTheShareOfPr
*/
public function userShouldHaveReceivedTheFollowingEmailFromUser(
string $user,
string $shouldOrNot,
string $sender,
PyStringNode $content
): void {
Expand All @@ -552,7 +555,7 @@ public function userShouldHaveReceivedTheFollowingEmailFromUser(
$rawExpectedEmailBodyContent,
$sender
);
$this->assertEmailContains($user, $expectedEmailBodyContent);
$this->assertEmailContains($user, $expectedEmailBodyContent, false, $shouldOrNot === "");
}

/**
Expand Down Expand Up @@ -582,14 +585,16 @@ public function userShouldHaveReceivedTheFollowingEmailFromUserIgnoringWhitespac
* @param string $user
* @param string $expectedEmailBodyContent
* @param bool $ignoreWhiteSpace
* @param bool $contains
*
* @return void
* @throws GuzzleException
*/
public function assertEmailContains(
string $user,
string $expectedEmailBodyContent,
$ignoreWhiteSpace = false
bool $ignoreWhiteSpace = false,
bool $contains = true,
): void {
$address = $this->featureContext->getEmailAddressForUser($user);
$this->featureContext->pushEmailRecipientAsMailBox($address);
Expand All @@ -598,13 +603,23 @@ public function assertEmailContains(
$expectedEmailBodyContent = preg_replace('/\s+/', '', $expectedEmailBodyContent);
$actualEmailBodyContent = preg_replace('/\s+/', '', $actualEmailBodyContent);
}
Assert::assertStringContainsString(
$expectedEmailBodyContent,
$actualEmailBodyContent,
"The email address '$address' should have received an"
. "email with the body containing $expectedEmailBodyContent
if ($contains) {
Assert::assertStringContainsString(
$expectedEmailBodyContent,
$actualEmailBodyContent,
"The email address '$address' should have received an"
. "email with the body containing $expectedEmailBodyContent
but the received email is $actualEmailBodyContent"
);
);
} else {
Assert::assertStringNotContainsString(
$expectedEmailBodyContent,
$actualEmailBodyContent,
"The email address '$address' shouldn't have received an"
. "email with the body containing $expectedEmailBodyContent
but received the email: $actualEmailBodyContent"
);
}
}

/**
Expand Down Expand Up @@ -732,4 +747,83 @@ public function userDeletesDeprovisioningNotification(?string $user = null): voi
);
$this->featureContext->setResponse($response);
}

/**
* @When user :user updates following notification settings:
*
* @param string $user
* @param TableNode $tableNode
*
* @return void
*/
public function userUpdatesTheFollowingNotificationSettings(string $user, TableNode $tableNode): void {
$response = HttpRequestHelper::sendRequest(
$this->featureContext->getBaseUrl() . "/api/v0/settings/values-save",
null,
'POST',
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
null,
json_encode($this->createBodyForNotificationSetting($user, $tableNode)),
);
$this->featureContext->setResponse($response);
}

/**
* @param string $user
*
* @return ResponseInterface
*/
public function getSettingLists(string $user): ResponseInterface {
return HttpRequestHelper::sendRequest(
$this->featureContext->getBaseUrl() . "/api/v0/settings/values-list",
null,
'POST',
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
null,
json_encode(["account_uuid" => "me"]),
);
}

/**
* @param string $user
* @param TableNode $tableNode
*
* @return array
*/
public function createBodyForNotificationSetting(string $user, TableNode $tableNode): array {
$settingsValues = $this->getSettingLists($user);
$notificationSetting = $tableNode->getRowsHash();
$settingsValues = (json_decode($settingsValues->getBody()->getContents()));
foreach ($settingsValues->values as $settingsValue) {
if ($settingsValue->identifier->setting === "event-share-created-options") {
return [
"value" => [
"accountUuid" => "me",
"bundleId" => $settingsValue->value->bundleId,
"settingId" => $settingsValue->value->settingId,
"resource" => [
"type" => $settingsValue->value->resource->type
],
"boolValue" => true,
"collectionValue" => [
"values" => [
[
"key" => "mail",
"boolValue" => !$notificationSetting["mail"] === "false"
],
[
"key" => "in-app",
"boolValue" => !$notificationSetting["in-app"] === "false"
]
]
]
]
];
}
}
throw new Exception(('`event-share-created-options` not found in the setting list'));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@email
Feature: Notification Settings
As a user
I want to manage my notification settings
So that i am not bothered by unimportant events


Scenario: disable mail and in-app notification
Given these users have been created with default attributes:
| username |
| Alice |
| Brian |
And user "Alice" has uploaded file with content "other data" to "textfile.txt"
And user "Alice" has uploaded file with content "other data" to "textfile1.txt"
And user "Alice" has sent the following resource share invitation:
| resource | textfile.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
When user "Brian" updates following notification settings:
| mail | false |
| in-app | false |
Then the HTTP status code should be "201"
And user "Alice" has sent the following resource share invitation:
| resource | textfile1.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
And user "Brian" should have received the following email from user "Alice"
"""
Hello Brian Murphy
%displayname% has shared "textfile.txt" with you.
Click here to view it: %base_url%/files/shares/with-me
"""
And user "Brian" should not have received the following email from user "Alice"
"""
Hello Brian Murphy
%displayname% has shared "textfile1.txt" with you.
Click here to view it: %base_url%/files/shares/with-me
"""
And user "Brian" should have a notification with subject "Resource shared" and message:
| message |
| Alice Hansen shared textfile.txt with you |
But user "Brian" should not have a notification related to resource "textfile1.txt" with subject "Resource shared"

0 comments on commit 112ab53

Please sign in to comment.