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); test("file w/ metadata-photos-ifd0", _filesNc28MetadataIfd0); test("file w/ metadata-photos-exif", _filesNc28MetadataExif); test("file w/ metadata-photos-gps", _filesNc28MetadataGps); test("file w/ metadata-photos-size", _filesNc28MetadataSize); }); }); } 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, ), ]); } Future _filesNc28MetadataIfd0() async { const xml = """ /nextcloud/remote.php/dav/files/admin/1.jpg Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" image/jpeg 123 3963036 false SUPER Phone 1 1 72/1 72/1 2 1.0 2020:01:02 03:04:05 1 HTTP/1.1 200 OK """; final results = await FileParser().parse(xml); expect(results, [ File( href: "/nextcloud/remote.php/dav/files/admin/1.jpg", contentLength: 3963036, contentType: "image/jpeg", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, metadataPhotosIfd0: { "Make": "SUPER", "Model": "Phone 1", "Orientation": "1", "XResolution": "72/1", "YResolution": "72/1", "ResolutionUnit": "2", "Software": "1.0", "DateTime": "2020:01:02 03:04:05", "YCbCrPositioning": "1", }, ), ]); } Future _filesNc28MetadataExif() async { const xml = """ /nextcloud/remote.php/dav/files/admin/1.jpg Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" image/jpeg 123 3963036 false 1/381 9/5 2 20 0231 2020:01:02 03:04:05 2020:01:02 03:04:05 +01:00 126682/14777 54823/32325 69659/9080 0/1 5 16 4/1 SUPER 65535 4032 3024 2 0 0 28 0 HTTP/1.1 200 OK """; final results = await FileParser().parse(xml); expect(results, [ File( href: "/nextcloud/remote.php/dav/files/admin/1.jpg", contentLength: 3963036, contentType: "image/jpeg", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, metadataPhotosExif: { "ExposureTime": "1/381", "FNumber": "9/5", "ExposureProgram": "2", "ISOSpeedRatings": "20", "ExifVersion": "0231", "DateTimeOriginal": "2020:01:02 03:04:05", "DateTimeDigitized": "2020:01:02 03:04:05", "UndefinedTag__x____": "+01:00", "ComponentsConfiguration": "", "ShutterSpeedValue": "126682/14777", "ApertureValue": "54823/32325", "BrightnessValue": "69659/9080", "ExposureBiasValue": "0/1", "MeteringMode": "5", "Flash": "16", "FocalLength": "4/1", "MakerNote": "SUPER", "ColorSpace": "65535", "ExifImageWidth": "4032", "ExifImageLength": "3024", "SensingMethod": "2", "SceneType": "", "ExposureMode": "0", "WhiteBalance": "0", "FocalLengthIn__mmFilm": "28", "SceneCaptureType": "0", }, ), ]); } Future _filesNc28MetadataGps() async { const xml = """ /nextcloud/remote.php/dav/files/admin/1.jpg Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" image/jpeg 123 3963036 false 1.23456 2.34567 3.45678 HTTP/1.1 200 OK """; final results = await FileParser().parse(xml); expect(results, [ File( href: "/nextcloud/remote.php/dav/files/admin/1.jpg", contentLength: 3963036, contentType: "image/jpeg", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, metadataPhotosGps: { "latitude": "1.23456", "longitude": "2.34567", "altitude": "3.45678", }, ), ]); } Future _filesNc28MetadataSize() async { const xml = """ /nextcloud/remote.php/dav/files/admin/1.jpg Fri, 01 Jan 2021 02:03:04 GMT "1324f58d4d5c8d81bed6e4ed9d5ea862" image/jpeg 123 3963036 false 4032 3024 HTTP/1.1 200 OK """; final results = await FileParser().parse(xml); expect(results, [ File( href: "/nextcloud/remote.php/dav/files/admin/1.jpg", contentLength: 3963036, contentType: "image/jpeg", etag: "1324f58d4d5c8d81bed6e4ed9d5ea862", lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4), hasPreview: false, fileId: 123, isCollection: false, metadataPhotosSize: { "width": "4032", "height": "3024", }, ), ]); }