adding test for disabling mail notifications for space disabled event

This commit is contained in:
Niraj Acharya
2025-01-20 16:08:34 +05:45
parent 98f5df181d
commit 2bbc4d6177
3 changed files with 142 additions and 5 deletions

View File

@@ -380,6 +380,40 @@ class NotificationContext implements Context {
return $filteredNotifications;
}
/**
* filter notification according to subject and space
*
* @param string $subject
* @param string $space
* @param ResponseInterface|null $response
*
* @return array
*/
public function filterNotificationsBySubjectAndSpace(
string $subject,
string $space,
?ResponseInterface $response = null
): array {
$filteredNotifications = [];
$response = $response ?? $this->featureContext->getResponse();
$responseObject = $this->featureContext->getJsonDecodedResponseBodyContent($response);
if (!isset($responseObject->ocs->data)) {
Assert::fail("Response doesn't contain notification: " . print_r($responseObject, true));
}
$notifications = $responseObject->ocs->data;
foreach ($notifications as $notification) {
if (isset($notification->subject) && $notification->subject === $subject
&& isset($notification->messageRichParameters->space->name)
&& $notification->messageRichParameters->space->name === $space
) {
$this->notificationIds[] = $notification->notification_id;
$filteredNotifications[] = $notification;
}
}
return $filteredNotifications;
}
/**
* @Then /^user "([^"]*)" should (?:get|have) a notification with subject "([^"]*)" and message:$/
*
@@ -466,21 +500,27 @@ class NotificationContext implements Context {
}
/**
* @Then user :user should not have a notification related to resource :resource with subject :subject
* @Then /^user "([^"]*)" should not have a notification related to (resource|space) "([^"]*)" with subject "([^"]*)"$/
*
* @param string $user
* @param string $resourceOrSpace
* @param string $resource
* @param string $subject
*
* @return void
*/
public function userShouldNotHaveANotificationRelatedToResourceWithSubject(
public function userShouldNotHaveANotificationRelatedToResourceOrSpaceWithSubject(
string $user,
string $resourceOrSpace,
string $resource,
string $subject
): void {
$response = $this->listAllNotifications($user);
$filteredResponse = $this->filterNotificationsBySubjectAndResource($subject, $resource, $response);
if ($resourceOrSpace === "space") {
$filteredResponse = $this->filterNotificationsBySubjectAndSpace($subject, $resource, $response);
} else {
$filteredResponse = $this->filterNotificationsBySubjectAndResource($subject, $resource, $response);
}
Assert::assertCount(
0,
$filteredResponse,