From ad2c1b9d2c11e04e42fa597af32551ee8c457bb1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Aug 2023 21:59:49 +0200 Subject: [PATCH] tests(reminder): Add integration tests for reminder functionality Signed-off-by: Joas Schilling --- .../features/bootstrap/FeatureContext.php | 51 ++++++- .../features/callapi/recording.feature | 4 +- .../features/chat-2/reminder.feature | 127 ++++++++++++++++++ 3 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 tests/integration/features/chat-2/reminder.feature diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 9288761cca4..8e8dbfc6ffe 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -1685,6 +1685,49 @@ public function userSendsMessageToRoom(string $user, string $sendingMode, string } } + /** + * @Then /^user "([^"]*)" sets reminder for message ("[^"]*"|'[^']*') in room "([^"]*)" for time (\d+) with (\d+)(?: \((v1)\))?$/ + * + * @param string $user + * @param string $setOrDelete + * @param string $message + * @param string $identifier + * @param string $statusCode + * @param string $apiVersion + */ + public function userSetsReminder(string $user, string $message, string $identifier, int $timestamp, int $statusCode, string $apiVersion = 'v1'): void { + $message = substr($message, 1, -1); + + $this->setCurrentUser($user); + $this->sendRequest( + 'POST', + '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/' . self::$textToMessageId[$message] . '/reminder', + new TableNode([['timestamp', $timestamp]]) + ); + $this->assertStatusCode($this->response, $statusCode); + } + + /** + * @Then /^user "([^"]*)" deletes reminder for message ("[^"]*"|'[^']*') in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ + * + * @param string $user + * @param string $setOrDelete + * @param string $message + * @param string $identifier + * @param string $statusCode + * @param string $apiVersion + */ + public function userDeletesReminder(string $user, string $message, string $identifier, string $statusCode, string $apiVersion = 'v1'): void { + $message = substr($message, 1, -1); + + $this->setCurrentUser($user); + $this->sendRequest( + 'DELETE', + '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/' . self::$textToMessageId[$message] . '/reminder' + ); + $this->assertStatusCode($this->response, $statusCode); + } + /** * @Then /^user "([^"]*)" shares rich-object "([^"]*)" "([^"]*)" '([^']*)' to room "([^"]*)" with (\d+)(?: \((v1)\))?$/ * @@ -3440,13 +3483,13 @@ public function userShareLastNotificationFile(string $user, string $firstLast, s } /** - * @When /^run transcript background jobs$/ + * @When /^run "([^"]*)" background jobs$/ */ - public function runTranscriptBackgroundJobs(): void { - $this->runOcc(['background-job:list', '--output=json_pretty', '--class=OC\SpeechToText\TranscriptionJob']); + public function runReminderBackgroundJobs(string $class): void { + $this->runOcc(['background-job:list', '--output=json_pretty', '--class=' . $class]); $list = json_decode($this->lastStdOut, true, 512, JSON_THROW_ON_ERROR); - Assert::assertNotEmpty($list, 'List of OC\SpeechToText\TranscriptionJob should not be empty'); + Assert::assertNotEmpty($list, 'List of ' . $class . ' should not be empty'); foreach ($list as $job) { $this->runOcc(['background-job:execute', (string) $job['id']]); diff --git a/tests/integration/features/callapi/recording.feature b/tests/integration/features/callapi/recording.feature index d9b0b1ec217..c5db0434f50 100644 --- a/tests/integration/features/callapi/recording.feature +++ b/tests/integration/features/callapi/recording.feature @@ -444,7 +444,7 @@ Feature: callapi/recording And user "participant1" is participant of the following unordered rooms (v4) | type | name | callRecording | | 2 | room1 | 0 | - When run transcript background jobs + When run "OC\SpeechToText\TranscriptionJob" background jobs Then user "participant1" has the following notifications | app | object_type | object_id | subject | message | | spreed | recording | room1 | Transcript now available | The transcript for the call in room1 was uploaded to /Talk/Recording/ROOM(room1)/join_call.txt. | @@ -470,7 +470,7 @@ Feature: callapi/recording And user "participant1" is participant of the following unordered rooms (v4) | type | name | callRecording | | 2 | room1 | 0 | - When run transcript background jobs + When run "OC\SpeechToText\TranscriptionJob" background jobs Then user "participant1" has the following notifications | app | object_type | object_id | subject | message | | spreed | recording | room1 | Failed to transcript call recording | The server failed to transcript the recording at /Talk/Recording/ROOM(room1)/leave_call.ogg for the call in room1. Please reach out to the administration. | diff --git a/tests/integration/features/chat-2/reminder.feature b/tests/integration/features/chat-2/reminder.feature new file mode 100644 index 00000000000..86af1ff79c4 --- /dev/null +++ b/tests/integration/features/chat-2/reminder.feature @@ -0,0 +1,127 @@ +Feature: chat-2/reminder + + Background: + Given user "participant1" exists + Given user "participant2" exists + + Scenario: Reminder in one-to-one chat (and sender is deleted) + Given user "participant1" creates room "room" (v4) + | roomType | 1 | + | invite | participant2 | + And user "participant2" joins room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant1" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant2" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And run "OCA\Talk\BackgroundJob\ChatMessageReminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: You in private conversation participant2-displayname | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: participant1-displayname in private conversation | + When user "participant1" is deleted + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: A deleted user in private conversation participant1-displayname | + And user "participant2" deletes reminder for message "Message 1" in room "room" with 200 (v1) + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Reminder in one-to-one chat recipient is deleted + Given user "participant1" creates room "room" (v4) + | roomType | 1 | + | invite | participant2 | + And user "participant2" joins room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant1" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant2" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And run "OCA\Talk\BackgroundJob\ChatMessageReminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: You in private conversation participant2-displayname | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: participant1-displayname in private conversation | + When user "participant2" is deleted + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: You in private conversation participant2-displayname | + And user "participant1" deletes reminder for message "Message 1" in room "room" with 200 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Reminder on user message + 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 "participant2" joins room "room" with 200 (v4) + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant1" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant2" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And run "OCA\Talk\BackgroundJob\ChatMessageReminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: You in conversation room | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: participant1-displayname in conversation room | + When user "participant1" is deleted + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: A deleted user in conversation room | + And user "participant2" deletes reminder for message "Message 1" in room "room" with 200 (v1) + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Reminder on anonymous guest message + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "guest" joins room "room" with 200 (v4) + And user "guest" sends message "Message 1" to room "room" with 201 + When user "participant1" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant2" sets reminder for message "Message 1" in room "room" for time 1234567 with 404 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And run "OCA\Talk\BackgroundJob\ChatMessageReminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: A guest in conversation room | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And user "participant1" deletes reminder for message "Message 1" in room "room" with 200 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Reminder on named guest message + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "guest" joins room "room" with 200 (v4) + And guest "guest" sets name to "FooBar" in room "room" with 200 + And user "guest" sends message "Message 1" to room "room" with 201 + When user "participant1" sets reminder for message "Message 1" in room "room" for time 1234567 with 201 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And run "OCA\Talk\BackgroundJob\ChatMessageReminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: FooBar (guest) in conversation room | + And user "participant1" deletes reminder for message "Message 1" in room "room" with 200 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject |