Skip to content

Commit 4a2650a

Browse files
committed
adding test for disabling mail and in app notifications for share create event
1 parent 2279b8f commit 4a2650a

File tree

2 files changed

+239
-11
lines changed

2 files changed

+239
-11
lines changed

tests/acceptance/bootstrap/SettingsContext.php

+104-5
Original file line numberDiff line numberDiff line change
@@ -566,18 +566,19 @@ public function userDisablesEmailNotificationUsingTheSettingsAPI(string $user):
566566
$this->featureContext->getBaseUrl(),
567567
$this->featureContext->getActualUsername($user),
568568
$this->featureContext->getPasswordForUser($user),
569-
json_encode($this->getBodyForNotificationSetting($user)),
569+
json_encode($this->getBodyForNotificationSetting($user, "Disable Email Notifications")),
570570
$this->featureContext->getStepLineRef(),
571571
);
572572
$this->featureContext->setResponse($response);
573573
}
574574

575575
/**
576576
* @param string $user
577+
* @param string $event
577578
*
578579
* @return array
579580
*/
580-
public function getBodyForNotificationSetting(string $user): array {
581+
public function getBodyForNotificationSetting(string $user, string $event): array {
581582
$settingsValues = (json_decode(
582583
SettingsHelper::getBundlesList(
583584
$this->featureContext->getBaseUrl(),
@@ -587,7 +588,7 @@ public function getBodyForNotificationSetting(string $user): array {
587588
)->getBody()->getContents()
588589
));
589590
foreach ($settingsValues->bundles[0]->settings as $settingsValue) {
590-
if ($settingsValue->name === "disable-email-notifications") {
591+
if ($settingsValue->displayName === $this->getDisplayNameFromEvents($event)) {
591592
return [
592593
"value" => [
593594
"account_uuid" => "me",
@@ -596,11 +597,109 @@ public function getBodyForNotificationSetting(string $user): array {
596597
"resource" => [
597598
"type" => $settingsValue->resource->type
598599
],
599-
"boolValue" => true
600600
]
601601
];
602602
}
603603
}
604-
throw new Exception(('`disable-email-notifications` not found in the setting list'));
604+
throw new Exception(("'$event' not found in the setting list"));
605+
}
606+
607+
/**
608+
* @When /^user "([^"]*)" (disables|enables) notification for following event using Settings API:$/
609+
*
610+
* @param string $user
611+
* @param string $enableOrDisable
612+
* @param TableNode $table
613+
*
614+
* @return void
615+
*/
616+
public function userDisablesNotificationForFollowingEventUsingSettingsApi(
617+
string $user,
618+
string $enableOrDisable,
619+
TableNode $table
620+
): void {
621+
$settings = $table->getRowsHash();
622+
foreach ($settings as $event => $value) {
623+
$body = $this->getBodyForNotificationSetting($user, $event);
624+
if (str_contains($value, "mail")) {
625+
$body["value"]["collectionValue"]["values"][]
626+
= ["key" => "mail","boolValue" => $enableOrDisable === "enables"];
627+
}
628+
if (str_contains($value, "in-app")) {
629+
$body["value"]["collectionValue"]["values"][]
630+
= ["key" => "in-app","boolValue" => $enableOrDisable === "enables"];
631+
}
632+
$response = HttpRequestHelper::sendRequest(
633+
$this->featureContext->getBaseUrl() . "/api/v0/settings/values-save",
634+
$this->featureContext->getStepLineRef(),
635+
'POST',
636+
$this->featureContext->getActualUsername($user),
637+
$this->featureContext->getPasswordForUser($user),
638+
null,
639+
json_encode($body),
640+
);
641+
$this->featureContext->setResponse($response);
642+
}
643+
}
644+
645+
/**
646+
* @Given /^user "([^"]*)" has (disabled|enabled) notification for following event using Settings API:$/
647+
*
648+
* @param string $user
649+
* @param string $enableOrDisable
650+
* @param TableNode $table
651+
*
652+
* @return void
653+
*/
654+
public function userHasDisabledOrEnabledNotificationForFollowingEventUsingSettingsApi(
655+
string $user,
656+
string $enableOrDisable,
657+
TableNode $table
658+
): void {
659+
$settings = $table->getRowsHash();
660+
foreach ($settings as $event => $value) {
661+
// var_dump("$event: $value");
662+
$body = $this->getBodyForNotificationSetting($user, $event);
663+
if (str_contains($value, "mail")) {
664+
$body["value"]["collectionValue"]["values"][]
665+
= ["key" => "mail","boolValue" => $enableOrDisable === "enables"];
666+
}
667+
if (str_contains($value, "in-app")) {
668+
$body["value"]["collectionValue"]["values"][]
669+
= ["key" => "in-app","boolValue" => $enableOrDisable === "enables"];
670+
}
671+
$response = HttpRequestHelper::sendRequest(
672+
$this->featureContext->getBaseUrl() . "/api/v0/settings/values-save",
673+
$this->featureContext->getStepLineRef(),
674+
'POST',
675+
$this->featureContext->getActualUsername($user),
676+
$this->featureContext->getPasswordForUser($user),
677+
null,
678+
json_encode($body),
679+
);
680+
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
681+
}
682+
}
683+
684+
/**
685+
* @param string $event
686+
*
687+
* @return string
688+
*/
689+
public function getDisplayNameFromEvents(string $event): string {
690+
switch ($event) {
691+
case "Share created":
692+
return "Share Received";
693+
case "Space shared":
694+
return "Added as space member";
695+
case "Space unshared":
696+
return "Removed as space member";
697+
case "Space expired":
698+
return "Space membership expired";
699+
case "Postprocessing Step Finished":
700+
return "File rejected";
701+
default:
702+
return $event;
703+
}
605704
}
606705
}

tests/acceptance/features/apiSettings/notificationSetting.feature

+135-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ Feature: Notification Settings
44
I want to manage my notification settings
55
So that I do not get notified of unimportant events
66

7-
8-
Scenario: disable email notification
7+
Background:
98
Given these users have been created with default attributes:
109
| username |
1110
| Alice |
1211
| Brian |
1312
And user "Alice" has uploaded file with content "some data" to "lorem.txt"
13+
14+
15+
Scenario: disable email notification
16+
Given user "Alice" has uploaded file with content "some data" to "lorem.txt"
1417
When user "Brian" disables email notification using the settings API
1518
Then the HTTP status code should be "201"
1619
And the JSON data of the response should match
@@ -41,13 +44,93 @@ Feature: Notification Settings
4144
"value":{
4245
"type": "object",
4346
"required": [
47+
"id",
48+
"bundleId",
49+
"settingId",
50+
"accountUuid",
51+
"resource"
52+
],
53+
"properties":{
54+
"id":{
55+
"pattern": "%user_id_pattern%"
56+
},
57+
"bundleId":{
58+
"pattern":"%user_id_pattern%"
59+
},
60+
"settingId":{
61+
"pattern":"%user_id_pattern%"
62+
},
63+
"accountUuid":{
64+
"pattern":"%user_id_pattern%"
65+
},
66+
"resource":{
67+
"type": "object",
68+
"required":["type"],
69+
"properties": {
70+
"type":{
71+
"const": "TYPE_USER"
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
"""
82+
And user "Alice" has sent the following resource share invitation:
83+
| resource | lorem.txt |
84+
| space | Personal |
85+
| sharee | Brian |
86+
| shareType | user |
87+
| permissionsRole | Viewer |
88+
And user "Brian" should have "0" emails
89+
90+
91+
Scenario: disable mail and in-app notification for Share created event
92+
When user "Brian" disables notification for following event using Settings API:
93+
| Share created | mail,in-app |
94+
Then the HTTP status code should be "201"
95+
And the JSON data of the response should match
96+
"""
97+
{
98+
"type": "object",
99+
"required": ["value"],
100+
"properties": {
101+
"value": {
102+
"type": "object",
103+
"required": ["identifier","value"],
104+
"properties": {
105+
"identifier":{
106+
"type": "object",
107+
"required": ["extension","bundle","setting"],
108+
"properties": {
109+
"extension":{
110+
"const": "ocis-accounts"
111+
},
112+
"bundle":{
113+
"const": "profile"
114+
},
115+
"setting":{
116+
"const": "event-share-created-options"
117+
}
118+
}
119+
},
120+
"value":{
121+
"type": "object",
122+
"required": [
123+
"id",
44124
"bundleId",
45125
"settingId",
46126
"accountUuid",
47127
"resource",
48-
"boolValue"
128+
"collectionValue"
49129
],
50130
"properties":{
131+
"id":{
132+
"pattern":"%user_id_pattern%"
133+
},
51134
"bundleId":{
52135
"pattern":"%user_id_pattern%"
53136
},
@@ -66,8 +149,51 @@ Feature: Notification Settings
66149
}
67150
}
68151
},
69-
"boolValue":{
70-
"const": true
152+
"collectionValue":{
153+
"type": "object",
154+
"required":["values"],
155+
"properties": {
156+
"values":{
157+
"type": "array",
158+
"maxItems": 2,
159+
"minItems": 2,
160+
"uniqueItems": true,
161+
"items": {
162+
"oneOf": [
163+
{
164+
"type": "object",
165+
"required": [
166+
"key",
167+
"boolValue"
168+
],
169+
"properties": {
170+
"key":{
171+
"const": "mail"
172+
},
173+
"boolValue":{
174+
"const": false
175+
}
176+
}
177+
},
178+
{
179+
"type": "object",
180+
"required": [
181+
"key",
182+
"boolValue"
183+
],
184+
"properties": {
185+
"key":{
186+
"const": "in-app"
187+
},
188+
"boolValue":{
189+
"const": false
190+
}
191+
}
192+
}
193+
]
194+
}
195+
}
196+
}
71197
}
72198
}
73199
}
@@ -82,4 +208,7 @@ Feature: Notification Settings
82208
| sharee | Brian |
83209
| shareType | user |
84210
| permissionsRole | Viewer |
85-
And user "Brian" should have "0" emails
211+
And user "Brian" should have "0" emails
212+
When user "Brian" lists all notifications
213+
Then the HTTP status code should be "200"
214+
And the notifications should be empty

0 commit comments

Comments
 (0)