@@ -566,18 +566,19 @@ public function userDisablesEmailNotificationUsingTheSettingsAPI(string $user):
566
566
$ this ->featureContext ->getBaseUrl (),
567
567
$ this ->featureContext ->getActualUsername ($ user ),
568
568
$ this ->featureContext ->getPasswordForUser ($ user ),
569
- json_encode ($ this ->getBodyForNotificationSetting ($ user )),
569
+ json_encode ($ this ->getBodyForNotificationSetting ($ user, " Disable Email Notifications " )),
570
570
$ this ->featureContext ->getStepLineRef (),
571
571
);
572
572
$ this ->featureContext ->setResponse ($ response );
573
573
}
574
574
575
575
/**
576
576
* @param string $user
577
+ * @param string $event
577
578
*
578
579
* @return array
579
580
*/
580
- public function getBodyForNotificationSetting (string $ user ): array {
581
+ public function getBodyForNotificationSetting (string $ user, string $ event ): array {
581
582
$ settingsValues = (json_decode (
582
583
SettingsHelper::getBundlesList (
583
584
$ this ->featureContext ->getBaseUrl (),
@@ -587,7 +588,7 @@ public function getBodyForNotificationSetting(string $user): array {
587
588
)->getBody ()->getContents ()
588
589
));
589
590
foreach ($ settingsValues ->bundles [0 ]->settings as $ settingsValue ) {
590
- if ($ settingsValue ->name === " disable-email-notifications " ) {
591
+ if ($ settingsValue ->displayName === $ this -> getDisplayNameFromEvents ( $ event ) ) {
591
592
return [
592
593
"value " => [
593
594
"account_uuid " => "me " ,
@@ -596,11 +597,109 @@ public function getBodyForNotificationSetting(string $user): array {
596
597
"resource " => [
597
598
"type " => $ settingsValue ->resource ->type
598
599
],
599
- "boolValue " => true
600
600
]
601
601
];
602
602
}
603
603
}
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
+ }
605
704
}
606
705
}
0 commit comments