fix(data): race-safe DB open, graceful unknown types, explicit id error + fallback tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 11:18:56 +02:00
co-authored by Claude Opus 4.8
parent 51c6ef904d
commit 6885771081
3 changed files with 35 additions and 7 deletions
+21
View File
@@ -49,6 +49,13 @@ class FakeRemote implements PokemonRemoteDataSource {
}
}
class ThrowingRemote implements PokemonRemoteDataSource {
@override
Future<List<Pokemon>> getAll() async => throw Exception('network');
@override
Future<Pokemon> getById(int id) async => throw Exception('network');
}
void main() {
group('getById', () {
test('retourne le cache local sans appeler l\'API', () async {
@@ -103,4 +110,18 @@ void main() {
expect(list.length, 3);
});
});
group('repli sur erreur', () {
test('getById retourne null si l\'API échoue et le cache est vide', () async {
final repo = PokemonRepositoryImpl(remote: ThrowingRemote(), local: FakeLocal());
expect(await repo.getById(42), isNull);
});
test('getAll retourne le cache existant si la synchro API échoue', () async {
final local = FakeLocal({1: _mk(1)}); // cache incomplet -> tente l'API, qui échoue
final repo = PokemonRepositoryImpl(remote: ThrowingRemote(), local: local);
final list = await repo.getAll();
expect(list.length, 1); // repli sur le cache
});
});
}