import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/webdav_response_parser.dart'; import 'package:test/test.dart'; import 'package:xml/xml.dart'; void main() { group("WebdavFileParser", () { test("file", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Nextcloud%20intro.mp4 Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" video/mp4 123 3963036 false HTTP/1.1 200 OK """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Nextcloud intro.mp4", contentLength: 3963036, contentType: "video/mp4", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, ), ]); }); test("file w/ 404 properties", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Nextcloud%20intro.mp4 Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" video/mp4 123 3963036 false HTTP/1.1 200 OK HTTP/1.1 404 Not Found """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Nextcloud intro.mp4", contentLength: 3963036, contentType: "video/mp4", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, ), ]); }); test("file w/ metadata", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Photos/Nextcloud%20community.jpg Fri, 01 Jan 2021 02:03:04 GMT "8950e39a034e369237d9285e2d815a50" image/jpeg 123 797325 true {"version":2,"lastUpdated":"2021-01-02T03:04:05.678Z","fileEtag":"8950e39a034e369237d9285e2d815a50","imageWidth":3000,"imageHeight":2000} HTTP/1.1 200 OK """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Photos/Nextcloud community.jpg", contentLength: 797325, contentType: "image/jpeg", etag: "8950e39a034e369237d9285e2d815a50", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: true, fileId: 123, isCollection: false, metadata: Metadata( lastUpdated: DateTime.utc(2021, 1, 2, 3, 4, 5, 678), fileEtag: "8950e39a034e369237d9285e2d815a50", imageWidth: 3000, imageHeight: 2000, ), ), ]); }); test("file w/ is-archived", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Photos/Nextcloud%20community.jpg Fri, 01 Jan 2021 02:03:04 GMT "8950e39a034e369237d9285e2d815a50" image/jpeg 797325 true true HTTP/1.1 200 OK """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Photos/Nextcloud community.jpg", contentLength: 797325, contentType: "image/jpeg", etag: "8950e39a034e369237d9285e2d815a50", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: true, isCollection: false, isArchived: true, ), ]); }); test("multiple files", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Nextcloud%20intro.mp4 Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" video/mp4 123 3963036 false HTTP/1.1 200 OK /remote.php/dav/files/admin/Nextcloud.png Sat, 02 Jan 2021 03:04:05 GMT "48689d5b17c449d9db492ffe8f7ab8a6" image/png 124 50598 true {"version":2,"lastUpdated":"2021-01-02T03:04:05.678000Z","fileEtag":"48689d5b17c449d9db492ffe8f7ab8a6","imageWidth":500,"imageHeight":500} HTTP/1.1 200 OK """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Nextcloud intro.mp4", contentLength: 3963036, contentType: "video/mp4", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, ), File( path: "remote.php/dav/files/admin/Nextcloud.png", contentLength: 50598, contentType: "image/png", etag: "48689d5b17c449d9db492ffe8f7ab8a6", lastModified: DateTime.utc(2021, 1, 2, 3, 4, 5), hasPreview: true, fileId: 124, isCollection: false, metadata: Metadata( fileEtag: "48689d5b17c449d9db492ffe8f7ab8a6", imageWidth: 500, imageHeight: 500, lastUpdated: DateTime.utc(2021, 1, 2, 3, 4, 5, 678), ), ), ]); }); test("directory", () { final xml = XmlDocument.parse(""" /remote.php/dav/files/admin/Photos/ Fri, 01 Jan 2021 02:03:04 GMT "123456789abcd" 123 false HTTP/1.1 200 OK HTTP/1.1 404 Not Found """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Photos", etag: "123456789abcd", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), isCollection: true, hasPreview: false, fileId: 123, ), ]); }); test("nextcloud hosed in subdir", () { final xml = XmlDocument.parse(""" /nextcloud/remote.php/dav/files/admin/Nextcloud%20intro.mp4 Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" video/mp4 123 3963036 false HTTP/1.1 200 OK """); final results = WebdavFileParser()(xml); expect(results, [ File( path: "remote.php/dav/files/admin/Nextcloud intro.mp4", contentLength: 3963036, contentType: "video/mp4", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, ), ]); }); }); }