Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] adding test for disabling mail notifications #10820

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions tests/acceptance/bootstrap/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,22 @@ public function userShouldHaveReceivedTheFollowingEmailFromUser(
$this->assertEmailContains($user, $expectedEmailBodyContent);
}

/**
* @Then user :user should have :count emails
*
* @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" emails