diff options
author | Joas Schilling <coding@schilljs.com> | 2022-04-05 10:02:32 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-04-06 15:16:26 +0300 |
commit | 017552abb7f71685f9505ea22c4d9de912fb7492 (patch) | |
tree | 9a41bf1580700f40c3f514ac777a11083e16fb9f /tests | |
parent | 8fcf1e7cce6432946c8d11b892c02d8a25a4df95 (diff) |
Add check for notifications
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 2d78ad37d..346d3147a 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -1892,6 +1892,49 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->setCurrentUser($currentUser); } + /** + * @Then user :user has the following notifications + * + * @param string $user + * @param TableNode|null $body + */ + public function userNotifications(string $user, TableNode $body = null): void { + $this->setCurrentUser($user); + $this->sendRequest( + 'GET', '/apps/notifications/api/v2/notifications' + ); + + $data = $this->getDataFromResponse($this->response); + + if ($body === null) { + Assert::assertCount(0, $data); + return; + } + + $this->assertNotifications($data, $body); + } + + private function assertNotifications($notifications, TableNode $formData) { + Assert::assertCount(count($formData->getHash()), $notifications, 'Notifications count does not match'); + Assert::assertEquals($formData->getHash(), array_map(function ($notification, $expectedNotification) { + $data = []; + if (isset($expectedNotification['object_id'])) { + [$roomToken,] = explode('/', $notification['object_id']); + $data['object_id'] = self::$tokenToIdentifier[$roomToken]; + } + if (isset($expectedNotification['subject'])) { + $data['subject'] = (string) $notification['subject']; + } + if (isset($expectedNotification['object_type'])) { + $data['object_type'] = (string) $notification['object_type']; + } + if (isset($expectedNotification['app'])) { + $data['app'] = (string) $notification['app']; + } + + return $data; + }, $notifications, $formData->getHash())); + } /** * @Given /^guest accounts can be created$/ |