mirror of
https://github.com/immich-app/immich
synced 2026-08-22 13:13:05 +00:00
refactor: mobile tag and download action Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
73 lines
2.5 KiB
Dart
73 lines
2.5 KiB
Dart
import 'package:drift/drift.dart' as drift;
|
|
import 'package:drift/native.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:immich_mobile/domain/services/store.service.dart';
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
|
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
|
import 'package:immich_mobile/infrastructure/repositories/store.repository.dart';
|
|
import 'package:immich_mobile/services/action.service.dart';
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import '../infrastructure/repository.mock.dart';
|
|
import '../repository.mocks.dart';
|
|
|
|
void main() {
|
|
late ActionService sut;
|
|
|
|
late MockAssetApiRepository assetApiRepository;
|
|
late MockRemoteAssetRepository remoteAssetRepository;
|
|
|
|
late Drift db;
|
|
|
|
setUpAll(() async {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
|
|
|
db = Drift(drift.DatabaseConnection(NativeDatabase.memory(), closeStreamsSynchronously: true));
|
|
await StoreService.init(storeRepository: DriftStoreRepository(db));
|
|
});
|
|
|
|
tearDownAll(() async {
|
|
debugDefaultTargetPlatformOverride = null;
|
|
await Store.clear();
|
|
await db.close();
|
|
});
|
|
|
|
setUp(() {
|
|
assetApiRepository = MockAssetApiRepository();
|
|
remoteAssetRepository = MockRemoteAssetRepository();
|
|
|
|
sut = ActionService(assetApiRepository, remoteAssetRepository);
|
|
});
|
|
|
|
tearDown(() async {
|
|
await Store.clear();
|
|
});
|
|
|
|
group('ActionService.updateRating', () {
|
|
const assetId = 'asset_id_1';
|
|
|
|
test('calls both repositories with the given rating', () async {
|
|
when(() => assetApiRepository.updateRating(assetId, 3)).thenAnswer((_) async {});
|
|
when(() => remoteAssetRepository.updateRating(assetId, 3)).thenAnswer((_) async {});
|
|
|
|
final result = await sut.updateRating(assetId, 3);
|
|
|
|
expect(result, isTrue);
|
|
verify(() => assetApiRepository.updateRating(assetId, 3)).called(1);
|
|
verify(() => remoteAssetRepository.updateRating(assetId, 3)).called(1);
|
|
});
|
|
|
|
test('calls both repositories with null to clear rating', () async {
|
|
when(() => assetApiRepository.updateRating(assetId, null)).thenAnswer((_) async {});
|
|
when(() => remoteAssetRepository.updateRating(assetId, null)).thenAnswer((_) async {});
|
|
|
|
final result = await sut.updateRating(assetId, null);
|
|
|
|
expect(result, isTrue);
|
|
verify(() => assetApiRepository.updateRating(assetId, null)).called(1);
|
|
verify(() => remoteAssetRepository.updateRating(assetId, null)).called(1);
|
|
});
|
|
});
|
|
}
|