Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-09 13:46:06 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-18 18:02:26 +0300
commita2ef5a88e62f6b2b26092d755832df629e761911 (patch)
tree5ed6dbd02c4c36dd9401ea976551a6b9f9cfe54a /tests
parent76b0740bec3866538840e8b05cf240ea18f0f73b (diff)
Add integration tests for deleting a notification
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php71
-rw-r--r--tests/integration/features/delete-notifications.feature23
2 files changed, 93 insertions, 1 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 66576ce..948aba2 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -13,11 +13,19 @@ use GuzzleHttp\Message\ResponseInterface;
*/
class FeatureContext implements Context, SnippetAcceptingContext {
+ /** @var array[] */
+ protected $notificationIds;
+
+ /** @var int */
+ protected $deletedNotification;
+
use BasicStructure;
use Provisioning;
/**
* @Given /^list of notifiers (is|is not) empty$/
+ *
+ * @param string $noNotifiers
*/
public function hasNotifiers($noNotifiers) {
if ($noNotifiers === 'is') {
@@ -33,6 +41,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/**
* @Given /^user "([^"]*)" has notifications$/
+ *
+ * @param string $user
*/
public function hasNotifications($user) {
if ($user === 'test1') {
@@ -44,10 +54,69 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/**
* @Then /^list of notifications has (\d+) entries$/
+ *
+ * @param int $numNotifications
*/
public function checkNumNotifications($numNotifications) {
$notifications = $this->getArrayOfNotificationsResponded($this->response);
PHPUnit_Framework_Assert::assertCount((int) $numNotifications, $notifications);
+
+ $notificationIds = [];
+ foreach ($notifications as $notification) {
+ $notificationIds[] = (int) $notification['notification_id'];
+ }
+
+ $this->notificationIds[] = $notificationIds;
+ }
+
+ /**
+ * @Then /^user "([^"]*)" has (\d+) notifications(| missing the last one| missing the first one)$/
+ *
+ * @param string $user
+ * @param int $numNotifications
+ * @param string $missingLast
+ */
+ public function userNumNotifications($user, $numNotifications, $missingLast) {
+ if ($user === 'test1') {
+ $this->sendingTo('GET', '/apps/notifications/api/v1/notifications?format=json');
+ PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
+
+ $previousNotificationIds = [];
+ if ($missingLast) {
+ PHPUnit_Framework_Assert::assertNotEmpty($this->notificationIds);
+ $previousNotificationIds = end($this->notificationIds);
+ }
+
+ $this->checkNumNotifications((int) $numNotifications);
+
+ if ($missingLast) {
+ $now = end($this->notificationIds);
+ if ($missingLast === ' missing the last one') {
+ array_unshift($now, $this->deletedNotification);
+ } else {
+ $now[] = $this->deletedNotification;
+ }
+
+ PHPUnit_Framework_Assert::assertEquals($previousNotificationIds, $now);
+ }
+
+ }
+ }
+
+ /**
+ * @Then /^delete (first|last) notification$/
+ *
+ * @param string $firstOrLast
+ */
+ public function deleteNotification($firstOrLast) {
+ PHPUnit_Framework_Assert::assertNotEmpty($this->notificationIds);
+ $lastNotificationIds = end($this->notificationIds);
+ if ($firstOrLast === 'first') {
+ $this->deletedNotification = end($lastNotificationIds);
+ } else {
+ $this->deletedNotification = reset($lastNotificationIds);
+ }
+ $this->sendingTo('DELETE', '/apps/notifications/api/v1/notifications/' . $this->deletedNotification);
}
/**
@@ -55,7 +124,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @param ResponseInterface $resp
* @return array
*/
- public function getArrayOfNotificationsResponded($resp) {
+ public function getArrayOfNotificationsResponded(ResponseInterface $resp) {
$jsonResponse = json_decode($resp->getBody()->getContents(), 1);
return $jsonResponse['ocs']['data'];
}
diff --git a/tests/integration/features/delete-notifications.feature b/tests/integration/features/delete-notifications.feature
new file mode 100644
index 0000000..679e748
--- /dev/null
+++ b/tests/integration/features/delete-notifications.feature
@@ -0,0 +1,23 @@
+Feature: delete-notifications
+ Background:
+ Given using api version "2"
+ Given user "test1" exists
+ Given As an "test1"
+
+ Scenario: Delete first notification
+ Given list of notifiers is not empty
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ Then user "test1" has 3 notifications
+ And delete first notification
+ And user "test1" has 2 notifications missing the first one
+
+ Scenario: Delete last notification
+ Given list of notifiers is not empty
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ Then user "test1" has 3 notifications
+ And delete last notification
+ And user "test1" has 2 notifications missing the last one