Skip to content

Commit

Permalink
feat(tests): Add integration test for editing
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jan 10, 2024
1 parent 117a985 commit 5c48091
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,36 @@ public function userSendsMessageToRoom(string $user, string $sendingMode, string
}
}

/**
* @Then /^user "([^"]*)" edits message ("[^"]*"|'[^']*') in room "([^"]*)" to ("[^"]*"|'[^']*') with (\d+)(?: \((v1)\))?$/
*
* @param string $user
* @param string $oldMessage
* @param string $identifier
* @param string $newMessage
* @param string $statusCode
* @param string $apiVersion
*/
public function userEditsMessageToRoom(string $user, string $oldMessage, string $identifier, string $newMessage, string $statusCode, string $apiVersion = 'v1') {
$oldMessage = substr($oldMessage, 1, -1);
$oldMessage = str_replace('\n', "\n", $oldMessage);
$messageId = self::$textToMessageId[$oldMessage];
$newMessage = substr($newMessage, 1, -1);
$newMessage = str_replace('\n', "\n", $newMessage);

$this->setCurrentUser($user, $identifier);
$this->sendRequest(
'PUT',
'/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/' . $messageId,
new TableNode([['message', $newMessage]])
);
$this->assertStatusCode($this->response, $statusCode);
sleep(1); // make sure Postgres manages the order of the messages

self::$textToMessageId[$newMessage] = $messageId;
self::$messageIdToText[$messageId] = $newMessage;
}

/**
* @Then /^user "([^"]*)" sets reminder for message ("[^"]*"|'[^']*') in room "([^"]*)" for time (\d+) with (\d+)(?: \((v1)\))?$/
*
Expand Down Expand Up @@ -2549,7 +2579,7 @@ protected function compareDataResponse(TableNode $formData = null) {

$expected = $formData->getHash();
$count = count($expected);
Assert::assertCount($count, $messages, 'Message count does not match');
Assert::assertCount($count, $messages, 'Message count does not match' . "\n" . print_r($messages, true));
for ($i = 0; $i < $count; $i++) {
if ($expected[$i]['messageParameters'] === '"IGNORE"') {
$messages[$i]['messageParameters'] = 'IGNORE';
Expand Down
52 changes: 52 additions & 0 deletions tests/integration/features/chat-1/edit-message.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Feature: chat-1/edit-message
Background:
Given user "participant1" exists
Given user "participant2" exists

Scenario: Moderator edits their own message
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
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 | [] | |
And user "participant1" edits message "Message 1" in room "room" to "Message 1 - Edit 1" with 200
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 - Edit 1 | [] | |
Then user "participant2" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 - Edit 1 | [] | |
And user "participant2" edits message "Message 1 - Edit 1" in room "room" to "Message 1 - Edit 2" with 403
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 - Edit 1 | [] | |
Then user "participant2" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant1 | participant1-displayname | Message 1 - Edit 1 | [] | |

Scenario: User and moderator edit user message
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 "participant2" sends message "Message 1" to room "room" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant2 | participant2-displayname | Message 1 | [] | |
And user "participant1" edits message "Message 1" in room "room" to "Message 1 - Edit 1" with 200
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant2 | participant2-displayname | Message 1 - Edit 1 | [] | |
Then user "participant2" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant2 | participant2-displayname | Message 1 - Edit 1 | [] | |
And user "participant2" edits message "Message 1 - Edit 1" in room "room" to "Message 1 - Edit 2" with 200
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant2 | participant2-displayname | Message 1 - Edit 2 | [] | |
Then user "participant2" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| room | users | participant2 | participant2-displayname | Message 1 - Edit 2 | [] | |

0 comments on commit 5c48091

Please sign in to comment.