Browse Source

nextcloud: Add tests for WebDavFile

pull/393/head
jld3103 2 years ago
parent
commit
71a24ba847
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 7
      packages/nextcloud/lib/src/webdav/file.dart
  2. 108
      packages/nextcloud/test/webdav.dart

7
packages/nextcloud/lib/src/webdav/file.dart

@ -71,11 +71,12 @@ class WebDavFile {
/// Upload date of the file
late final DateTime? uploadedDate =
props.ncuploadtime != null ? DateTime.fromMillisecondsSinceEpoch(props.ncuploadtime! * 1000) : null;
props.ncuploadtime != null ? DateTime.fromMillisecondsSinceEpoch(props.ncuploadtime! * 1000, isUtc: true) : null;
/// Creation date of the file as provided by uploader
late final DateTime? createdDate =
props.nccreationtime != null ? DateTime.fromMillisecondsSinceEpoch(props.nccreationtime! * 1000) : null;
late final DateTime? createdDate = props.nccreationtime != null
? DateTime.fromMillisecondsSinceEpoch(props.nccreationtime! * 1000, isUtc: true)
: null;
/// Whether this file is marked as favorite
late final bool? favorite = props.ocfavorite == null ? null : props.ocfavorite == 1;

108
packages/nextcloud/test/webdav.dart

@ -221,7 +221,7 @@ Future run(final DockerImage image) async {
});
test('Get file props', () async {
final props = (await client.webdav.ls(
final response = (await client.webdav.ls(
'Nextcloud.png',
prop: WebDavPropfindProp.fromBools(
davgetlastmodified: true,
@ -253,38 +253,54 @@ Future run(final DockerImage image) async {
ocmsharepermissions: true,
),
))
.responses
.single
.propstats
.first
.prop;
expect(webdavDateFormat.parseUtc(props.davgetlastmodified!).isBefore(DateTime.now()), isTrue);
expect(props.davgetetag, isNotEmpty);
expect(props.davgetcontenttype, 'image/png');
expect(props.davgetcontentlength, 50598);
expect(props.davresourcetype!.collection, isNull);
expect(props.ocid, isNotEmpty);
expect(props.ocfileid, isNotEmpty);
expect(props.ocfavorite, 0);
expect(props.occommentshref, isNotEmpty);
expect(props.occommentscount, 0);
expect(props.occommentsunread, 0);
expect(props.ocdownloadurl, isNull);
expect(props.ocownerid, 'user1');
expect(props.ocownerdisplayname, 'User One');
expect(props.ocsize, 50598);
expect(props.ocpermissions, 'RGDNVW');
expect(props.ncnote, isNull);
expect(props.ncdatafingerprint, isNull);
expect(props.nchaspreview, isTrue);
expect(props.ncmounttype, isNull);
expect(props.ncisencrypted, isNull);
expect(props.ncmetadataetag, isNull);
expect(props.ncuploadtime, 0);
expect(props.nccreationtime, 0);
expect(props.ncrichworkspace, isNull);
expect(props.ocssharepermissions, 19);
expect(json.decode(props.ocmsharepermissions!), ['share', 'read', 'write']);
.toWebDavFiles(client.webdav)
.single;
expect(response.path, '/Nextcloud.png');
expect(response.id, isNotEmpty);
expect(response.fileId, isNotEmpty);
expect(response.isCollection, isFalse);
expect(response.mimeType, 'image/png');
expect(response.etag, isNotEmpty);
expect(response.size, 50598);
expect(response.ownerId, 'user1');
expect(response.ownerDisplay, 'User One');
expect(response.lastModified!.isBefore(DateTime.now()), isTrue);
expect(response.isDirectory, isFalse);
expect(response.uploadedDate, DateTime.utc(1970));
expect(response.createdDate, DateTime.utc(1970));
expect(response.favorite, isFalse);
expect(response.hasPreview, isTrue);
expect(response.name, 'Nextcloud.png');
expect(response.isDirectory, isFalse);
expect(webdavDateFormat.parseUtc(response.props.davgetlastmodified!).isBefore(DateTime.now()), isTrue);
expect(response.props.davgetetag, isNotEmpty);
expect(response.props.davgetcontenttype, 'image/png');
expect(response.props.davgetcontentlength, 50598);
expect(response.props.davresourcetype!.collection, isNull);
expect(response.props.ocid, isNotEmpty);
expect(response.props.ocfileid, isNotEmpty);
expect(response.props.ocfavorite, 0);
expect(response.props.occommentshref, isNotEmpty);
expect(response.props.occommentscount, 0);
expect(response.props.occommentsunread, 0);
expect(response.props.ocdownloadurl, isNull);
expect(response.props.ocownerid, 'user1');
expect(response.props.ocownerdisplayname, 'User One');
expect(response.props.ocsize, 50598);
expect(response.props.ocpermissions, 'RGDNVW');
expect(response.props.ncnote, isNull);
expect(response.props.ncdatafingerprint, isNull);
expect(response.props.nchaspreview, isTrue);
expect(response.props.ncmounttype, isNull);
expect(response.props.ncisencrypted, isNull);
expect(response.props.ncmetadataetag, isNull);
expect(response.props.ncuploadtime, 0);
expect(response.props.nccreationtime, 0);
expect(response.props.ncrichworkspace, isNull);
expect(response.props.ocssharepermissions, 19);
expect(json.decode(response.props.ocmsharepermissions!), ['share', 'read', 'write']);
});
test('Get directory props', () async {
@ -292,7 +308,7 @@ Future run(final DockerImage image) async {
await client.webdav.mkdir('test');
await client.webdav.upload(data, 'test/test.txt');
final props = (await client.webdav.ls(
final response = (await client.webdav.ls(
'test',
prop: WebDavPropfindProp.fromBools(
davgetcontenttype: true,
@ -302,15 +318,21 @@ Future run(final DockerImage image) async {
),
depth: '0',
))
.responses
.single
.propstats
.first
.prop;
expect(props.davgetcontenttype, isNull);
expectDateInReasonableTimeRange(webdavDateFormat.parseUtc(props.davgetlastmodified!), DateTime.now());
expect(props.davresourcetype!.collection, isNotNull);
expect(props.ocsize, data.lengthInBytes);
.toWebDavFiles(client.webdav)
.single;
expect(response.path, '/test/');
expect(response.isCollection, isTrue);
expect(response.mimeType, isNull);
expect(response.size, data.lengthInBytes);
expectDateInReasonableTimeRange(response.lastModified!, DateTime.now());
expect(response.name, 'test');
expect(response.isDirectory, isTrue);
expect(response.props.davgetcontenttype, isNull);
expectDateInReasonableTimeRange(webdavDateFormat.parseUtc(response.props.davgetlastmodified!), DateTime.now());
expect(response.props.davresourcetype!.collection, isNotNull);
expect(response.props.ocsize, data.lengthInBytes);
});
test('Filter files', () async {

Loading…
Cancel
Save