Skip to content

Commit

Permalink
[DI] Remove test env
Browse files Browse the repository at this point in the history
  • Loading branch information
proninyaroslav committed Sep 9, 2024
1 parent 12fdc7f commit fa69fc1
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 166 deletions.
1 change: 0 additions & 1 deletion lib/core/crash_report/crash_report_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class DevCrashReportBuilder extends CrashReportBuilderImpl {
String get _email => '[email protected]';
}

@Injectable(as: CrashReportBuilder, env: [Env.test])
class TestCrashReportBuilder extends DevCrashReportBuilder {
TestCrashReportBuilder(
super.platform,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/model/request_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RequestFactoryImpl implements RequestFactory {
_mapServiceToBuilder(info: info, authData: authData);
}

@Injectable(as: RequestFactory, env: [Env.dev, Env.test])
@Injectable(as: RequestFactory, env: [Env.dev])
class DevRequestFactoryImpl implements RequestFactory {
@override
RequestBuilder builderOf({
Expand Down
2 changes: 1 addition & 1 deletion lib/core/work_manager/work_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class WorkManagerImpl extends _WorkManagerImpl {
);
}

@Singleton(as: WorkManager, env: [Env.dev, Env.test])
@Singleton(as: WorkManager, env: [Env.dev])
class DebugWorkManagerImpl extends _WorkManagerImpl {
DebugWorkManagerImpl(
WorkManagerRepository repo,
Expand Down
8 changes: 1 addition & 7 deletions lib/di/app_database_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ import 'dart:async';

import 'package:injectable/injectable.dart';
import 'package:libretrack/core/storage/database.dart';
import 'package:libretrack/env.dart';

@module
abstract class AppDatabaseModule {
@Singleton(env: [Env.prod, Env.dev])
@singleton
@preResolve
Future<AppDatabase> get db async => $FloorAppDatabase
.databaseBuilder('libretrack.db')
.addMigrations(migrations)
.build();

@Singleton(env: [Env.test])
@preResolve
Future<AppDatabase> get inMemoryDb async =>
$FloorAppDatabase.inMemoryDatabaseBuilder().build();
}
7 changes: 1 addition & 6 deletions lib/di/flutter_secure_storage_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:injectable/injectable.dart';
import 'package:libretrack/core/storage/service_auth_storage.dart';
import 'package:libretrack/env.dart';

@module
abstract class FlutterSecureStorageModule {
@Injectable(env: [Env.prod, Env.dev])
@injectable
FlutterSecureStorage get storage => const FlutterSecureStorage();

@Injectable(env: [Env.test])
FlutterSecureStorage get testStorage => TestFlutterSecureStorage();
}
19 changes: 2 additions & 17 deletions lib/di/shared_preferences_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
// along with LibreTrack. If not, see <http://www.gnu.org/licenses/>.

import 'package:injectable/injectable.dart';
import 'package:libretrack/core/settings/settings.dart';
import 'package:libretrack/core/settings/shared_pref_migrator.dart';
import 'package:libretrack/env.dart';
import 'package:shared_preferences/shared_preferences.dart';

@module
abstract class SharedPreferencesModule {
@Singleton(env: [Env.prod, Env.dev])
@singleton
@preResolve
Future<SharedPreferences> get prefOld async =>
SharedPreferences.getInstance();

@Singleton(env: [Env.prod, Env.dev])
@singleton
@preResolve
Future<SharedPreferencesAsync> pref(SharedPreferences prefOld) async {
final pref = SharedPreferencesAsync();
Expand All @@ -41,17 +39,4 @@ abstract class SharedPreferencesModule {

return pref;
}

@Singleton(env: [Env.test])
@preResolve
Future<SharedPreferencesAsync> get testPref async =>
TestSharedPreferencesAsync();

@Singleton(env: [Env.test])
@preResolve
Future<SharedPreferences> get testOldPref async {
// ignore: invalid_use_of_visible_for_testing_member
SharedPreferences.setMockInitialValues({});
return SharedPreferences.getInstance();
}
}
1 change: 0 additions & 1 deletion lib/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
abstract class Env {
static const String prod = 'prod';
static const String dev = 'dev';
static const String test = 'test';
}
150 changes: 50 additions & 100 deletions lib/injector.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions test/crash_report/crash_report_id_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:libretrack/core/crash_report/crash_report_id_generator.dart';
import 'package:libretrack/core/crash_report/crash_report_manager.dart';
import 'package:libretrack/env.dart';
import 'package:libretrack/injector.dart';

void main() {
group('Crash report ID generator |', () {
late CrashReportIdGenerator generator;

setUpAll(() async {
await initInjector(Env.test);
generator = getIt<CrashReportIdGenerator>();
generator = CrashReportIdGeneratorImpl();
});

test('Random', () {
Expand Down
Loading

0 comments on commit fa69fc1

Please sign in to comment.