chore(files_reminder): add integration tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>pull/56520/head
parent
fee82adad4
commit
32e1d6cf9c
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
use Behat\Behat\Context\Context;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
|
||||
/**
|
||||
* Files reminders context.
|
||||
*/
|
||||
class FilesRemindersContext implements Context {
|
||||
use BasicStructure;
|
||||
use WebDav;
|
||||
|
||||
/**
|
||||
* @When the user sets a reminder for :path with due date :dueDate
|
||||
*/
|
||||
public function settingAReminderForFileWithDueDate($path, $dueDate) {
|
||||
$fileId = $this->getFileIdForPath($this->currentUser, $path);
|
||||
$this->sendRequestForJSON(
|
||||
'PUT',
|
||||
'/apps/files_reminders/api/v1/' . $fileId,
|
||||
['dueDate' => $dueDate],
|
||||
['OCS-APIREQUEST' => 'true']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the user sees the reminder for :path is set to :dueDate
|
||||
*/
|
||||
public function retrievingTheReminderForFile($path, $dueDate) {
|
||||
$fileId = $this->getFileIdForPath($this->currentUser, $path);
|
||||
$this->sendRequestForJSON(
|
||||
'GET',
|
||||
'/apps/files_reminders/api/v1/' . $fileId,
|
||||
null,
|
||||
['OCS-APIREQUEST' => 'true']
|
||||
);
|
||||
$response = $this->getDueDateFromOCSResponse();
|
||||
Assert::assertEquals($dueDate, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the user sees the reminder for :path is not set
|
||||
*/
|
||||
public function retrievingTheReminderForFileIsNotSet($path) {
|
||||
$fileId = $this->getFileIdForPath($this->currentUser, $path);
|
||||
$this->sendRequestForJSON(
|
||||
'GET',
|
||||
'/apps/files_reminders/api/v1/' . $fileId,
|
||||
null,
|
||||
['OCS-APIREQUEST' => 'true']
|
||||
);
|
||||
$response = $this->getDueDateFromOCSResponse();
|
||||
Assert::assertNull($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the user removes the reminder for :path
|
||||
*/
|
||||
public function removingTheReminderForFile($path) {
|
||||
$fileId = $this->getFileIdForPath($this->currentUser, $path);
|
||||
$this->sendRequestForJSON(
|
||||
'DELETE',
|
||||
'/apps/files_reminders/api/v1/' . $fileId,
|
||||
null,
|
||||
['OCS-APIREQUEST' => 'true']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the due date from OCS response
|
||||
*/
|
||||
private function getDueDateFromOCSResponse(): ?string {
|
||||
if ($this->response === null) {
|
||||
throw new \RuntimeException('No response available');
|
||||
}
|
||||
|
||||
$body = (string)$this->response->getBody();
|
||||
if (str_starts_with($body, '<')) {
|
||||
$body = simplexml_load_string($body);
|
||||
if ($body === false) {
|
||||
throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
|
||||
}
|
||||
return $body->data->dueDate;
|
||||
}
|
||||
|
||||
$body = json_decode($body, true);
|
||||
return $body['ocs']['data']['dueDate'] ?? null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
Feature: Files reminders
|
||||
|
||||
Background:
|
||||
Given using api version "2"
|
||||
|
||||
Scenario: Set a reminder with a past due date
|
||||
Given user "user0" exists
|
||||
Given As an "user0"
|
||||
Given User "user0" uploads file "data/textfile.txt" to "/file.txt"
|
||||
When the user sets a reminder for "/file.txt" with due date "2000-01-01T00:00:00Z"
|
||||
Then the OCS status code should be "400"
|
||||
Then the user sees the reminder for "/file.txt" is not set
|
||||
|
||||
Scenario: Set a reminder with a valid due date
|
||||
Given user "user1" exists
|
||||
Given As an "user1"
|
||||
Given User "user1" uploads file "data/textfile.txt" to "/file.txt"
|
||||
When the user sets a reminder for "/file.txt" with due date "2100-01-01T00:00:00Z"
|
||||
Then the OCS status code should be "201"
|
||||
Then the user sees the reminder for "/file.txt" is set to "2100-01-01T00:00:00+00:00"
|
||||
|
||||
Scenario: Remove a reminder
|
||||
Given user "user2" exists
|
||||
Given As an "user2"
|
||||
Given User "user2" uploads file "data/textfile.txt" to "/file.txt"
|
||||
When the user sets a reminder for "/file.txt" with due date "2100-01-01T00:00:00Z"
|
||||
Then the OCS status code should be "201"
|
||||
Then the user sees the reminder for "/file.txt" is set to "2100-01-01T00:00:00+00:00"
|
||||
When the user removes the reminder for "/file.txt"
|
||||
Then the OCS status code should be "200"
|
||||
Then the user sees the reminder for "/file.txt" is not set
|
||||
Loading…
Reference in New Issue