From d955b070bc57ae01d6b0346b85e7944ee98b5049 Mon Sep 17 00:00:00 2001 From: pradip Date: Thu, 23 Jan 2025 15:24:59 +0545 Subject: [PATCH] tests: email notification using CLI command --- tests/acceptance/bootstrap/CliContext.php | 17 +++++ .../acceptance/bootstrap/SettingsContext.php | 71 +++++++++++++++++++ tests/acceptance/config/behat.yml | 1 + .../cliCommands/emailNotification.feature | 30 ++++++++ 4 files changed, 119 insertions(+) create mode 100644 tests/acceptance/features/cliCommands/emailNotification.feature diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index 1dae04440c3..5d41a84133f 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -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)); + } } diff --git a/tests/acceptance/bootstrap/SettingsContext.php b/tests/acceptance/bootstrap/SettingsContext.php index f52dc5fbb93..06a87accc63 100644 --- a/tests/acceptance/bootstrap/SettingsContext.php +++ b/tests/acceptance/bootstrap/SettingsContext.php @@ -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 + ); + } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index b6d00e21b16..f8889a462f7 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -461,6 +461,7 @@ default: - TagContext: - TrashbinContext: - SpacesTUSContext: + - SettingsContext: coreApiMain: paths: diff --git a/tests/acceptance/features/cliCommands/emailNotification.feature b/tests/acceptance/features/cliCommands/emailNotification.feature new file mode 100644 index 00000000000..ab37e50dd66 --- /dev/null +++ b/tests/acceptance/features/cliCommands/emailNotification.feature @@ -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 | | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + 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 |