Skip to content

Commit

Permalink
Add tests to delete all notification
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Jul 11, 2023
1 parent f091fe7 commit 75047f3
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 65 deletions.
2 changes: 1 addition & 1 deletion tests/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static function printHeaders(?array $headers):void {
*/
private static function printBody(?StreamInterface $body):void {
print("Body:\n");
\print_r($body->getContents());
\var_dump($body->getContents());
// Rewind the stream so that later code can read from the start.
$body->rewind();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@api
Feature: 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"


Scenario: user deletes a notification
Given user "Alice" has shared entry "my_data" with user "Brian"
And user "Alice" has shared entry "/textfile1.txt" with user "Brian"
When user "Brian" deletes the 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 |


Scenario: user deletes all notification
Given user "Alice" has shared entry "my_data" with user "Brian"
And user "Alice" has shared entry "/textfile1.txt" with user "Brian"
When user "Brian" deletes all notification
Then the HTTP status code should be "200"
10 changes: 0 additions & 10 deletions tests/acceptance/features/apiNotification/notification.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ Feature: Notification
And user "Alice" has created folder "my_data"


Scenario: user gets a notification of resource sharing
Given user "Alice" has shared entry "my_data" with user "Brian"
And user "Alice" has shared entry "/textfile1.txt" with user "Brian"
When user "Brian" deletes notification of 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 |


Scenario Outline: user gets a notification of resource sharing
Given user "Alice" has shared entry "<resource>" with user "Brian"
When user "Brian" lists all notifications
Expand Down
139 changes: 85 additions & 54 deletions tests/acceptance/features/bootstrap/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\Assert;
use TestHelpers\GraphHelper;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -104,39 +105,70 @@ public function userListAllNotifications(string $user):void {
$this->featureContext->setResponse($response);
}

/**
* @When user :user deletes notification of resource :resource with subject :subject
*/
public function userDeletesNotificationOfResourceAndSubject($user, $resource, $subject):void
{
$this->userListAllNotifications($user);
$this->filterResponseByNotificationSubjectAndResource($subject,$resource);
$notificationID = $this->getNotificationIds();
$this->userDeleteNotification($user,$notificationID);
/**
* @When user :user deletes all notification
*
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userDeletesAllNotification(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->userDeleteNotification($user);
}

}
/**
* delete notfication
*/
public function userDeleteNotification($user, $notificationID):void{
$this->setUserRecipient($user);
$headers = ["accept-language" => $this->settingsContext->getSettingLanguageValue($user)];
$payload["ids"]=$notificationID;
var_dump($payload);
$response = OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
'DELETE',
$this->notificationEndpointPath,
$this->featureContext->getStepLineRef(),
\json_encode($payload),
2,
$headers
);
$this->featureContext->setResponse($response);
/**
* @When user :user deletes the 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->userDeleteNotification($user);
}

}
/**
* deletes notification
*
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userDeleteNotification(string $user):void {
$this->setUserRecipient($user);
$headers = ["accept-language" => $this->settingsContext->getSettingLanguageValue($user)];
$payload["ids"] = $this->getNotificationIds();
$response = OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
'DELETE',
$this->notificationEndpointPath,
$this->featureContext->getStepLineRef(),
\json_encode($payload),
2,
$headers
);
$this->featureContext->setResponse($response);
}

/**
* @Then the notifications should be empty
Expand Down Expand Up @@ -224,31 +256,30 @@ public function filterResponseAccordingToNotificationSubject(string $subject): o
return $responseBody;
}

/**
* @param string $subject
* @param string $resource
*
* @return array
*/
public function filterResponseByNotificationSubjectAndResource(string $subject, string $resource): array {
$responseBodyArray = [];
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) {
$responseBodyArray[] = $value;
$this->notificationIds[] = $value->notification_id;
}
}
} else {
$responseBodyArray[] = $this->featureContext->getJsonDecodedResponseBodyContent();
}
return $responseBodyArray;
}
/**
* @param string $subject
* @param string $resource
*
* @return array
*/
public function filterResponseByNotificationSubjectAndResource(string $subject, string $resource): array {
$responseBodyArray = [];
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) {
$responseBodyArray[] = $value;
$this->notificationIds[] = $value->notification_id;
}
}
} else {
$responseBodyArray[] = $this->featureContext->getJsonDecodedResponseBodyContent();
}
return $responseBodyArray;
}

/**
* @Then user :user should get a notification with subject :subject and message:
* @Then user :user should have a notification with subject :subject and message:
* @Then /^user "([^"]*)" should (?:get|have) a notification with subject "([^"]*)" and message:$/
*
* @param string $user
* @param string $subject
Expand Down

0 comments on commit 75047f3

Please sign in to comment.