test(threads): Test saving the notification level

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling
2025-07-17 10:08:30 +02:00
parent 166bd8e602
commit e892c94987
2 changed files with 61 additions and 20 deletions

View File

@ -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,
];

View File

@ -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 |