Skip to content

Commit

Permalink
refactor(nextcloud)!: Return raw response in WebDAV proppatch
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 10, 2024
1 parent 9692c52 commit ea1b5f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
13 changes: 2 additions & 11 deletions packages/nextcloud/lib/src/api/webdav/webdav_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,11 @@ class WebDavClient extends DynamiteClient {
///
/// The props in [set] will be added/updated.
/// The props in [remove] will be removed.
/// Returns true if the update was successful.
///
/// See:
/// * http://www.webdav.org/specs/rfc2518.html#METHOD_PROPPATCH for more information.
/// * [proppatch_Request] for the request sent by this method.
Future<bool> proppatch(
Future<WebDavMultistatus> proppatch(
PathUri path, {
WebDavProp? set,
WebDavPropWithoutValues? remove,
Expand All @@ -612,15 +611,7 @@ class WebDavClient extends DynamiteClient {
throw DynamiteStatusCodeException(response);
}

final data = const WebDavResponseConverter().convert(response);
for (final a in data.responses) {
for (final b in a.propstats) {
if (!b.status.contains('200')) {
return false;
}
}
}
return true;
return const WebDavResponseConverter().convert(response);
}

/// Returns a request to move the resource from [sourcePath] to [destinationPath].
Expand Down
30 changes: 21 additions & 9 deletions packages/nextcloud/test/api/webdav/webdav_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,16 @@ void main() {
created: createdDate,
);

final updated = await tester.client.webdav.proppatch(
final response = await tester.client.webdav.proppatch(
PathUri.parse('test/set-props.txt'),
set: const WebDavProp(
ocFavorite: true,
),
);
expect(updated, isTrue);
expect(
response.responses.where((r) => r.propstats.where((ps) => !ps.status.contains('200 OK')).isNotEmpty),
isEmpty,
);

final props = (await tester.client.webdav.propfind(
PathUri.parse('test/set-props.txt'),
Expand All @@ -440,13 +443,16 @@ void main() {
test('Remove properties', () async {
await tester.client.webdav.put(utf8.encode('test'), PathUri.parse('test/remove-props.txt'));

var updated = await tester.client.webdav.proppatch(
var response = await tester.client.webdav.proppatch(
PathUri.parse('test/remove-props.txt'),
set: const WebDavProp(
ocFavorite: true,
),
);
expect(updated, isTrue);
expect(
response.responses.where((r) => r.propstats.where((ps) => !ps.status.contains('200 OK')).isNotEmpty),
isEmpty,
);

var props = (await tester.client.webdav.propfind(
PathUri.parse('test/remove-props.txt'),
Expand All @@ -463,13 +469,16 @@ void main() {
.prop;
expect(props.ocFavorite, true);

updated = await tester.client.webdav.proppatch(
response = await tester.client.webdav.proppatch(
PathUri.parse('test/remove-props.txt'),
remove: const WebDavPropWithoutValues.fromBools(
ocFavorite: true,
),
);
expect(updated, isFalse);
expect(
response.responses.where((r) => r.propstats.where((ps) => !ps.status.contains('200 OK')).isNotEmpty),
isNotEmpty,
);

props = (await tester.client.webdav.propfind(
PathUri.parse('test/remove-props.txt'),
Expand All @@ -491,15 +500,18 @@ void main() {
PathUri.parse('test/tags.txt'),
);

final updated = await tester.client.webdav.proppatch(
var response = await tester.client.webdav.proppatch(
PathUri.parse('test/tags.txt'),
set: const WebDavProp(
ocTags: WebDavOcTags(tags: ['example']),
),
);
expect(updated, isTrue);
expect(
response.responses.where((r) => r.propstats.where((ps) => !ps.status.contains('200 OK')).isNotEmpty),
isEmpty,
);

final response = await tester.client.webdav.propfind(
response = await tester.client.webdav.propfind(
PathUri.parse('test/tags.txt'),
prop: const WebDavPropWithoutValues.fromBools(
ocTags: true,
Expand Down

0 comments on commit ea1b5f7

Please sign in to comment.