Browse Source

Add integration test for search

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/8057/head
Joas Schilling 3 years ago
parent
commit
87f8ec1a8e
No known key found for this signature in database GPG Key ID: C400AAF20C1BB6FC
  1. 51
      tests/integration/features/bootstrap/FeatureContext.php
  2. 31
      tests/integration/features/chat/search.feature

51
tests/integration/features/bootstrap/FeatureContext.php

@ -1930,6 +1930,27 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->compareDataResponse($formData);
}
/**
* @Then /^user "([^"]*)" searches for "([^"]*)" in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
* @param string $user
* @param string $search
* @param string $identifier
* @param string $statusCode
* @param string $apiVersion
*/
public function userSearchesInRoom(string $user, string $search, string $identifier, $statusCode, string $apiVersion = 'v1', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/search/providers/talk-message-current/search?term=' . $search . '&from=' . '/call/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);
if ($statusCode !== '200') {
return;
}
$this->compareSearchResponse($formData);
}
/**
* @Then /^user "([^"]*)" sees the following shared (media|audio|voice|file|deckcard|location|other) in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
@ -2067,6 +2088,36 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}, $messages));
}
/**
* @param TableNode|null $formData
*/
protected function compareSearchResponse(TableNode $formData = null) {
$messages = $this->getDataFromResponse($this->response)['entries'];
if ($formData === null) {
Assert::assertEmpty($messages);
return;
}
$expected = array_map(static function (array $message) {
$message['attributes.conversation'] = self::$identifierToToken[$message['attributes.conversation']];
$message['attributes.messageId'] = self::$textToMessageId[$message['attributes.messageId']];
return $message;
}, $formData->getHash());
$count = count($expected);
Assert::assertCount($count, $messages, 'Message count does not match');
Assert::assertEquals($expected, array_map(static function ($message) {
return [
'title' => $message['title'],
'subline' => $message['subline'],
'attributes.conversation' => $message['attributes']['conversation'],
'attributes.messageId' => $message['attributes']['messageId'],
];
}, $messages));
}
/**
* @Then /^user "([^"]*)" sees the following system messages in room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*

31
tests/integration/features/chat/search.feature

@ -0,0 +1,31 @@
Feature: chat/search
Background:
Given user "participant1" exists
Given user "participant2" exists
Scenario: Can not search when not a participant
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" sends message "Message 1" to room "room" with 201
When user "participant2" searches for "essa" in room "room" with 200
Scenario: Search for message when being a participant
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| 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
When user "participant2" searches for "essa" in room "room" with 200
| title | subline | attributes.conversation | attributes.messageId |
| participant1-displayname | Message 1 | room | Message 1 |
Scenario: Can not search when being blocked by the lobby
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| 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" sets lobby state for room "room" to "non moderators" with 200 (v4)
When user "participant2" searches for "essa" in room "room" with 200
Loading…
Cancel
Save