mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Update tests
This commit is contained in:
parent
c8ad689a52
commit
19b89cb4e7
2 changed files with 90 additions and 1 deletions
|
@ -100,7 +100,7 @@ class MockAppDb implements AppDb {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<T> use<T>(FutureOr<T> Function(Database) fn) async {
|
||||
Future<T> use<T>(FutureOr<T> Function(Database db) fn) async {
|
||||
final db = await _dbFactory.open(
|
||||
"test.db",
|
||||
version: 1,
|
||||
|
|
89
test/use_case/db_compat/v5_test.dart
Normal file
89
test/use_case/db_compat/v5_test.dart
Normal file
|
@ -0,0 +1,89 @@
|
|||
import 'package:idb_shim/idb_client.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/use_case/db_compat/v5.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../mock_type.dart';
|
||||
import '../../test_util.dart' as util;
|
||||
|
||||
void main() {
|
||||
group("DbCompatV5", () {
|
||||
group("isNeedMigration", () {
|
||||
test("w/ meta entry == false", () async {
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction =
|
||||
db.transaction(AppDb.metaStoreName, idbModeReadWrite);
|
||||
final metaStore = transaction.objectStore(AppDb.metaStoreName);
|
||||
const entry = AppDbMetaEntryDbCompatV5(false);
|
||||
await metaStore.put(entry.toEntry().toJson());
|
||||
});
|
||||
|
||||
expect(await DbCompatV5.isNeedMigration(appDb), true);
|
||||
});
|
||||
|
||||
test("w/ meta entry == true", () async {
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction =
|
||||
db.transaction(AppDb.metaStoreName, idbModeReadWrite);
|
||||
final metaStore = transaction.objectStore(AppDb.metaStoreName);
|
||||
const entry = AppDbMetaEntryDbCompatV5(true);
|
||||
await metaStore.put(entry.toEntry().toJson());
|
||||
});
|
||||
|
||||
expect(await DbCompatV5.isNeedMigration(appDb), false);
|
||||
});
|
||||
|
||||
test("w/o meta entry", () async {
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction =
|
||||
db.transaction(AppDb.metaStoreName, idbModeReadWrite);
|
||||
final metaStore = transaction.objectStore(AppDb.metaStoreName);
|
||||
const entry = AppDbMetaEntryDbCompatV5(true);
|
||||
await metaStore.put(entry.toEntry().toJson());
|
||||
});
|
||||
|
||||
expect(await DbCompatV5.isNeedMigration(appDb), false);
|
||||
});
|
||||
});
|
||||
|
||||
test("migrate", () async {
|
||||
final account = util.buildAccount();
|
||||
final files = (util.FilesBuilder()
|
||||
..addJpeg(
|
||||
"admin/test1.jpg",
|
||||
lastModified: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
))
|
||||
.build();
|
||||
final appDb = MockAppDb();
|
||||
await appDb.use((db) async {
|
||||
final transaction =
|
||||
db.transaction(AppDb.file2StoreName, idbModeReadWrite);
|
||||
final fileStore = transaction.objectStore(AppDb.file2StoreName);
|
||||
await fileStore.put({
|
||||
"server": account.url,
|
||||
"userId": account.username.toCaseInsensitiveString(),
|
||||
"strippedPath": files[0].strippedPathWithEmpty,
|
||||
"file": files[0].toJson(),
|
||||
}, "${account.url}/${account.username.toCaseInsensitiveString()}/${files[0].fileId}");
|
||||
});
|
||||
await DbCompatV5.migrate(appDb);
|
||||
|
||||
final objs =
|
||||
await util.listAppDb(appDb, AppDb.file2StoreName, (item) => item);
|
||||
expect(objs, [
|
||||
{
|
||||
"server": account.url,
|
||||
"userId": account.username.toCaseInsensitiveString(),
|
||||
"strippedPath": files[0].strippedPathWithEmpty,
|
||||
"dateTimeEpochMs": 1577934245000,
|
||||
"file": files[0].toJson(),
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue