Skip to content

Commit 4d5fba1

Browse files
authored
Merge pull request #11530 from owncloud/test/delete-notification-by-id
[tests-only][full-ci] Add test to delete a notification using its id
2 parents b9b9add + bb8d47e commit 4d5fba1

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

tests/acceptance/bootstrap/NotificationContext.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class NotificationContext implements Context {
2626
private FeatureContext $featureContext;
27-
private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json';
27+
private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications';
2828
private string $globalNotificationEndpointPath = '/apps/notifications/api/v1/notifications/global';
2929

3030
private array $notificationIds;
@@ -115,7 +115,7 @@ public function listAllNotifications(string $user): ResponseInterface {
115115
$this->featureContext->getActualUsername($user),
116116
$this->featureContext->getPasswordForUser($user),
117117
'GET',
118-
$this->notificationEndpointPath,
118+
$this->notificationEndpointPath . '?format=json',
119119
[],
120120
2,
121121
$headers,
@@ -216,7 +216,7 @@ public function userDeletesNotification(string $user): ResponseInterface {
216216
$this->featureContext->getActualUsername($user),
217217
$this->featureContext->getPasswordForUser($user),
218218
'DELETE',
219-
$this->notificationEndpointPath,
219+
$this->notificationEndpointPath . '?format=json',
220220
\json_encode($payload),
221221
2,
222222
);
@@ -614,4 +614,50 @@ public function userDeletesDeprovisioningNotification(?string $user = null): voi
614614
);
615615
$this->featureContext->setResponse($response);
616616
}
617+
618+
/**
619+
* deletes notification using id
620+
*
621+
* @param string $user
622+
* @param string $notificationId
623+
*
624+
* @return ResponseInterface
625+
* @throws GuzzleException
626+
* @throws JsonException
627+
*/
628+
public function deleteNotificationUsingId(string $user, string $notificationId): ResponseInterface {
629+
$deleteNotificationEndpoint = $this->notificationEndpointPath . '/' . $notificationId;
630+
return OcsApiHelper::sendRequest(
631+
$this->featureContext->getBaseUrl(),
632+
$this->featureContext->getActualUsername($user),
633+
$this->featureContext->getPasswordForUser($user),
634+
'DELETE',
635+
$deleteNotificationEndpoint,
636+
);
637+
}
638+
639+
/**
640+
* @When user :user deletes a notification related to resource :resource with subject :subject using id
641+
*
642+
* @param string $user
643+
* @param string $resource
644+
* @param string $subject
645+
*
646+
* @return void
647+
* @throws GuzzleException
648+
* @throws JsonException
649+
*/
650+
public function userDeletesNotificationOfResourceAndSubjectById(
651+
string $user,
652+
string $resource,
653+
string $subject,
654+
): void {
655+
$allNotifications = $this->listAllNotifications($user);
656+
$filteredNotificationId = $this->filterNotificationsBySubjectAndResource(
657+
$subject,
658+
$resource,
659+
$allNotifications,
660+
)[0]->notification_id;
661+
$this->featureContext->setResponse($this->deleteNotificationUsingId($user, $filteredNotificationId));
662+
}
617663
}

tests/acceptance/features/apiNotification/deleteNotification.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ Feature: Delete notification
3838
When user "Brian" deletes all notifications
3939
Then the HTTP status code should be "200"
4040
And user "Brian" should not have any notification
41+
42+
43+
Scenario: delete a notification using id
44+
When user "Brian" deletes a notification related to resource "my_data" with subject "Resource shared" using id
45+
Then the HTTP status code should be "200"
46+
And user "Brian" should have a notification with subject "Resource shared" and message:
47+
| message |
48+
| Alice Hansen shared textfile1.txt with you |
49+
But user "Brian" should not have a notification related to resource "my_data" with subject "Resource shared"

0 commit comments

Comments
 (0)