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 Dec 13, 2023
1 parent c4687fa commit db8d8a5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,35 @@ 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
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 |
| group room | users | participant1 | participant1-displayname | Message 1 | [] | |
And user "participant1" edits message "Message 1" in room "room" to "Message 1 - Edit 1" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| group 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 |
| group 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 |
| group 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 |
| group 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 |
| group room | users | participant2 | participant2-displayname | Message 1 | [] | |
And user "participant1" edits message "Message 1" in room "room" to "Message 1 - Edit 1" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| group 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 |
| group 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 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
| group 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 |
| group room | users | participant2 | participant2-displayname | Message 1 - Edit 2 | [] | |

0 comments on commit db8d8a5

Please sign in to comment.