nc-photos/test/entity/album_test.dart

1672 lines
54 KiB
Dart
Raw Normal View History

import 'package:intl/intl.dart';
import 'package:nc_photos/account.dart';
2021-04-15 20:46:34 +02:00
import 'package:nc_photos/entity/album.dart';
2021-06-26 13:51:13 +02:00
import 'package:nc_photos/entity/album/cover_provider.dart';
2021-07-05 09:54:01 +02:00
import 'package:nc_photos/entity/album/item.dart';
2021-06-24 18:26:56 +02:00
import 'package:nc_photos/entity/album/provider.dart';
2021-07-07 20:40:43 +02:00
import 'package:nc_photos/entity/album/sort_provider.dart';
2021-06-24 16:54:41 +02:00
import 'package:nc_photos/entity/album/upgrader.dart';
2021-04-15 20:46:34 +02:00
import 'package:nc_photos/entity/file.dart';
import 'package:test/test.dart';
void main() {
group("Album", () {
group("fromJson", () {
test("lastUpdated", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
2021-07-23 22:05:57 +02:00
"name": "",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-04-15 20:46:34 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
));
});
test("name", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "album",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-04-15 20:46:34 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "album",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
));
});
2021-07-09 12:07:37 +02:00
group("AlbumStaticProvider", () {
test("AlbumFileItem", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test2.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
],
},
2021-04-15 20:46:34 +02:00
},
2021-07-09 12:07:37 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-07-09 12:07:37 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test1.jpg"),
),
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test2.jpg"),
),
],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
));
});
test("AlbumLabelItem", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "label",
"content": <String, dynamic>{
"text": "Testing",
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-07-09 12:07:37 +02:00
},
2021-06-24 18:26:56 +02:00
],
2021-07-09 12:07:37 +02:00
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-07-09 12:07:37 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumLabelItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
text: "Testing",
),
],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
));
});
2021-06-26 13:51:13 +02:00
});
test("AlbumAutoCoverProvider", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-06-26 13:51:13 +02:00
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-06-26 13:51:13 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(
coverFile: File(
path: "remote.php/dav/files/admin/test1.jpg",
),
),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-07 20:40:43 +02:00
));
});
test("AlbumTimeSortProvider", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": true,
},
},
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-07-07 20:40:43 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumTimeSortProvider(
2021-07-07 20:40:43 +02:00
isAscending: true,
),
2021-04-15 20:46:34 +02:00
));
});
test("albumFile", () {
final json = <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
2021-07-23 22:05:57 +02:00
"name": "",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
2021-04-15 20:46:34 +02:00
},
};
expect(
Album.fromJson(
json,
upgraderV1: null,
upgraderV2: null,
upgraderV3: null,
upgraderV4: null,
upgraderV5: null,
),
2021-04-15 20:46:34 +02:00
Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
albumFile: File(path: "remote.php/dav/files/admin/test1.jpg"),
2021-04-15 20:46:34 +02:00
));
});
});
group("toRemoteJson", () {
test("lastUpdated", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
);
expect(album.toRemoteJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
});
});
test("name", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "album",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
);
expect(album.toRemoteJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "album",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
});
});
2021-07-09 12:07:37 +02:00
group("AlbumStaticProvider", () {
test("AlbumFileItem", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test1.jpg"),
),
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test2.jpg"),
),
],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
);
expect(album.toRemoteJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test2.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
});
test("AlbumLabelItem", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumLabelItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
text: "Testing",
),
2021-06-24 18:26:56 +02:00
],
2021-07-09 12:07:37 +02:00
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
);
expect(album.toRemoteJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "label",
"content": <String, dynamic>{
"text": "Testing",
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-07-09 12:07:37 +02:00
},
],
},
2021-04-15 20:46:34 +02:00
},
2021-07-09 12:07:37 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
2021-06-26 13:51:13 +02:00
});
});
test("AlbumAutoCoverProvider", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(
coverFile: File(path: "remote.php/dav/files/admin/test1.jpg")),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-06-26 13:51:13 +02:00
);
expect(album.toRemoteJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
});
test("AlbumTimeSortProvider", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumTimeSortProvider(
2021-07-07 20:40:43 +02:00
isAscending: true,
),
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": true,
},
},
2021-04-15 20:46:34 +02:00
});
});
});
group("toAppDbJson", () {
test("lastUpdated", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
});
});
test("name", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "album",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-04-15 20:46:34 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "album",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
});
});
2021-07-09 12:07:37 +02:00
group("AlbumStaticProvider", () {
test("AlbumFileItem", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test1.jpg"),
),
AlbumFileItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
file: File(path: "remote.php/dav/files/admin/test2.jpg"),
),
],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test2.jpg",
},
2021-06-24 18:26:56 +02:00
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-06-24 18:26:56 +02:00
},
2021-07-09 12:07:37 +02:00
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
});
test("AlbumLabelItem", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [
AlbumLabelItem(
addedBy: "admin",
addedAt: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
2021-07-09 12:07:37 +02:00
text: "Testing",
),
2021-06-24 18:26:56 +02:00
],
2021-07-09 12:07:37 +02:00
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-07-09 12:07:37 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "label",
"content": <String, dynamic>{
"text": "Testing",
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
2021-07-09 12:07:37 +02:00
},
],
},
2021-04-15 20:46:34 +02:00
},
2021-07-09 12:07:37 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
2021-06-26 13:51:13 +02:00
});
});
test("AlbumAutoCoverProvider", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(
coverFile: File(
path: "remote.php/dav/files/admin/test1.jpg",
),
),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
2021-06-26 13:51:13 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
});
});
test("AlbumTimeSortProvider", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
provider: AlbumStaticProvider(
items: [],
),
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumTimeSortProvider(
2021-07-07 20:40:43 +02:00
isAscending: true,
),
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": true,
},
},
2021-04-15 20:46:34 +02:00
});
});
test("albumFile", () {
final album = Album(
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5, 678, 901),
name: "",
2021-06-24 18:26:56 +02:00
provider: AlbumStaticProvider(
items: [],
),
2021-06-26 13:51:13 +02:00
coverProvider: AlbumAutoCoverProvider(),
2021-09-15 08:58:06 +02:00
sortProvider: const AlbumNullSortProvider(),
albumFile: File(path: "remote.php/dav/files/admin/test1.jpg"),
2021-04-15 20:46:34 +02:00
);
expect(album.toAppDbJson(), <String, dynamic>{
"version": Album.version,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"name": "",
2021-06-24 18:26:56 +02:00
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-07-07 20:40:43 +02:00
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
2021-04-15 20:46:34 +02:00
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
2021-04-15 20:46:34 +02:00
},
});
});
});
2021-06-24 16:54:41 +02:00
test("AlbumUpgraderV1", () {
final json = <String, dynamic>{
"version": 1,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV1()(json), <String, dynamic>{
"version": 1,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"items": [],
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
2021-04-15 20:46:34 +02:00
});
});
2021-06-24 18:26:56 +02:00
test("AlbumUpgraderV2", () {
final json = <String, dynamic>{
"version": 2,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV2()(json), <String, dynamic>{
"version": 2,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
2021-06-26 13:51:13 +02:00
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
2021-06-24 18:26:56 +02:00
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
2021-07-07 20:40:43 +02:00
test("AlbumUpgraderV3", () {
final json = <String, dynamic>{
"version": 3,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV3()(json), <String, dynamic>{
"version": 3,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
group("AlbumUpgraderV4", () {
test("Non AlbumFileItem", () {
final json = <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "label",
"content": <String, dynamic>{
"text": "123",
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV4()(json), <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "label",
"content": <String, dynamic>{
"text": "123",
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
group("AlbumFileItem", () {
test("drop metadata", () {
final json = <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"metadata": <String, dynamic>{
"Make": "Super",
"Model": "A123",
},
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV4()(json), <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
test("lastModified as latestItemTime", () {
final json = <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"lastModified": "2020-01-02T03:04:05.678901Z",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV4()(json), <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"latestItemTime": "2020-01-02T03:04:05.678901Z",
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"lastModified": "2020-01-02T03:04:05.678901Z",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"lastModified": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
test("dateTimeOriginal as latestItemTime", () {
final json = <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"metadata": <String, dynamic>{
"exif": <String, dynamic>{
// convert 2020-01-02T03:04:05Z to local time
"DateTimeOriginal":
DateFormat("yyyy:MM:dd HH:mm:ss").format(
DateTime.utc(2020, 1, 2, 3, 4, 5)
.toLocal()),
},
},
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV4()(json), <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"latestItemTime": "2020-01-02T03:04:05.000Z",
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
test("overrideDateTime as latestItemTime", () {
final json = <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"overrideDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV4()(json), <String, dynamic>{
"version": 4,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"latestItemTime": "2020-01-02T03:04:05.678901Z",
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"overrideDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"overrideDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
});
});
group("AlbumUpgraderV5", () {
final account = Account("http", "example.com", "user1", "123", [""]);
test("w/ ownerId", () {
final json = <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
"ownerId": "admin",
},
};
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
"ownerId": "admin",
},
});
});
test("w/o ownerId", () {
final json = <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
"addedBy": "user1",
"addedAt": "2020-01-02T03:04:05.678901Z",
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
test("w/o albumFile", () {
final json = <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
};
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
"addedBy": "user1",
"addedAt": "2020-01-02T03:04:05.678901Z",
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
});
});
test("w/ external albumFile", () {
final json = <String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
};
final albumFile = File(
path: "remote.php/dav/files/admin/test1.json",
ownerId: "admin",
);
expect(
AlbumUpgraderV5(account, albumFile: albumFile)(json),
<String, dynamic>{
"version": 5,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [
<String, dynamic>{
"type": "file",
"content": <String, dynamic>{
"file": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
},
},
"addedBy": "admin",
"addedAt": "2020-01-02T03:04:05.678901Z",
},
],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "time",
"content": <String, dynamic>{
"isAscending": false,
},
},
});
});
});
2021-04-15 20:46:34 +02:00
});
}