mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Simplify tests
This commit is contained in:
parent
004c4fe39f
commit
d937e33685
4 changed files with 33 additions and 131 deletions
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:idb_shim/idb.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/ci_string.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/album/cover_provider.dart';
|
||||
|
@ -12,6 +14,8 @@ import 'package:nc_photos/entity/share.dart';
|
|||
import 'package:nc_photos/entity/sharee.dart';
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
|
||||
import 'mock_type.dart';
|
||||
|
||||
class FilesBuilder {
|
||||
FilesBuilder({
|
||||
int initialFileId = 0,
|
||||
|
@ -266,3 +270,15 @@ Sharee buildSharee({
|
|||
shareType: shareType,
|
||||
shareWith: shareWith,
|
||||
);
|
||||
|
||||
Future<void> fillAppDb(
|
||||
MockAppDb appDb, Account account, Iterable<File> files) async {
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
for (final f in files) {
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, f).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, f));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'package:event_bus/event_bus.dart';
|
||||
import 'package:idb_shim/idb.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/ci_string.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/album/cover_provider.dart';
|
||||
|
@ -44,12 +42,7 @@ Future<void> _addFile() async {
|
|||
final album = util.AlbumBuilder().build();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, [file]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
|
||||
|
@ -108,12 +101,7 @@ Future<void> _addExistingFile() async {
|
|||
final newFile = files[0].copyWith();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
|
||||
|
@ -190,12 +178,7 @@ Future<void> _addFileToSharedAlbumOwned() async {
|
|||
final album = (util.AlbumBuilder()..addShare("user1")).build();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, [file]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: albumFile, shareWith: "user1"),
|
||||
|
@ -236,12 +219,7 @@ Future<void> _addFileOwnedByUserToSharedAlbumOwned() async {
|
|||
final album = (util.AlbumBuilder()..addShare("user1")).build();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, [file]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: albumFile, shareWith: "user1"),
|
||||
|
@ -284,18 +262,13 @@ Future<void> _addFileToMultiuserSharedAlbumNotOwned() async {
|
|||
.build();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, [file]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(
|
||||
id: "0", uidOwner: "user1", file: albumFile, shareWith: "admin"),
|
||||
id: "0", file: albumFile, uidOwner: "user1", shareWith: "admin"),
|
||||
util.buildShare(
|
||||
id: "1", uidOwner: "user1", file: albumFile, shareWith: "user2"),
|
||||
id: "1", file: albumFile, uidOwner: "user1", shareWith: "user2"),
|
||||
]);
|
||||
|
||||
await AddToAlbum(albumRepo, shareRepo, appDb, pref)(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'package:event_bus/event_bus.dart';
|
||||
import 'package:idb_shim/idb.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/pref.dart';
|
||||
import 'package:nc_photos/use_case/remove_album.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
@ -31,15 +29,6 @@ Future<void> _removeAlbum() async {
|
|||
final albumFile1 = album1.albumFile!;
|
||||
final album2 = util.AlbumBuilder.ofId(albumId: 1).build();
|
||||
final albumFile2 = album2.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, albumFile1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, albumFile1));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, albumFile2).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, albumFile2));
|
||||
});
|
||||
final fileRepo = MockFileMemoryRepo([albumFile1, albumFile2]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album1, album2]);
|
||||
final shareRepo = MockShareRepo();
|
||||
|
@ -66,15 +55,6 @@ Future<void> _removeSharedAlbum() async {
|
|||
..addShare("user1"))
|
||||
.build();
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, albumFile).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, albumFile));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
});
|
||||
final fileRepo = MockFileMemoryRepo([albumFile, ...files]);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
|
@ -112,17 +92,6 @@ Future<void> _removeSharedAlbumFileInOtherAlbum() async {
|
|||
.build(),
|
||||
];
|
||||
final albumFiles = albums.map((e) => e.albumFile!).toList();
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, albumFiles[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, albumFiles[0]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, albumFiles[1]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, albumFiles[1]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
});
|
||||
final fileRepo = MockFileMemoryRepo([...albumFiles, ...files]);
|
||||
final albumRepo = MockAlbumMemoryRepo(albums);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
|
|
|
@ -49,12 +49,7 @@ Future<void> _removeLastFile() async {
|
|||
final fileItem1 = util.AlbumBuilder.fileItemsOf(album)[0];
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file1));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
final fileRepo = MockFileMemoryRepo([albumFile, file1]);
|
||||
|
@ -99,16 +94,7 @@ Future<void> _remove1OfNFiles() async {
|
|||
final fileItems = util.AlbumBuilder.fileItemsOf(album);
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[1]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[1]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[2]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[2]));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
final fileRepo = MockFileMemoryRepo([albumFile, ...files]);
|
||||
|
@ -159,16 +145,7 @@ Future<void> _removeLatestOfNFiles() async {
|
|||
final fileItems = util.AlbumBuilder.fileItemsOf(album);
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[1]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[1]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[2]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[2]));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
final fileRepo = MockFileMemoryRepo([albumFile, ...files]);
|
||||
|
@ -216,16 +193,7 @@ Future<void> _removeManualCoverFile() async {
|
|||
final fileItems = util.AlbumBuilder.fileItemsOf(album);
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[1]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[1]));
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[2]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[2]));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareRepo();
|
||||
final fileRepo = MockFileMemoryRepo([albumFile, ...files]);
|
||||
|
@ -270,12 +238,7 @@ Future<void> _removeFromSharedAlbumOwned() async {
|
|||
final fileItem1 = util.AlbumBuilder.fileItemsOf(album)[0];
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file1));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: albumFile, shareWith: "user1"),
|
||||
|
@ -298,6 +261,7 @@ Future<void> _removeFromSharedAlbumOwned() async {
|
|||
/// unchanged
|
||||
Future<void> _removeFromSharedAlbumOwnedWithOtherShare() async {
|
||||
final account = util.buildAccount();
|
||||
final user1Account = util.buildAccount(username: "user1");
|
||||
final files = (util.FilesBuilder(initialFileId: 1)
|
||||
..addJpeg("user1/test1.jpg", ownerId: "user1"))
|
||||
.build();
|
||||
|
@ -310,12 +274,7 @@ Future<void> _removeFromSharedAlbumOwnedWithOtherShare() async {
|
|||
final fileItem1 = util.AlbumBuilder.fileItemsOf(album)[0];
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file1));
|
||||
});
|
||||
await util.fillAppDb(appDb, user1Account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: albumFile, shareWith: "user1"),
|
||||
|
@ -359,12 +318,7 @@ Future<void> _removeFromSharedAlbumOwnedLeaveExtraShare() async {
|
|||
final fileItem1 = util.AlbumBuilder.fileItemsOf(album)[0];
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file1));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: albumFile, shareWith: "user1"),
|
||||
|
@ -406,12 +360,7 @@ Future<void> _removeFromSharedAlbumOwnedFileInOtherAlbum() async {
|
|||
final album1File = album1.albumFile!;
|
||||
final album2File = album2.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, files[0]).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, files[0]));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album1, album2]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(id: "0", file: album1File, shareWith: "user1"),
|
||||
|
@ -449,12 +398,7 @@ Future<void> _removeFromSharedAlbumNotOwned() async {
|
|||
final fileItem1 = util.AlbumBuilder.fileItemsOf(album)[0];
|
||||
final albumFile = album.albumFile!;
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction = db.transaction(AppDb.fileDbStoreName, idbModeReadWrite);
|
||||
final store = transaction.objectStore(AppDb.fileDbStoreName);
|
||||
await store.put(AppDbFileDbEntry.fromFile(account, file1).toJson(),
|
||||
AppDbFileDbEntry.toPrimaryKey(account, file1));
|
||||
});
|
||||
await util.fillAppDb(appDb, account, files);
|
||||
final albumRepo = MockAlbumMemoryRepo([album]);
|
||||
final shareRepo = MockShareMemoryRepo([
|
||||
util.buildShare(
|
||||
|
|
Loading…
Reference in a new issue