From af6189d436587c2855af6997f6627735bdb33205 Mon Sep 17 00:00:00 2001 From: "Guilherme C. Matuella" Date: Fri, 26 Mar 2021 14:47:58 -0300 Subject: [PATCH] Exposes core private functionality in data layer, while annotating with @visibleForTesting --- lib/data/database_repository.dart | 4 +++- lib/data/sembast_database.dart | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/data/database_repository.dart b/lib/data/database_repository.dart index c43dbf70..ba59c244 100644 --- a/lib/data/database_repository.dart +++ b/lib/data/database_repository.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; +import 'package:meta/meta.dart'; import 'package:sembast/sembast.dart'; /// Handles the local persistence to the database @@ -139,7 +140,8 @@ class DatabaseRepositoryImpl implements DatabaseRepository { } } -extension on DatabaseStore { +extension StoreKeys on DatabaseStore { + @visibleForTesting String get key { switch (this) { case DatabaseStore.decks: diff --git a/lib/data/sembast_database.dart b/lib/data/sembast_database.dart index 5cb81867..101c52bb 100644 --- a/lib/data/sembast_database.dart +++ b/lib/data/sembast_database.dart @@ -9,7 +9,7 @@ import 'package:sembast/sembast_io.dart'; const _schemaVersion = 1; const _dbName = 'memo_sembast.db'; -/// Opens this application's [Database], creating a new one if non-existing +/// Opens this application's [Database], creating a new one if nonexistent Future openDatabase() async { final dir = await getApplicationDocumentsDirectory(); // Make sure that the application documents directory exists @@ -17,14 +17,11 @@ Future openDatabase() async { final dbPath = path.join(dir.path, _dbName); - return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: _applyMigrations); + return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: applyMigrations); } -Future _applyMigrations(Database db, int oldVersion, int newVersion) async { - if (oldVersion == newVersion) { - return SynchronousFuture(null); - } - +@visibleForTesting +Future applyMigrations(Database db, int oldVersion, int newVersion) async { // Call the necessary migrations in order }