mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-31 01:10:20 -06:00
Add tests for deleting specific notification (#6735)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
@api
|
||||
Feature: Delete notification
|
||||
As a user
|
||||
I want to delete notifications
|
||||
So that I can filter notifications
|
||||
|
||||
Background:
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username |
|
||||
| Alice |
|
||||
| Brian |
|
||||
And user "Alice" has uploaded file with content "other data" to "/textfile1.txt"
|
||||
And user "Alice" has created folder "my_data"
|
||||
And user "Alice" has shared folder "my_data" with user "Brian"
|
||||
And user "Alice" has shared file "/textfile1.txt" with user "Brian"
|
||||
|
||||
|
||||
Scenario: delete a notification
|
||||
When user "Brian" deletes a notification related to resource "my_data" with subject "Resource shared"
|
||||
Then the HTTP status code should be "200"
|
||||
And user "Brian" should have a notification with subject "Resource shared" and message:
|
||||
| message |
|
||||
| Alice Hansen shared textfile1.txt with you |
|
||||
But user "Brian" should not have a notification related to resource "my_data" with subject "Resource shared"
|
||||
|
||||
|
||||
Scenario: delete all notifications
|
||||
When user "Brian" deletes all notifications
|
||||
Then the HTTP status code should be "200"
|
||||
And user "Brian" should not have any notification
|
||||
@@ -14,6 +14,8 @@ use TestHelpers\EmailHelper;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use TestHelpers\GraphHelper;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
require_once 'bootstrap.php';
|
||||
|
||||
@@ -104,6 +106,68 @@ class NotificationContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user deletes all notifications
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userDeletesAllNotifications(string $user):void {
|
||||
$this->userListAllNotifications($user);
|
||||
if (isset($this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data)) {
|
||||
$responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data;
|
||||
foreach ($responseBody as $value) {
|
||||
// set notificationId
|
||||
$this->notificationIds[] = $value->notification_id;
|
||||
}
|
||||
}
|
||||
$this->featureContext->setResponse($this->userDeletesNotification($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user deletes a notification related to resource :resource with subject :subject
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $resource
|
||||
* @param string $subject
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userDeletesNotificationOfResourceAndSubject(string $user, string $resource, string $subject):void {
|
||||
$this->userListAllNotifications($user);
|
||||
$this->filterResponseByNotificationSubjectAndResource($subject, $resource);
|
||||
$this->featureContext->setResponse($this->userDeletesNotification($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes notification
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userDeletesNotification(string $user):ResponseInterface {
|
||||
$this->setUserRecipient($user);
|
||||
$payload["ids"] = $this->getNotificationIds();
|
||||
return OcsApiHelper::sendRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
'DELETE',
|
||||
$this->notificationEndpointPath,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
\json_encode($payload),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the notifications should be empty
|
||||
*
|
||||
@@ -111,10 +175,31 @@ class NotificationContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theNotificationsShouldBeEmpty(): void {
|
||||
$statusCode = $this->featureContext->getResponse()->getStatusCode();
|
||||
if ($statusCode !== 200) {
|
||||
$response = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
throw new \Exception(
|
||||
__METHOD__
|
||||
. " Failed to get user notification list" . $response
|
||||
);
|
||||
}
|
||||
$notifications = $this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data;
|
||||
Assert::assertNull($notifications, "response should not contain any notification");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then user :user should not have any notification
|
||||
*
|
||||
* @param $user
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userShouldNotHaveAnyNotification($user): void {
|
||||
$this->userListAllNotifications($user);
|
||||
$this->theNotificationsShouldBeEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^user "([^"]*)" should have "([^"]*)" notifications$/
|
||||
*
|
||||
@@ -168,6 +253,8 @@ class NotificationContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* filter notification according to subject
|
||||
*
|
||||
* @param string $subject
|
||||
*
|
||||
* @return object
|
||||
@@ -191,7 +278,37 @@ class NotificationContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then user :user should get a notification with subject :subject and message:
|
||||
* filter notification according to subject and resource
|
||||
*
|
||||
* @param string $subject
|
||||
* @param string $resource
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filterResponseByNotificationSubjectAndResource(string $subject, string $resource): array {
|
||||
$responseBodyArray = [];
|
||||
$statusCode = $this->featureContext->getResponse()->getStatusCode();
|
||||
if ($statusCode !== 200) {
|
||||
$response = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
Assert::fail($response . " Response should contain status code 200");
|
||||
}
|
||||
if (isset($this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data)) {
|
||||
$responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data;
|
||||
foreach ($responseBody as $value) {
|
||||
if (isset($value->subject) && $value->subject === $subject && isset($value->messageRichParameters->resource->name) && $value->messageRichParameters->resource->name === $resource) {
|
||||
$this->notificationIds[] = $value->notification_id;
|
||||
$responseBodyArray[] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$responseBodyArray[] = $this->featureContext->getJsonDecodedResponseBodyContent();
|
||||
Assert::fail("Response should contain notification but found: $responseBodyArray");
|
||||
}
|
||||
return $responseBodyArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^user "([^"]*)" should (?:get|have) a notification with subject "([^"]*)" and message:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $subject
|
||||
@@ -201,7 +318,6 @@ class NotificationContext implements Context {
|
||||
*/
|
||||
public function userShouldGetANotificationWithMessage(string $user, string $subject, TableNode $table):void {
|
||||
$this->userListAllNotifications($user);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200);
|
||||
$actualMessage = str_replace(["\r", "\n"], " ", $this->filterResponseAccordingToNotificationSubject($subject)->message);
|
||||
$expectedMessage = $table->getColumnsHash()[0]['message'];
|
||||
Assert::assertSame(
|
||||
@@ -211,6 +327,21 @@ class NotificationContext implements Context {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then user :user should not have a notification related to resource :resource with subject :subject
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $resource
|
||||
* @param string $subject
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function userShouldNotHaveANotificationRelatedToResourceWithSubject(string $user, string $resource, string $subject):void {
|
||||
$this->userListAllNotifications($user);
|
||||
$response = $this->filterResponseByNotificationSubjectAndResource($subject, $resource);
|
||||
Assert::assertCount(0, $response, "Response should not contain notification related to resource '$resource' with subject '$subject' but found" . print_r($response, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then user :user should have received the following email from user :sender about the share of project space :spaceName
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user