-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api-test] first notification test (#5958)
* notification test * fix after review * fix lint
- Loading branch information
1 parent
351ad9c
commit e3c5466
Showing
3 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tests/acceptance/features/apiSpaces/notification.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
@api @skipOnOcV10 | ||
Feature: Notification | ||
As a user | ||
I want to be notified of actions related to me | ||
|
||
Background: | ||
Given these users have been created with default attributes and without skeleton files: | ||
| username | | ||
| Alice | | ||
| Brian | | ||
| Carol | | ||
And the administrator has given "Alice" the role "Space Admin" using the settings api | ||
|
||
|
||
Scenario: user gets a notification of space sharing | ||
Given user "Alice" has created a space "notificaton checking" with the default quota using the GraphApi | ||
And user "Alice" has shared a space "notificaton checking" with settings: | ||
| shareWith | Brian | | ||
| role | editor | | ||
When user "Brian" lists all notifications | ||
Then the HTTP status code should be "200" | ||
And the JSON response should contain a notification message with the subject "Space shared" and the message-details should match | ||
""" | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"app", | ||
"datetime", | ||
"message", | ||
"messageRich", | ||
"messageRichParameters", | ||
"notification_id", | ||
"object_id", | ||
"object_type", | ||
"subject", | ||
"subjectRich", | ||
"user" | ||
], | ||
"properties": { | ||
"app": { | ||
"type": "string", | ||
"enum": ["userlog"] | ||
}, | ||
"message": { | ||
"type": "string", | ||
"enum": ["Alice Hansen added you to Space notificaton checking"] | ||
}, | ||
"messageRich": { | ||
"type": "string", | ||
"enum": ["{user} added you to Space {space}"] | ||
}, | ||
"messageRichParameters": { | ||
"type": "object", | ||
"required": [ | ||
"space", | ||
"user" | ||
], | ||
"properties": { | ||
"space": { | ||
"type": "object", | ||
"required": [ | ||
"id", | ||
"name" | ||
], | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"enum": ["notificaton checking"] | ||
} | ||
} | ||
}, | ||
"user": { | ||
"type": "object", | ||
"required": [ | ||
"displayname", | ||
"id", | ||
"name" | ||
], | ||
"properties": { | ||
"displayname": { | ||
"type": "string", | ||
"enum": ["Alice Hansen"] | ||
}, | ||
"id": { | ||
"type": "string", | ||
"enim": ["%user_id%"] | ||
}, | ||
"name": { | ||
"type": "string", | ||
"enum": ["Alice"] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"notification_id": { | ||
"type": "string" | ||
}, | ||
"object_id": { | ||
"type": "string" | ||
}, | ||
"object_type": { | ||
"type": "string", | ||
"enum": ["storagespace"] | ||
}, | ||
"subject": { | ||
"type": "string", | ||
"enum": ["Space shared"] | ||
}, | ||
"subjectRich": { | ||
"type": "string", | ||
"enum": ["Space shared"] | ||
}, | ||
"user": { | ||
"type": "string", | ||
"enum": ["Alice"] | ||
} | ||
} | ||
} | ||
""" | ||
|
148 changes: 148 additions & 0 deletions
148
tests/acceptance/features/bootstrap/NotificationContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ownCloud | ||
* | ||
* @author Viktor Scharf <[email protected]> | ||
* @copyright Copyright (c) 2023 Viktor Scharf [email protected] | ||
*/ | ||
|
||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use TestHelpers\OcsApiHelper; | ||
use Behat\Gherkin\Node\PyStringNode; | ||
use Helmich\JsonAssert\JsonAssertions; | ||
|
||
require_once 'bootstrap.php'; | ||
|
||
/** | ||
* Defines application features from the specific context. | ||
*/ | ||
class NotificationContext implements Context { | ||
/** | ||
* @var FeatureContext | ||
*/ | ||
private $featureContext; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json'; | ||
|
||
/** | ||
* @var array[] | ||
*/ | ||
private $notificationIds; | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function getNotificationIds():array { | ||
return $this->notificationIds; | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function getLastNotificationId():array { | ||
return \end($this->notificationIds); | ||
} | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $userRecipient; | ||
|
||
/** | ||
* @param string $userRecipient | ||
* | ||
* @return void | ||
*/ | ||
public function setUserRecipient(string $userRecipient): void { | ||
$this->userRecipient = $userRecipient; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUserRecipient(): string { | ||
return $this->userRecipient; | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
* | ||
* @param BeforeScenarioScope $scope | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function setUpScenario(BeforeScenarioScope $scope):void { | ||
// Get the environment | ||
$environment = $scope->getEnvironment(); | ||
// Get all the contexts you need in this context | ||
$this->featureContext = $environment->getContext('FeatureContext'); | ||
} | ||
|
||
/** | ||
* @Then /^user "([^"]*)" lists all notifications$/ | ||
* | ||
* @param string $user | ||
* | ||
* @return void | ||
*/ | ||
public function userListAllNotifications(string $user):void { | ||
$this->setUserRecipient($user); | ||
$response = OcsApiHelper::sendRequest( | ||
$this->featureContext->getBaseUrl(), | ||
$this->featureContext->getActualUsername($user), | ||
$this->featureContext->getPasswordForUser($user), | ||
'GET', | ||
$this->notificationEndpointPath, | ||
$this->featureContext->getStepLineRef() | ||
); | ||
$this->featureContext->setResponse($response); | ||
} | ||
|
||
/** | ||
* @Then /^the JSON response should contain a notification message with the subject "([^"]*)" and the message-details should match$/ | ||
* | ||
* @param string $subject | ||
* @param PyStringNode $schemaString | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function theJsonDataFromLastResponseShouldMatch( | ||
string $subject, | ||
PyStringNode $schemaString | ||
): void { | ||
if (isset($this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data)) { | ||
$responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->ocs->data; | ||
foreach ($responseBody as $value) { | ||
if (isset($value->subject) && $value->subject === $subject) { | ||
$responseBody = $value; | ||
// set notificationId | ||
$this->notificationIds[] = $value->notification_id; | ||
break; | ||
} | ||
} | ||
} else { | ||
$responseBody = $this->featureContext->getJsonDecodedResponseBodyContent(); | ||
} | ||
|
||
// substitute the value here | ||
$schemaString = $schemaString->getRaw(); | ||
$schemaString = $this->featureContext->substituteInLineCodes( | ||
$schemaString, | ||
$this->featureContext->getCurrentUser(), | ||
[], | ||
[], | ||
null, | ||
$this->getUserRecipient(), | ||
); | ||
JsonAssertions::assertJsonDocumentMatchesSchema( | ||
$responseBody, | ||
$this->featureContext->getJSONSchema($schemaString) | ||
); | ||
} | ||
} |