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 4171f79
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,28 @@ config = {
"apiDepthInfinity",
"apiLocks",
"apiActivities",
],
"skip": False,
},
"settings": {
"suites": [
"apiSettings",
],
"skip": False,
"withRemotePhp": [True],
"emailNeeded": True,
"extraEnvironment": {
"EMAIL_HOST": "email",
"EMAIL_PORT": "9000",
},
"extraServerEnvironment": {
"OCIS_ADD_RUN_SERVICES": "notifications",
"NOTIFICATIONS_SMTP_HOST": "email",
"NOTIFICATIONS_SMTP_PORT": "2500",
"NOTIFICATIONS_SMTP_INSECURE": "true",
"NOTIFICATIONS_SMTP_SENDER": "ownCloud <[email protected]>",
"NOTIFICATIONS_DEBUG_ADDR": "0.0.0.0:9174",
},
},
"graph": {
"suites": [
Expand Down
17 changes: 17 additions & 0 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 @@ -555,6 +556,22 @@ public function userShouldHaveReceivedTheFollowingEmailFromUser(
$this->assertEmailContains($user, $expectedEmailBodyContent);
}

/**
* @Then user :arg1 should have :arg2 email
*
* @param string $user
* @param int $count
*
* @return void
*/
public function userShouldHaveEmail(string $user, int $count): void {
$address = $this->featureContext->getEmailAddressForUser($user);
$this->featureContext->pushEmailRecipientAsMailBox($address);
$mailBox = EmailHelper::getMailBoxFromEmail($address);
$mailboxResponse = EmailHelper::getMailboxInformation($mailBox, $this->featureContext->getStepLineRef());
Assert::assertCount($count, $mailboxResponse);
}

/**
* @Then user :user should have received the following email from user :sender ignoring whitespaces
*
Expand Down
50 changes: 50 additions & 0 deletions tests/acceptance/bootstrap/SettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,54 @@ 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 = SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
json_encode($this->getBodyForNotificationSetting($user)),
$this->featureContext->getStepLineRef(),
);
$this->featureContext->setResponse($response);
}

/**
* @param string $user
*
* @return array
*/
public function getBodyForNotificationSetting(string $user): array {
$settingsValues = (json_decode(
SettingsHelper::getBundlesList(
$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" => [
"account_uuid" => "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'));
}
}
2 changes: 2 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ default:
- FeatureContext: *common_feature_context_params
- GraphContext:
- SettingsContext:
- SharingNgContext:
- NotificationContext:

apiSharingNgShareInvitation:
paths:
Expand Down
85 changes: 85 additions & 0 deletions tests/acceptance/features/apiSettings/notificationSetting.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@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 have "0" email

0 comments on commit 4171f79

Please sign in to comment.