From e892c94987c044e4e2cd2d5cb6a312a87b121f11 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jul 2025 10:08:30 +0200 Subject: [PATCH] test(threads): Test saving the notification level Signed-off-by: Joas Schilling --- .../features/bootstrap/FeatureContext.php | 23 +++++++- .../features/chat-4/threads.feature | 58 +++++++++++++------ 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index d924a0ea2..7805fdeb9 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2783,6 +2783,22 @@ class FeatureContext implements Context, SnippetAcceptingContext { sleep(1); } + #[Then('/^user "([^"]*)" subscribes to thread "([^"]*)" in room "([^"]*)" with notification level (\d+) with (\d+)(?: \((v1)\))?$/')] + public function userSubscribesThreadInRoom(string $user, string $message, string $identifier, int $level, int $statusCode, string $apiVersion = 'v1', ?TableNode $formData = null): void { + $this->setCurrentUser($user); + $this->sendRequest( + 'POST', + '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/threads/' . self::$textToMessageId[$message] . '/notify', + ['level' => $level], + ); + $this->assertStatusCode($this->response, $statusCode); + + if ($formData !== null) { + $result = $this->getDataFromResponse($this->response); + $this->compareThreadsResponse($formData, [$result]); + } + } + protected function compareThreadsResponse(?TableNode $formData, array $results): void { if ($formData === null) { Assert::assertEmpty($results); @@ -2794,9 +2810,11 @@ class FeatureContext implements Context, SnippetAcceptingContext { Assert::assertCount($count, $results, 'Result count does not match'); $expected = array_map(static function (array $result) { - foreach (['t.id', 't.lastMessage', 'firstMessage', 'lastMessage'] as $field) { + foreach (['t.id', 't.lastMessage', 'a.notificationLevel', 'firstMessage', 'lastMessage'] as $field) { if (isset($result[$field])) { - if ($result[$field] === '0') { + if ($field === 'a.notificationLevel') { + $result[$field] = (int)$result[$field]; + } elseif ($result[$field] === '0') { $result[$field] = 0; } elseif ($result[$field] === 'NULL') { $result[$field] = null; @@ -2817,6 +2835,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { 't.id' => $actual['thread']['id'], 't.numReplies' => $actual['thread']['numReplies'], 't.lastMessage' => $actual['thread']['lastMessageId'], + 'a.notificationLevel' => $actual['attendee']['notificationLevel'], 'firstMessage' => $actual['first']['id'] ?? null, 'lastMessage' => $actual['last']['id'] ?? null, ]; diff --git a/tests/integration/features/chat-4/threads.feature b/tests/integration/features/chat-4/threads.feature index 83c8d92e1..fc984d558 100644 --- a/tests/integration/features/chat-4/threads.feature +++ b/tests/integration/features/chat-4/threads.feature @@ -20,8 +20,8 @@ Feature: chat-4/threads And user "participant1" adds user "participant2" to room "room" with 200 (v4) And user "participant1" sends message "Message 1" to room "room" with 201 And user "participant1" creates thread "Message 1" in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 0 | 0 | Message 1 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | Scenario: Create thread on root with reply Given user "participant1" creates room "room" (v4) @@ -31,8 +31,8 @@ Feature: chat-4/threads And user "participant1" sends message "Message 1" to room "room" with 201 And user "participant2" sends reply "Message 1-1" on message "Message 1" to room "room" with 201 And user "participant1" creates thread "Message 1" in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 1 | Message 1-1 | Message 1 | Message 1-1 | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 1 | Message 1-1 | 0 | Message 1 | Message 1-1 | Scenario: Create thread on reply Given user "participant1" creates room "room" (v4) @@ -42,8 +42,8 @@ Feature: chat-4/threads And user "participant1" sends message "Message 1" to room "room" with 201 And user "participant2" sends reply "Message 1-1" on message "Message 1" to room "room" with 201 And user "participant1" creates thread "Message 1-1" in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 1 | Message 1-1 | Message 1 | Message 1-1 | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 1 | Message 1-1 | 0 | Message 1 | Message 1-1 | Scenario: Creating a thread again does not conflict nor duplicate Given user "participant1" creates room "room" (v4) @@ -54,11 +54,11 @@ Feature: chat-4/threads When user "participant1" creates thread "Message 1" in room "room" with 200 When user "participant2" creates thread "Message 1" in room "room" with 200 Then user "participant1" sees the following recent threads in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 0 | 0 | Message 1 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | Then user "participant2" sees the following recent threads in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 0 | 0 | Message 1 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | Scenario: Recent threads are sorted by last activity Given user "participant1" creates room "room" (v4) @@ -69,15 +69,37 @@ Feature: chat-4/threads And user "participant2" sends message "Message 2" to room "room" with 201 When user "participant2" creates thread "Message 2" in room "room" with 200 Then user "participant1" sees the following recent threads in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 2 | 0 | 0 | Message 2 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 2 | 0 | 0 | 0 | Message 2 | NULL | When user "participant1" creates thread "Message 1" in room "room" with 200 Then user "participant1" sees the following recent threads in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 1 | 0 | 0 | Message 1 | NULL | - | Message 2 | 0 | 0 | Message 2 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | + | Message 2 | 0 | 0 | 0 | Message 2 | NULL | When user "participant1" sends reply "Message 2-1" on message "Message 2" to room "room" with 201 Then user "participant2" sees the following recent threads in room "room" with 200 - | t.id | t.numReplies | t.lastMessage | firstMessage | lastMessage | - | Message 2 | 1 | Message 2-1 | Message 2 | Message 2-1 | - | Message 1 | 0 | 0 | Message 1 | NULL | + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 2 | 1 | Message 2-1 | 0 | Message 2 | Message 2-1 | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | + + Scenario: Create thread on reply + Given user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" adds user "participant2" to room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + And user "participant1" creates thread "Message 1" in room "room" with 200 + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL | + And user "participant1" subscribes to thread "Message 1" in room "room" with notification level 1 with 200 + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 1 | Message 1 | NULL | + And user "participant1" subscribes to thread "Message 1" in room "room" with notification level 2 with 200 + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 2 | Message 1 | NULL | + And user "participant1" subscribes to thread "Message 1" in room "room" with notification level 3 with 200 + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 3 | Message 1 | NULL | + And user "participant1" subscribes to thread "Message 1" in room "room" with notification level 0 with 200 + | t.id | t.numReplies | t.lastMessage | a.notificationLevel | firstMessage | lastMessage | + | Message 1 | 0 | 0 | 0 | Message 1 | NULL |