Skip to content

Commit

Permalink
tests: email notification using CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
anon-pradip committed Jan 27, 2025
1 parent d7156bc commit d955b07
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/acceptance/bootstrap/CliContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,21 @@ public function cleanUploadsSessions(): void {
$response = CliHelper::runCommand($body);
Assert::assertEquals("200", $response->getStatusCode(), "Failed to clean upload sessions");
}

/**
* @When /^the administrator triggers "([^"]*)" email notifications using the CLI$/
*
* @param string $interval
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function theAdministratorTriggersEmailNotificationsUsingTheCLI(string $interval): void {
$command = $interval === "daily" ? "notifications send-email --daily" : "notifications send-email --weekly";
$body = [
"command" => $command
];

$this->featureContext->setResponse(CliHelper::runCommand($body));
}
}
71 changes: 71 additions & 0 deletions tests/acceptance/bootstrap/SettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,4 +642,75 @@ public function userDisablesNotificationForFollowingEventUsingSettingsApi(
$this->featureContext->setResponse($response);
}
}

/**
* @param string $user
* @param string $interval
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestToSwitchEmailSendingInterval(string $user, string $interval): ResponseInterface {
$profileBundlesList = $this->getBundleByName($user, "Profile");
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");

$settingId = '';
foreach ($profileBundlesList["settings"] as $value) {
if ($value["name"] === "email-sending-interval-options") {
$settingId = $value["id"];
break;
}
}
Assert::assertNotEmpty($settingId, "settingId is empty");

$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$body = json_encode(
[
"value" => [
"account_uuid" => "me",
"bundleId" => $profileBundlesList["id"],
"id" => $userId,
"listValue" => [
"values" => [
[
"stringValue" => $interval
]
]
],
"resource" => [
"type" => "TYPE_USER"
],
"settingId" => $settingId
]
],
JSON_THROW_ON_ERROR
);
return SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$this->featureContext->getStepLineRef()
);
}

/**
* @Given /^user "([^"]*)" has switched the email sending interval to "([^"]*)" using the settings API$/
*
* @param string $user
* @param string $interval
*
* @return void
* @throws GuzzleException
*/
public function userHasSwitchedTheEmailSendingIntervalTo(string $user, string $interval): void {
$response = $this->sendRequestToSwitchEmailSendingInterval($user, $interval);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response
);
}
}
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ default:
- TagContext:
- TrashbinContext:
- SpacesTUSContext:
- SettingsContext:

coreApiMain:
paths:
Expand Down
30 changes: 30 additions & 0 deletions tests/acceptance/features/cliCommands/emailNotification.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@env-config @email
Feature: get email notification via CLI command

Background:
Given these users have been created with default attributes:
| username |
| Alice |
| Brian |


Scenario Outline: get daily/weekly email notification when someone shares a resource
Given user "Alice" has created folder "FolderToShare"
And user "Alice" has uploaded file with content "some data" to "lorem.txt"
And user "Brian" has switched the email sending interval to "daily" using the settings API
And user "Alice" has sent the following resource share invitation:
| resource | <resource> |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | <permissions-role> |
When the administrator triggers "daily" email notifications using the CLI
Then the command should be successful
And the command output should contain "successfully sent SendEmailsEvent"
Examples:
| permissions-role | resource |
| Viewer | lorem.txt |
| File Editor | lorem.txt |
| Viewer | FolderToShare |
| Editor | FolderToShare |
| Uploader | FolderToShare |

0 comments on commit d955b07

Please sign in to comment.