Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-05-13 17:37:17 +0300
committerVitor Mattos <vitor@php.rio>2022-06-30 21:01:24 +0300
commit03fb81d305cf2eb9e5fc8bc68dd2820bad855936 (patch)
tree2e0350a89509f61b0252b59fe1a21e184ec3acbd /tests
parent87fd76e367aa63b907450a64a015b6caa95844a7 (diff)
Add job to apply ttl
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php31
-rw-r--r--tests/integration/features/ttl/ttl.feature11
-rw-r--r--tests/integration/spreedcheats/appinfo/routes.php1
-rw-r--r--tests/integration/spreedcheats/lib/Controller/ApiController.php38
-rw-r--r--tests/php/Service/RoomServiceTest.php3
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php1
6 files changed, 76 insertions, 9 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 3b5fe0051..a5dfc8ce0 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -2581,18 +2581,35 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/**
* @Given user :user check if ttl of room :identifier is :ttl (:apiVersion)
*/
- public function theTtlOfRoomIsV(string $user, string $identifier, int $ttl, string $apiVersion = 'v4') {
+ public function userCheckIfTtlOfRoomIsX(string $user, string $identifier, int $ttl, string $apiVersion = 'v4') {
$this->setCurrentUser($user);
- $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room');
- $rooms = $this->getDataFromResponse($this->response);
+ $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier]);
+ $room = $this->getDataFromResponse($this->response);
- $rooms = array_filter($rooms, function ($room) {
- return $room['type'] !== 4;
- });
- Assert::assertEquals($ttl, $rooms[0]['timeToLive']);
+ Assert::assertEquals($ttl, $room['timeToLive']);
}
+ /**
+ * @When wait for :seconds seconds
+ */
+ public function waitForXSeconds($seconds): void {
+ sleep($seconds);
+ }
+ /**
+ * @When apply ttl job to room :identifier
+ */
+ public function applyTtlJobToRoom($identifier): void {
+ $currentUser = $this->currentUser;
+ $this->setCurrentUser('admin');
+ $this->sendRequest('GET', '/apps/spreedcheats/get_ttl_job/' . self::$identifierToToken[$identifier]);
+ $response = $this->response->getBody()->getContents();
+ $response = json_decode($response, true);
+ Assert::assertIsArray($response, 'Room ' . $identifier . 'not found');
+ Assert::assertArrayHasKey('id', $response);
+ $this->runOcc(['background-job:execute', $response['id']]);
+ $this->setCurrentUser($currentUser);
+ }
/*
* Requests
diff --git a/tests/integration/features/ttl/ttl.feature b/tests/integration/features/ttl/ttl.feature
index 5f9ce10ca..85d7972b7 100644
--- a/tests/integration/features/ttl/ttl.feature
+++ b/tests/integration/features/ttl/ttl.feature
@@ -3,14 +3,21 @@ Feature: room/ttp
Given user "participant1" exists
Given user "participant2" exists
Given user "participant3" exists
+
Scenario: Enable TTL and check after expire
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" set the ttl to -1 of room "room" with 400 (v4)
And user "participant2" set the ttl to 3 of room "room" with 403 (v4)
And user "participant3" set the ttl to 3 of room "room" with 404 (v4)
And user "participant1" set the ttl to 3 of room "room" with 200 (v4)
- And user "participant1" sends message "Message 1" to room "room" with 201
- And user "participant1" check if ttl of room "room" is 3 (v4) \ No newline at end of file
+ And user "participant1" sends message "Message 2" to room "room" with 201
+ And user "participant1" check if ttl of room "room" is 3 (v4)
+ And wait for 3 seconds
+ And apply ttl job to room "room"
+ 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 | [] | | \ No newline at end of file
diff --git a/tests/integration/spreedcheats/appinfo/routes.php b/tests/integration/spreedcheats/appinfo/routes.php
index 7798d929f..618bbf9a1 100644
--- a/tests/integration/spreedcheats/appinfo/routes.php
+++ b/tests/integration/spreedcheats/appinfo/routes.php
@@ -26,5 +26,6 @@ declare(strict_types=1);
return [
'ocs' => [
['name' => 'Api#resetSpreed', 'url' => '/', 'verb' => 'DELETE'],
+ ['name' => 'Api#getTtlJob', 'url' => '/get_ttl_job/{token}', 'verb' => 'GET'],
],
];
diff --git a/tests/integration/spreedcheats/lib/Controller/ApiController.php b/tests/integration/spreedcheats/lib/Controller/ApiController.php
index 9975d7c88..30184cca8 100644
--- a/tests/integration/spreedcheats/lib/Controller/ApiController.php
+++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php
@@ -27,6 +27,7 @@ namespace OCA\SpreedCheats\Controller;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\Share\IShare;
@@ -102,4 +103,41 @@ class ApiController extends OCSController {
return new DataResponse();
}
+
+ /**
+ * @NoCSRFRequired
+ *
+ * @return JSONResponse
+ */
+ public function getTtlJob($token): JSONResponse {
+ $class = 'OCA\Talk\BackgroundJob\ApplyTtl';
+ $roomId = $this->getRoomIdByToken($token);
+ if (!$roomId) {
+ return new JSONResponse();
+ }
+ $query = $this->db->getQueryBuilder();
+ $query->select('id')
+ ->from('jobs')
+ ->where(
+ $query->expr()->andX(
+ $query->expr()->eq('class', $query->createNamedParameter($class)),
+ $query->expr()->eq('argument', $query->createNamedParameter(json_encode(['room_id' => (int) $roomId])))
+ )
+ );
+ $result = $query->executeQuery();
+ $job = $result->fetchOne();
+ if ($job) {
+ return new JSONResponse(['id' => (int) $job]);
+ }
+ return new JSONResponse();
+ }
+
+ private function getRoomIdByToken(string $token): ?string {
+ $query = $this->db->getQueryBuilder();
+ $query->select('id')
+ ->from('talk_rooms')
+ ->where($query->expr()->eq('token', $query->createNamedParameter($token)));
+ $result = $query->executeQuery();
+ return $result->fetchOne();
+ }
}
diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php
index 8733cbccc..836071c79 100644
--- a/tests/php/Service/RoomServiceTest.php
+++ b/tests/php/Service/RoomServiceTest.php
@@ -67,6 +67,7 @@ class RoomServiceTest extends TestCase {
$this->manager = $this->createMock(Manager::class);
$this->participantService = $this->createMock(ParticipantService::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->shareManager = $this->createMock(IShareManager::class);
$this->hasher = $this->createMock(IHasher::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
@@ -74,6 +75,7 @@ class RoomServiceTest extends TestCase {
$this->manager,
$this->participantService,
\OC::$server->get(IDBConnection::class),
+ $this->timeFactory,
$this->shareManager,
$this->hasher,
$this->dispatcher
@@ -337,6 +339,7 @@ class RoomServiceTest extends TestCase {
$this->manager,
$this->participantService,
\OC::$server->get(IDBConnection::class),
+ $this->timeFactory,
$this->shareManager,
$this->hasher,
$dispatcher
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index 051188a53..a3f02d608 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -155,6 +155,7 @@ class BackendNotifierTest extends TestCase {
$this->manager,
$this->participantService,
$dbConnection,
+ $this->timeFactory,
$this->createMock(IManager::class),
$this->createMock(IHasher::class),
$this->dispatcher