mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-22 06:59:21 +01:00
Fix broken tests
This commit is contained in:
parent
3e5dc3fedf
commit
6778750d51
3 changed files with 337 additions and 301 deletions
|
@ -1,167 +1,169 @@
|
||||||
// import 'package:drift/drift.dart' as sql;
|
import 'package:drift/drift.dart' as sql;
|
||||||
// import 'package:nc_photos/di_container.dart';
|
import 'package:nc_photos/db/entity_converter.dart';
|
||||||
// import 'package:nc_photos/entity/face_recognition_person.dart';
|
import 'package:nc_photos/di_container.dart';
|
||||||
// import 'package:nc_photos/entity/face_recognition_person/data_source.dart';
|
import 'package:nc_photos/entity/face_recognition_person.dart';
|
||||||
// import 'package:nc_photos/entity/face_recognition_person/repo.dart';
|
import 'package:nc_photos/entity/face_recognition_person/data_source.dart';
|
||||||
// import 'package:np_db_sqlite/np_db_sqlite_compat.dart' as compat;
|
import 'package:nc_photos/entity/face_recognition_person/repo.dart';
|
||||||
// import 'package:nc_photos/entity/sqlite/type_converter.dart';
|
import 'package:nc_photos/use_case/face_recognition_person/sync_face_recognition_person.dart';
|
||||||
// import 'package:nc_photos/use_case/face_recognition_person/sync_face_recognition_person.dart';
|
import 'package:np_db/np_db.dart';
|
||||||
// import 'package:test/test.dart';
|
import 'package:np_db_sqlite/np_db_sqlite_compat.dart' as compat;
|
||||||
// import 'package:tuple/tuple.dart';
|
import 'package:test/test.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
// import '../../mock_type.dart';
|
import '../../mock_type.dart';
|
||||||
// import '../../test_util.dart' as util;
|
import '../../test_util.dart' as util;
|
||||||
|
|
||||||
// void main() {
|
void main() {
|
||||||
// group("SyncFaceRecognitionPerson", () {
|
group("SyncFaceRecognitionPerson", () {
|
||||||
// test("new", _new);
|
test("new", _new);
|
||||||
// test("remove", _remove);
|
test("remove", _remove);
|
||||||
// test("update", _update);
|
test("update", _update);
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are new persons
|
/// Sync with remote where there are new persons
|
||||||
// ///
|
///
|
||||||
// /// Remote: [test1, test2, test3]
|
/// Remote: [test1, test2, test3]
|
||||||
// /// Local: [test1]
|
/// Local: [test1]
|
||||||
// /// Expect: [test1, test2, test3]
|
/// Expect: [test1, test2, test3]
|
||||||
// Future<void> _new() async {
|
Future<void> _new() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
||||||
// account.id: [
|
account.id: [
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// const FaceRecognitionPerson(name: "test2", thumbFaceId: 2, count: 10),
|
const FaceRecognitionPerson(name: "test2", thumbFaceId: 2, count: 10),
|
||||||
// const FaceRecognitionPerson(name: "test3", thumbFaceId: 3, count: 100),
|
const FaceRecognitionPerson(name: "test3", thumbFaceId: 3, count: 100),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
||||||
// FaceRecognitionPersonSqliteDbDataSource(c.sqliteDb));
|
FaceRecognitionPersonSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insert(
|
batch.insert(
|
||||||
// c.sqliteDb.faceRecognitionPersons,
|
c.sqliteDb.faceRecognitionPersons,
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// );
|
);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// await SyncFaceRecognitionPerson(c)(account);
|
await SyncFaceRecognitionPerson(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbPersons(c.sqliteDb),
|
await _listSqliteDbPersons(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.userId.toCaseInsensitiveString(): {
|
account.userId.toCaseInsensitiveString(): {
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const DbFaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// const FaceRecognitionPerson(name: "test2", thumbFaceId: 2, count: 10),
|
const DbFaceRecognitionPerson(name: "test2", thumbFaceId: 2, count: 10),
|
||||||
// const FaceRecognitionPerson(name: "test3", thumbFaceId: 3, count: 100),
|
const DbFaceRecognitionPerson(
|
||||||
// },
|
name: "test3", thumbFaceId: 3, count: 100),
|
||||||
// },
|
},
|
||||||
// );
|
},
|
||||||
// }
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are removed persons
|
/// Sync with remote where there are removed persons
|
||||||
// ///
|
///
|
||||||
// /// Remote: [test1]
|
/// Remote: [test1]
|
||||||
// /// Local: [test1, test2, test3]
|
/// Local: [test1, test2, test3]
|
||||||
// /// Expect: [test1]
|
/// Expect: [test1]
|
||||||
// Future<void> _remove() async {
|
Future<void> _remove() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
||||||
// account.id: [
|
account.id: [
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
||||||
// FaceRecognitionPersonSqliteDbDataSource(c.sqliteDb));
|
FaceRecognitionPersonSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insertAll(c.sqliteDb.faceRecognitionPersons, [
|
batch.insertAll(c.sqliteDb.faceRecognitionPersons, [
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test2", thumbFaceId: 2, count: 10),
|
account: 1, name: "test2", thumbFaceId: 2, count: 10),
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test3", thumbFaceId: 3, count: 100),
|
account: 1, name: "test3", thumbFaceId: 3, count: 100),
|
||||||
// ]);
|
]);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// await SyncFaceRecognitionPerson(c)(account);
|
await SyncFaceRecognitionPerson(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbPersons(c.sqliteDb),
|
await _listSqliteDbPersons(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.userId.toCaseInsensitiveString(): {
|
account.userId.toCaseInsensitiveString(): {
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const DbFaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are updated persons (i.e, same name, different
|
/// Sync with remote where there are updated persons (i.e, same name, different
|
||||||
// /// properties)
|
/// properties)
|
||||||
// ///
|
///
|
||||||
// /// Remote: [test1, test2 (face: 3)]
|
/// Remote: [test1, test2 (face: 3)]
|
||||||
// /// Local: [test1, test2 (face: 2)]
|
/// Local: [test1, test2 (face: 2)]
|
||||||
// /// Expect: [test1, test2 (face: 3)]
|
/// Expect: [test1, test2 (face: 3)]
|
||||||
// Future<void> _update() async {
|
Future<void> _update() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
c.faceRecognitionPersonRepoRemote = MockFaceRecognitionPersonMemoryRepo({
|
||||||
// account.id: [
|
account.id: [
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// const FaceRecognitionPerson(name: "test2", thumbFaceId: 3, count: 10),
|
const FaceRecognitionPerson(name: "test2", thumbFaceId: 3, count: 10),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
c.faceRecognitionPersonRepoLocal = BasicFaceRecognitionPersonRepo(
|
||||||
// FaceRecognitionPersonSqliteDbDataSource(c.sqliteDb));
|
FaceRecognitionPersonSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insertAll(c.sqliteDb.faceRecognitionPersons, [
|
batch.insertAll(c.sqliteDb.faceRecognitionPersons, [
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
account: 1, name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// sql.FaceRecognitionPersonsCompanion.insert(
|
compat.FaceRecognitionPersonsCompanion.insert(
|
||||||
// account: 1, name: "test2", thumbFaceId: 2, count: 10),
|
account: 1, name: "test2", thumbFaceId: 2, count: 10),
|
||||||
// ]);
|
]);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// await SyncFaceRecognitionPerson(c)(account);
|
await SyncFaceRecognitionPerson(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbPersons(c.sqliteDb),
|
await _listSqliteDbPersons(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.userId.toCaseInsensitiveString(): {
|
account.userId.toCaseInsensitiveString(): {
|
||||||
// const FaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
const DbFaceRecognitionPerson(name: "test1", thumbFaceId: 1, count: 1),
|
||||||
// const FaceRecognitionPerson(name: "test2", thumbFaceId: 3, count: 10),
|
const DbFaceRecognitionPerson(name: "test2", thumbFaceId: 3, count: 10),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Future<Map<String, Set<FaceRecognitionPerson>>> _listSqliteDbPersons(
|
Future<Map<String, Set<DbFaceRecognitionPerson>>> _listSqliteDbPersons(
|
||||||
// sql.SqliteDb db) async {
|
compat.SqliteDb db) async {
|
||||||
// final query = db.select(db.faceRecognitionPersons).join([
|
final query = db.select(db.faceRecognitionPersons).join([
|
||||||
// sql.innerJoin(db.accounts,
|
sql.innerJoin(db.accounts,
|
||||||
// db.accounts.rowId.equalsExp(db.faceRecognitionPersons.account)),
|
db.accounts.rowId.equalsExp(db.faceRecognitionPersons.account)),
|
||||||
// ]);
|
]);
|
||||||
// final result = await query
|
final result = await query
|
||||||
// .map((r) => Tuple2(
|
.map((r) => Tuple2(
|
||||||
// r.readTable(db.accounts), r.readTable(db.faceRecognitionPersons)))
|
r.readTable(db.accounts), r.readTable(db.faceRecognitionPersons)))
|
||||||
// .get();
|
.get();
|
||||||
// final product = <String, Set<FaceRecognitionPerson>>{};
|
final product = <String, Set<DbFaceRecognitionPerson>>{};
|
||||||
// for (final r in result) {
|
for (final r in result) {
|
||||||
// (product[r.item1.userId] ??= {})
|
(product[r.item1.userId] ??= {})
|
||||||
// .add(SqliteFaceRecognitionPersonConverter.fromSql(r.item2));
|
.add(compat.FaceRecognitionPersonConverter.fromSql(r.item2));
|
||||||
// }
|
}
|
||||||
// return product;
|
return product;
|
||||||
// }
|
}
|
||||||
|
|
|
@ -1,152 +1,185 @@
|
||||||
// import 'package:drift/drift.dart' as sql;
|
import 'package:drift/drift.dart' as sql;
|
||||||
// import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
// import 'package:nc_photos/di_container.dart';
|
import 'package:nc_photos/db/entity_converter.dart';
|
||||||
// import 'package:np_db_sqlite/np_db_sqlite_compat.dart' as compat;
|
import 'package:nc_photos/di_container.dart';
|
||||||
// import 'package:nc_photos/entity/sqlite/type_converter.dart';
|
import 'package:nc_photos/entity/tag.dart';
|
||||||
// import 'package:nc_photos/entity/tag.dart';
|
import 'package:nc_photos/entity/tag/data_source.dart';
|
||||||
// import 'package:nc_photos/entity/tag/data_source.dart';
|
import 'package:nc_photos/use_case/sync_tag.dart';
|
||||||
// import 'package:nc_photos/use_case/sync_tag.dart';
|
import 'package:np_db/np_db.dart';
|
||||||
// import 'package:test/test.dart';
|
import 'package:np_db_sqlite/np_db_sqlite_compat.dart' as compat;
|
||||||
// import 'package:tuple/tuple.dart';
|
import 'package:test/test.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
// import '../mock_type.dart';
|
import '../mock_type.dart';
|
||||||
// import '../test_util.dart' as util;
|
import '../test_util.dart' as util;
|
||||||
|
|
||||||
// void main() {
|
void main() {
|
||||||
// group("SyncTag", () {
|
group("SyncTag", () {
|
||||||
// test("new", _new);
|
test("new", _new);
|
||||||
// test("remove", _remove);
|
test("remove", _remove);
|
||||||
// test("update", _update);
|
test("update", _update);
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are new tags
|
/// Sync with remote where there are new tags
|
||||||
// ///
|
///
|
||||||
// /// Remote: [tag0, tag1, tag2]
|
/// Remote: [tag0, tag1, tag2]
|
||||||
// /// Local: [tag0]
|
/// Local: [tag0]
|
||||||
// /// Expect: [tag0, tag1, tag2]
|
/// Expect: [tag0, tag1, tag2]
|
||||||
// Future<void> _new() async {
|
Future<void> _new() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.tagRepoRemote = MockTagMemoryRepo({
|
c.tagRepoRemote = MockTagMemoryRepo({
|
||||||
// account.url: [
|
account.url: [
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const Tag(id: 10, displayName: "tag0"),
|
||||||
// const Tag(id: 11, displayName: "tag1"),
|
const Tag(id: 11, displayName: "tag1"),
|
||||||
// const Tag(id: 12, displayName: "tag2"),
|
const Tag(id: 12, displayName: "tag2"),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.sqliteDb));
|
c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insert(c.sqliteDb.tags,
|
batch.insert(
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"));
|
c.sqliteDb.tags,
|
||||||
// });
|
compat.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"),
|
||||||
// });
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// await SyncTag(c)(account);
|
await SyncTag(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbTags(c.sqliteDb),
|
await _listSqliteDbTags(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.url: {
|
account.url: {
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const DbTag(
|
||||||
// const Tag(id: 11, displayName: "tag1"),
|
id: 10,
|
||||||
// const Tag(id: 12, displayName: "tag2"),
|
displayName: "tag0",
|
||||||
// },
|
userVisible: null,
|
||||||
// },
|
userAssignable: null,
|
||||||
// );
|
),
|
||||||
// }
|
const DbTag(
|
||||||
|
id: 11,
|
||||||
|
displayName: "tag1",
|
||||||
|
userVisible: null,
|
||||||
|
userAssignable: null,
|
||||||
|
),
|
||||||
|
const DbTag(
|
||||||
|
id: 12,
|
||||||
|
displayName: "tag2",
|
||||||
|
userVisible: null,
|
||||||
|
userAssignable: null,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are removed tags
|
/// Sync with remote where there are removed tags
|
||||||
// ///
|
///
|
||||||
// /// Remote: [tag0]
|
/// Remote: [tag0]
|
||||||
// /// Local: [tag0, tag1, tag2]
|
/// Local: [tag0, tag1, tag2]
|
||||||
// /// Expect: [tag0]
|
/// Expect: [tag0]
|
||||||
// Future<void> _remove() async {
|
Future<void> _remove() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.tagRepoRemote = MockTagMemoryRepo({
|
c.tagRepoRemote = MockTagMemoryRepo({
|
||||||
// account.url: [
|
account.url: [
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const Tag(id: 10, displayName: "tag0"),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.sqliteDb));
|
c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insertAll(c.sqliteDb.tags, [
|
batch.insertAll(c.sqliteDb.tags, [
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"),
|
compat.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"),
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 11, displayName: "tag1"),
|
compat.TagsCompanion.insert(server: 1, tagId: 11, displayName: "tag1"),
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 12, displayName: "tag2"),
|
compat.TagsCompanion.insert(server: 1, tagId: 12, displayName: "tag2"),
|
||||||
// ]);
|
]);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// await SyncTag(c)(account);
|
await SyncTag(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbTags(c.sqliteDb),
|
await _listSqliteDbTags(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.url: {
|
account.url: {
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const DbTag(
|
||||||
// },
|
id: 10,
|
||||||
// },
|
displayName: "tag0",
|
||||||
// );
|
userVisible: null,
|
||||||
// }
|
userAssignable: null,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /// Sync with remote where there are updated tags (i.e, same id, different
|
/// Sync with remote where there are updated tags (i.e, same id, different
|
||||||
// /// properties)
|
/// properties)
|
||||||
// ///
|
///
|
||||||
// /// Remote: [tag0, new tag1]
|
/// Remote: [tag0, new tag1]
|
||||||
// /// Local: [tag0, tag1]
|
/// Local: [tag0, tag1]
|
||||||
// /// Expect: [tag0, new tag1]
|
/// Expect: [tag0, new tag1]
|
||||||
// Future<void> _update() async {
|
Future<void> _update() async {
|
||||||
// final account = util.buildAccount();
|
final account = util.buildAccount();
|
||||||
// final c = DiContainer.late();
|
final c = DiContainer.late();
|
||||||
// c.sqliteDb = util.buildTestDb();
|
c.npDb = util.buildTestDb();
|
||||||
// addTearDown(() => c.sqliteDb.close());
|
addTearDown(() => c.sqliteDb.close());
|
||||||
// c.tagRepoRemote = MockTagMemoryRepo({
|
c.tagRepoRemote = MockTagMemoryRepo({
|
||||||
// account.url: [
|
account.url: [
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const Tag(id: 10, displayName: "tag0"),
|
||||||
// const Tag(id: 11, displayName: "new tag1"),
|
const Tag(id: 11, displayName: "new tag1"),
|
||||||
// ],
|
],
|
||||||
// });
|
});
|
||||||
// c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.sqliteDb));
|
c.tagRepoLocal = TagRepo(TagSqliteDbDataSource(c.npDb));
|
||||||
// await c.sqliteDb.transaction(() async {
|
await c.sqliteDb.transaction(() async {
|
||||||
// await c.sqliteDb.insertAccounts([account.toDb()]);
|
await c.sqliteDb.insertAccounts([account.toDb()]);
|
||||||
// await c.sqliteDb.batch((batch) {
|
await c.sqliteDb.batch((batch) {
|
||||||
// batch.insertAll(c.sqliteDb.tags, [
|
batch.insertAll(c.sqliteDb.tags, [
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"),
|
compat.TagsCompanion.insert(server: 1, tagId: 10, displayName: "tag0"),
|
||||||
// sql.TagsCompanion.insert(server: 1, tagId: 11, displayName: "tag1"),
|
compat.TagsCompanion.insert(server: 1, tagId: 11, displayName: "tag1"),
|
||||||
// ]);
|
]);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// await SyncTag(c)(account);
|
await SyncTag(c)(account);
|
||||||
// expect(
|
expect(
|
||||||
// await _listSqliteDbTags(c.sqliteDb),
|
await _listSqliteDbTags(c.sqliteDb),
|
||||||
// {
|
{
|
||||||
// account.url: {
|
account.url: {
|
||||||
// const Tag(id: 10, displayName: "tag0"),
|
const DbTag(
|
||||||
// const Tag(id: 11, displayName: "new tag1"),
|
id: 10,
|
||||||
// },
|
displayName: "tag0",
|
||||||
// },
|
userVisible: null,
|
||||||
// );
|
userAssignable: null,
|
||||||
// }
|
),
|
||||||
|
const DbTag(
|
||||||
|
id: 11,
|
||||||
|
displayName: "new tag1",
|
||||||
|
userVisible: null,
|
||||||
|
userAssignable: null,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Future<Map<String, Set<Tag>>> _listSqliteDbTags(sql.SqliteDb db) async {
|
Future<Map<String, Set<DbTag>>> _listSqliteDbTags(compat.SqliteDb db) async {
|
||||||
// final query = db.select(db.tags).join([
|
final query = db.select(db.tags).join([
|
||||||
// sql.innerJoin(db.servers, db.servers.rowId.equalsExp(db.tags.server)),
|
sql.innerJoin(db.servers, db.servers.rowId.equalsExp(db.tags.server)),
|
||||||
// ]);
|
]);
|
||||||
// final result = await query
|
final result = await query
|
||||||
// .map((r) => Tuple2(r.readTable(db.servers), r.readTable(db.tags)))
|
.map((r) => Tuple2(r.readTable(db.servers), r.readTable(db.tags)))
|
||||||
// .get();
|
.get();
|
||||||
// final product = <String, Set<Tag>>{};
|
final product = <String, Set<DbTag>>{};
|
||||||
// for (final r in result) {
|
for (final r in result) {
|
||||||
// (product[r.item1.address] ??= {}).add(SqliteTagConverter.fromSql(r.item2));
|
(product[r.item1.address] ??= {}).add(compat.TagConverter.fromSql(r.item2));
|
||||||
// }
|
}
|
||||||
// return product;
|
return product;
|
||||||
// }
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
library np_db_sqlite;
|
library np_db_sqlite;
|
||||||
|
|
||||||
|
export 'src/converter.dart';
|
||||||
export 'src/database.dart';
|
export 'src/database.dart';
|
||||||
export 'src/database_extension.dart';
|
export 'src/database_extension.dart';
|
||||||
|
|
Loading…
Reference in a new issue