import 'package:np_api/src/entity/entity.dart'; import 'package:np_api/src/entity/file_parser.dart'; import 'package:test/test.dart'; void main() { group("FileParser", () { group("parse", () { test("file", _files); test("file w/ 404 properties", _files404props); test("file w/ metadata", _filesMetadata); test("file w/ is-archived", _filesIsArchived); test("file w/ override-date-time", _filesOverrideDateTime); test("multiple files", _filesMultiple); test("directory", _filesDir); test("nextcloud hosted in subdir", _filesServerHostedInSubdir); }); }); } Future _files() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/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, ), ]); } Future _files404props() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/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, ), ]); } Future _filesMetadata() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/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, customProperties: { "com.nkming.nc_photos:metadata": "{\"version\":2,\"lastUpdated\":\"2021-01-02T03:04:05.678Z\",\"fileEtag\":\"8950e39a034e369237d9285e2d815a50\",\"imageWidth\":3000,\"imageHeight\":2000}", }, ), ]); } Future _filesIsArchived() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/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, customProperties: { "com.nkming.nc_photos:is-archived": "true", }, ), ]); } Future _filesOverrideDateTime() async { const xml = """ /remote.php/dav/files/admin/Photos/Nextcloud%20community.jpg Fri, 01 Jan 2021 02:03:04 GMT "8950e39a034e369237d9285e2d815a50" image/jpeg 797325 true 2021-01-02T03:04:05.000Z HTTP/1.1 200 OK """; final results = await FileParser().parse(xml); expect(results, [ File( href: "/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, customProperties: { "com.nkming.nc_photos:override-date-time": "2021-01-02T03:04:05.000Z", }, ), ]); } Future _filesMultiple() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/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( href: "/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, customProperties: { "com.nkming.nc_photos:metadata": "{\"version\":2,\"lastUpdated\":\"2021-01-02T03:04:05.678000Z\",\"fileEtag\":\"48689d5b17c449d9db492ffe8f7ab8a6\",\"imageWidth\":500,\"imageHeight\":500}", }, ), ]); } Future _filesDir() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/remote.php/dav/files/admin/Photos/", etag: "123456789abcd", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), isCollection: true, hasPreview: false, fileId: 123, ), ]); } Future _filesServerHostedInSubdir() async { const xml = """ /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 = await FileParser().parse(xml); expect(results, [ File( href: "/nextcloud/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, ), ]); }