Skip to content

Commit 42ad477

Browse files
committed
chore(files_reminder): add integration tests
Signed-off-by: skjnldsv <[email protected]>
1 parent fee82ad commit 42ad477

File tree

5 files changed

+156
-7
lines changed

5 files changed

+156
-7
lines changed

.github/workflows/integration-sqlite.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
- '--tags ~@large files_features'
6363
- 'filesdrop_features'
6464
- 'file_conversions'
65+
- 'files_reminders'
6566
- 'openldap_features'
6667
- 'openldap_numerical_features'
6768
- 'ldap_features'

build/integration/config/behat.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ default:
131131
- admin
132132
- admin
133133
regular_user_password: 123456
134+
files_reminders:
135+
paths:
136+
- "%paths.base%/../files_reminders"
137+
contexts:
138+
- FilesRemindersContext:
139+
baseUrl: http://localhost:8080
140+
admin:
141+
- admin
142+
- admin
143+
regular_user_password: 123456
134144
capabilities:
135145
paths:
136146
- "%paths.base%/../capabilities_features"

build/integration/features/bootstrap/BasicStructure.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,27 @@ public function sendingTo($verb, $url) {
116116
}
117117

118118
/**
119-
* Parses the xml answer to get ocs response which doesn't match with
119+
* Parses the xml or json answer to get ocs response which doesn't match with
120120
* http one in v1 of the api.
121121
*
122122
* @param ResponseInterface $response
123123
* @return string
124124
*/
125-
public function getOCSResponse($response) {
126-
$body = simplexml_load_string((string)$response->getBody());
127-
if ($body === false) {
128-
throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
125+
public function getOCSResponseCode($response): int {
126+
if ($response === null) {
127+
throw new \RuntimeException('No response available');
129128
}
130-
return $body->meta[0]->statuscode;
129+
130+
$body = (string)$response->getBody();
131+
if (str_starts_with($body, '<')) {
132+
$body = simplexml_load_string($body);
133+
if ($body === false) {
134+
throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
135+
}
136+
return $body->meta[0]->statuscode;
137+
}
138+
139+
return json_decode($body, true)['ocs']['meta']['statuscode'];
131140
}
132141

133142
/**
@@ -257,7 +266,7 @@ public function isExpectedUrl($possibleUrl, $finalPart) {
257266
* @param int $statusCode
258267
*/
259268
public function theOCSStatusCodeShouldBe($statusCode) {
260-
Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
269+
Assert::assertEquals($statusCode, $this->getOCSResponseCode($this->response));
261270
}
262271

263272
/**
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
use Behat\Behat\Context\Context;
8+
use PHPUnit\Framework\Assert;
9+
10+
require __DIR__ . '/../../vendor/autoload.php';
11+
12+
13+
/**
14+
* Files reminders context.
15+
*/
16+
class FilesRemindersContext implements Context {
17+
use BasicStructure;
18+
use WebDav;
19+
20+
/**
21+
* @When the user sets a reminder for :path with due date :dueDate
22+
*/
23+
public function settingAReminderForFileWithDueDate($path, $dueDate) {
24+
$fileId = $this->getFileIdForPath($this->currentUser, $path);
25+
$this->sendRequestForJSON(
26+
'PUT',
27+
'/apps/files_reminders/api/v1/' . $fileId,
28+
['dueDate' => $dueDate],
29+
['OCS-APIREQUEST' => 'true']
30+
);
31+
}
32+
33+
/**
34+
* @Then the user sees the reminder for :path is set to :dueDate
35+
*/
36+
public function retrievingTheReminderForFile($path, $dueDate) {
37+
$fileId = $this->getFileIdForPath($this->currentUser, $path);
38+
$this->sendRequestForJSON(
39+
'GET',
40+
'/apps/files_reminders/api/v1/' . $fileId,
41+
null,
42+
['OCS-APIREQUEST' => 'true']
43+
);
44+
$response = $this->getDueDateFromOCSResponse();
45+
Assert::assertEquals($dueDate, $response);
46+
}
47+
48+
/**
49+
* @Then the user sees the reminder for :path is not set
50+
*/
51+
public function retrievingTheReminderForFileIsNotSet($path) {
52+
$fileId = $this->getFileIdForPath($this->currentUser, $path);
53+
$this->sendRequestForJSON(
54+
'GET',
55+
'/apps/files_reminders/api/v1/' . $fileId,
56+
null,
57+
['OCS-APIREQUEST' => 'true']
58+
);
59+
$response = $this->getDueDateFromOCSResponse();
60+
Assert::assertNull($response);
61+
}
62+
63+
/**
64+
* @When the user removes the reminder for :path
65+
*/
66+
public function removingTheReminderForFile($path) {
67+
$fileId = $this->getFileIdForPath($this->currentUser, $path);
68+
$this->sendRequestForJSON(
69+
'DELETE',
70+
'/apps/files_reminders/api/v1/' . $fileId,
71+
null,
72+
['OCS-APIREQUEST' => 'true']
73+
);
74+
}
75+
76+
/**
77+
* Check the due date from OCS response
78+
*/
79+
private function getDueDateFromOCSResponse(): string|null {
80+
if ($this->response === null) {
81+
throw new \RuntimeException('No response available');
82+
}
83+
84+
$body = (string)$this->response->getBody();
85+
if (str_starts_with($body, '<')) {
86+
$body = simplexml_load_string($body);
87+
if ($body === false) {
88+
throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
89+
}
90+
return $body->data->dueDate;
91+
}
92+
93+
$body = json_decode($body, true);
94+
return $body['ocs']['data']['dueDate'] ?? null;
95+
}
96+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-only
3+
Feature: Files reminders
4+
5+
Background:
6+
Given using api version "2"
7+
8+
Scenario: Set a reminder with a past due date
9+
Given user "user0" exists
10+
Given As an "user0"
11+
Given User "user0" uploads file "data/textfile.txt" to "/file.txt"
12+
When the user sets a reminder for "/file.txt" with due date "2000-01-01T00:00:00Z"
13+
Then the OCS status code should be "400"
14+
Then the user sees the reminder for "/file.txt" is not set
15+
16+
Scenario: Set a reminder with a valid due date
17+
Given user "user1" exists
18+
Given As an "user1"
19+
Given User "user1" uploads file "data/textfile.txt" to "/file.txt"
20+
When the user sets a reminder for "/file.txt" with due date "2100-01-01T00:00:00Z"
21+
Then the OCS status code should be "201"
22+
Then the user sees the reminder for "/file.txt" is set to "2100-01-01T00:00:00+00:00"
23+
24+
Scenario: Remove a reminder
25+
Given user "user2" exists
26+
Given As an "user2"
27+
Given User "user2" uploads file "data/textfile.txt" to "/file.txt"
28+
When the user sets a reminder for "/file.txt" with due date "2100-01-01T00:00:00Z"
29+
Then the OCS status code should be "201"
30+
Then the user sees the reminder for "/file.txt" is set to "2100-01-01T00:00:00+00:00"
31+
When the user removes the reminder for "/file.txt"
32+
Then the OCS status code should be "200"
33+
Then the user sees the reminder for "/file.txt" is not set

0 commit comments

Comments
 (0)