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 10, 2025
1 parent b48b113 commit d32a39e
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 11 deletions.
26 changes: 26 additions & 0 deletions tests/acceptance/TestHelpers/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,30 @@ public static function updateSettings(
$body
);
}

/**
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $xRequestId
*
* @return ResponseInterface
*/
public static function getSettingsList(
string $baseUrl,
string $user,
string $password,
string $xRequestId,
): ResponseInterface {
return HttpRequestHelper::sendRequest(
$baseUrl . "/api/v0/settings/bundles-list",
$xRequestId,
'POST',
$user,
$password,
null,
'{}',
);
}
}
37 changes: 26 additions & 11 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,17 +534,19 @@ public function userShouldHaveReceivedTheFollowingEmailFromUserAboutTheShareOfPr
}

/**
* @Then user :user should have received the following email from user :sender
* @Then /^user "([^"]*)" (should|should not) have received the following email from user "([^"]*)"$/
*
* @param string $user
* @param string $shouldOrNot
* @param string $sender
* @param PyStringNode $content
*
* @return void
* @throws Exception
*/
public function userShouldHaveReceivedTheFollowingEmailFromUser(
public function userShouldOrShouldNotHaveReceivedTheFollowingEmailFromUser(
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 === "should");
}

/**
Expand Down Expand Up @@ -582,14 +585,16 @@ public function userShouldHaveReceivedTheFollowingEmailFromUserIgnoringWhitespac
* @param string $user
* @param string $expectedEmailBodyContent
* @param bool $ignoreWhiteSpace
* @param bool $emailShouldContain
*
* @return void
* @throws GuzzleException
*/
public function assertEmailContains(
string $user,
string $expectedEmailBodyContent,
$ignoreWhiteSpace = false
bool $ignoreWhiteSpace = false,
bool $emailShouldContain = 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
but the received email is $actualEmailBodyContent"
);
if ($emailShouldContain) {
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 email: $actualEmailBodyContent"
);
}
}

/**
Expand Down
52 changes: 52 additions & 0 deletions tests/acceptance/bootstrap/SettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,56 @@ public function userDisablesAutoAcceptingUsingSettingsApi(string $user): void {
$this->featureContext->setResponse($response);
$this->featureContext->rememberUserAutoSyncSetting($user, false);
}

/**
* @When user :user disables email notification using the settings API
*
* @param string $user
*
* @return void
*/
public function userDisablesEmailNotificationUsingTheSettingsAPI(string $user): void {
$response = HttpRequestHelper::sendRequest(
$this->featureContext->getBaseUrl() . "/api/v0/settings/values-save",
$this->featureContext->getStepLineRef(),
'POST',
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
null,
json_encode($this->getBodyForNotificationSetting($user)),
);
$this->featureContext->setResponse($response);
}

/**
* @param string $user
*
* @return array
*/
public function getBodyForNotificationSetting(string $user): array {
$settingsValues = (json_decode(
SettingsHelper::getSettingsList(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getStepLineRef(),
)->getBody()->getContents()
));
foreach ($settingsValues->bundles[0]->settings as $settingsValue) {
if ($settingsValue->name === "disable-email-notifications") {
return [
"value" => [
"accountUuid" => "me",
"bundleId" => $settingsValues->bundles[0]->id,
"settingId" => $settingsValue->id,
"resource" => [
"type" => $settingsValue->resource->type
],
"boolValue" => true
]
];
}
}
throw new Exception(('`disable-email-notifications` not found in the setting list'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@email
Feature: Notification Settings
As a user
I want to manage my notification settings
So that I do not get notified of unimportant events


Scenario: disable email notification
Given these users have been created with default attributes:
| username |
| Alice |
| Brian |
And user "Alice" has uploaded file with content "some data" to "lorem.txt"
When user "Brian" disables email notification using the settings API
Then the HTTP status code should be "201"
And the JSON data of the response should match
"""
{
"type": "object",
"required": ["value"],
"properties": {
"value": {
"type": "object",
"required": ["identifier","value"],
"properties": {
"identifier":{
"type": "object",
"required": ["extension","bundle","setting"],
"properties": {
"extension":{
"const": "ocis-accounts"
},
"bundle":{
"const": "profile"
},
"setting":{
"const": "disable-email-notifications"
}
}
},
"value":{
"type": "object",
"required": [
"bundleId",
"settingId",
"accountUuid",
"resource",
"boolValue"
],
"properties":{
"bundleId":{
"pattern":"%user_id_pattern%"
},
"settingId":{
"pattern":"%user_id_pattern%"
},
"accountUuid":{
"pattern":"%user_id_pattern%"
},
"resource":{
"type": "object",
"required":["type"],
"properties": {
"type":{
"const": "TYPE_USER"
}
}
},
"boolValue":{
"const": true
}
}
}
}
}
}
}
"""
And user "Alice" has sent the following resource share invitation:
| resource | lorem.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
And user "Brian" should not have received the following email from user "Alice"
"""
Hello Brian Murphy
%displayname% has shared "lorem.txt" with you.
Click here to view it: %base_url%/files/shares/with-me
"""

0 comments on commit d32a39e

Please sign in to comment.