Browse Source

Add integration tests for the read status of messages

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/4231/head
Joas Schilling 5 years ago
parent
commit
e747556e33
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 89
      tests/integration/features/bootstrap/FeatureContext.php
  2. 114
      tests/integration/features/chat/read-status.feature

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

@ -949,6 +949,24 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
}
/**
* @Then /^user "([^"]*)" reads message "([^"]*)" in room "([^"]*)" with (\d+)(?: \((v(1|2|3))\))?$/
*
* @param string $user
* @param string $message
* @param string $identifier
* @param string $statusCode
* @param string $apiVersion
*/
public function userReadsMessageInRoom($user, $message, $identifier, $statusCode, $apiVersion = 'v1') {
$this->setCurrentUser($user);
$this->sendRequest(
'POST', '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/read',
new TableNode([['lastReadMessage', self::$messages[$message]]])
);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" sends message "([^"]*)" with reference id "([^"]*)" to room "([^"]*)" with (\d+)(?: \((v(1|2|3))\))?$/
*
@ -1199,6 +1217,77 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^last response has (no) last common read message header$/
*
* @param string $no
*/
public function hasNoChatLastCommonReadHeader($no) {
Assert::assertArrayNotHasKey('X-Chat-Last-Common-Read', $this->response->getHeaders(), 'X-Chat-Last-Common-Read is set to ' . ($this->response->getHeader('X-Chat-Last-Common-Read')[0] ?? '0'));
}
/**
* @Then /^last response has last common read message header (set to|less than) "([^"]*)"$/
*
* @param string $setOrLower
* @param string $message
*/
public function hasChatLastCommonReadHeader($setOrLower, $message) {
Assert::assertArrayHasKey('X-Chat-Last-Common-Read', $this->response->getHeaders());
if ($setOrLower === 'set to') {
Assert::assertEquals(self::$messages[$message], $this->response->getHeader('X-Chat-Last-Common-Read')[0]);
} else {
// Less than might be required for the first message, because the last read message before is the join/room creation message and we don't know that ID
Assert::assertLessThan(self::$messages[$message], $this->response->getHeader('X-Chat-Last-Common-Read')[0]);
}
}
/**
* @Then /^user "([^"]*)" sets setting "([^"]*)" to "([^"]*)" with (\d+)(?: \((v(1|2|3))\))?$/
*
* @param string $user
* @param string $setting
* @param string $value
* @param string $statusCode
* @param string $apiVersion
*/
public function userSetting($user, $setting, $value, $statusCode, $apiVersion = 'v1') {
$this->setCurrentUser($user);
$this->sendRequest(
'POST', '/apps/spreed/api/' . $apiVersion . '/settings/user',
new TableNode([['key', $setting], ['value', $value]])
);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" has capability "([^"]*)" set to "([^"]*)"$/
*
* @param string $user
* @param string $capability
* @param string $value
*/
public function userCheckCapability($user, $capability, $value) {
$this->setCurrentUser($user);
$this->sendRequest(
'GET', '/cloud/capabilities'
);
$data = $this->getDataFromResponse($this->response);
$capabilities = $data['capabilities'];
$keys = explode('=>', $capability);
$finalKey = array_pop($keys);
$cur = $capabilities;
foreach ($keys as $key) {
Assert::assertArrayHasKey($key, $cur);
$cur = $cur[$key];
}
Assert::assertEquals($value, $cur[$finalKey]);
}
/**
* Parses the xml answer to get the array of users returned.
* @param ResponseInterface $response

114
tests/integration/features/chat/read-status.feature

@ -0,0 +1,114 @@
Feature: public
Background:
Given user "participant1" exists
Given user "participant2" exists
Given user "participant3" exists
Scenario: User toggles the read privacy
Given user "participant1" creates room "chatting" (v3)
| roomType | 3 |
| roomName | room |
# Private
When user "participant1" sets setting "read_status_privacy" to "1" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "1"
When user "participant1" sends message "Message 1" to room "chatting" with 201
Then last response has no last common read message header
# Public
When user "participant1" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant1" reads message "Message 1" in room "chatting" with 200
Then last response has last common read message header set to "Message 1"
# Private again
When user "participant1" sets setting "read_status_privacy" to "1" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "1"
When user "participant1" reads message "Message 1" in room "chatting" with 200
Then last response has no last common read message header
Scenario: Read status is the minimum of all public users
Given user "participant1" creates room "chatting" (v3)
| roomType | 3 |
| roomName | room |
And user "participant1" adds "participant2" to room "chatting" with 200
When user "participant1" sets setting "read_status_privacy" to "1" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "1"
When user "participant2" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant2" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant1" sends message "Message 1" to room "chatting" with 201
Then last response has no last common read message header
When user "participant2" sends message "Message 2" to room "chatting" with 201
Then last response has last common read message header set to "Message 2"
When user "participant1" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant2" sends message "Message 3" to room "chatting" with 201
Then last response has last common read message header set to "Message 1"
When user "participant1" reads message "Message 3" in room "chatting" with 200
Then last response has last common read message header set to "Message 3"
When user "participant2" reads message "Message 3" in room "chatting" with 200
Then last response has last common read message header set to "Message 3"
Scenario: User switching to private is not considered anymore
Given user "participant1" creates room "chatting" (v3)
| roomType | 3 |
| roomName | room |
And user "participant1" adds "participant2" to room "chatting" with 200
When user "participant1" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant2" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant2" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant1" sends message "Message 1" to room "chatting" with 201
Then last response has last common read message header less than "Message 1"
When user "participant2" reads message "Message 1" in room "chatting" with 200
Then last response has last common read message header set to "Message 1"
When user "participant2" sends message "Message 2" to room "chatting" with 201
Then last response has last common read message header set to "Message 1"
When user "participant2" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 1"
When user "participant1" sets setting "read_status_privacy" to "1" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "1"
When user "participant2" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 2"
Scenario: New users added start with the last message of when they are added
Given user "participant1" creates room "chatting" (v3)
| roomType | 3 |
| roomName | room |
And user "participant1" adds "participant2" to room "chatting" with 200
When user "participant1" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant1" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant2" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant2" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant3" sets setting "read_status_privacy" to "0" with 200 (v1)
Then user "participant3" has capability "spreed=>config=>chat=>read-privacy" set to "0"
When user "participant1" sends message "Message 1" to room "chatting" with 201
Then last response has last common read message header less than "Message 1"
When user "participant2" sends message "Message 2" to room "chatting" with 201
Then last response has last common read message header set to "Message 1"
When user "participant1" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 2"
And user "participant1" adds "participant3" to room "chatting" with 200
When user "participant1" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 2"
When user "participant2" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 2"
When user "participant3" reads message "Message 2" in room "chatting" with 200
Then last response has last common read message header set to "Message 2"
Loading…
Cancel
Save