import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/album/upgrader.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:test/test.dart'; void main() { group("Album", () { group("fromJson", () { test("lastUpdated", () { final json = { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "provider": { "type": "static", "content": { "items": [], }, }, }; expect( Album.fromJson(json), Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [], ), )); }); test("name", () { final json = { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "album", "provider": { "type": "static", "content": { "items": [], }, }, }; expect( Album.fromJson(json), Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "album", provider: AlbumStaticProvider( items: [], ), )); }); test("AlbumStaticProvider", () { final json = { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test2.jpg", }, }, }, ], }, }, }; expect( Album.fromJson(json), Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [ AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test1.jpg"), ), AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test2.jpg"), ), ], ), )); }); test("albumFile", () { final json = { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "provider": { "type": "static", "content": { "items": [], }, }, "albumFile": { "path": "remote.php/dav/files/admin/test1.jpg", }, }; expect( Album.fromJson(json), Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [], ), albumFile: File(path: "remote.php/dav/files/admin/test1.jpg"), )); }); }); group("toRemoteJson", () { test("lastUpdated", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [], ), ); expect(album.toRemoteJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [], }, }, }); }); test("name", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "album", provider: AlbumStaticProvider( items: [], ), ); expect(album.toRemoteJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "album", "provider": { "type": "static", "content": { "items": [], }, }, }); }); test("AlbumStaticProvider", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [ AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test1.jpg"), ), AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test2.jpg"), ), ], ), ); expect(album.toRemoteJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test2.jpg", }, }, }, ], }, }, }); }); }); group("toAppDbJson", () { test("lastUpdated", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [], ), ); expect(album.toAppDbJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [], }, }, }); }); test("name", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "album", provider: AlbumStaticProvider( items: [], ), ); expect(album.toAppDbJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "album", "provider": { "type": "static", "content": { "items": [], }, }, }); }); test("AlbumStaticProvider", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [ AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test1.jpg"), ), AlbumFileItem( file: File(path: "remote.php/dav/files/admin/test2.jpg"), ), ], ), ); expect(album.toAppDbJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test2.jpg", }, }, }, ], }, }, }); }); test("albumFile", () { final album = Album( lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901), name: "", provider: AlbumStaticProvider( items: [], ), albumFile: File(path: "remote.php/dav/files/admin/test1.jpg"), ); expect(album.toAppDbJson(), { "version": Album.version, "lastUpdated": "2020-01-02T03:04:05.678901Z", "name": "", "provider": { "type": "static", "content": { "items": [], }, }, "albumFile": { "path": "remote.php/dav/files/admin/test1.jpg", }, }); }); }); test("AlbumUpgraderV1", () { final json = { "version": 1, "lastUpdated": "2020-01-02T03:04:05.678901Z", "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, ], "albumFile": { "path": "remote.php/dav/files/admin/test1.json", }, }; expect(AlbumUpgraderV1()(json), { "version": 1, "lastUpdated": "2020-01-02T03:04:05.678901Z", "items": [], "albumFile": { "path": "remote.php/dav/files/admin/test1.json", }, }); }); test("AlbumUpgraderV2", () { final json = { "version": 2, "lastUpdated": "2020-01-02T03:04:05.678901Z", "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, ], "albumFile": { "path": "remote.php/dav/files/admin/test1.json", }, }; expect(AlbumUpgraderV2()(json), { "version": 2, "lastUpdated": "2020-01-02T03:04:05.678901Z", "provider": { "type": "static", "content": { "items": [ { "type": "file", "content": { "file": { "path": "remote.php/dav/files/admin/test1.jpg", }, }, }, ], }, }, "albumFile": { "path": "remote.php/dav/files/admin/test1.json", }, }); }); }); }