refactor(mobile): encapsulate most access to photomanager in repository (#12754)

* refactor(mobile): encapsulate most access to photomanager in repository
This commit is contained in:
Fynn Petersen-Frey
2024-09-18 17:15:52 +02:00
committed by GitHub
parent 6740c67ed8
commit 6995cc2b38
45 changed files with 1205 additions and 500 deletions
@@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/entities/backup_album.entity.dart';
import 'package:immich_mobile/services/album.service.dart';
import 'package:mocktail/mocktail.dart';
import '../fixtures/album.stub.dart';
import '../repository.mocks.dart';
import '../service.mocks.dart';
@@ -14,6 +15,7 @@ void main() {
late MockAssetRepository assetRepository;
late MockUserRepository userRepository;
late MockBackupRepository backupRepository;
late MockAlbumMediaRepository albumMediaRepository;
setUp(() {
apiService = MockApiService();
@@ -23,6 +25,7 @@ void main() {
assetRepository = MockAssetRepository();
userRepository = MockUserRepository();
backupRepository = MockBackupRepository();
albumMediaRepository = MockAlbumMediaRepository();
sut = AlbumService(
apiService,
@@ -32,6 +35,7 @@ void main() {
assetRepository,
userRepository,
backupRepository,
albumMediaRepository,
);
});
@@ -48,5 +52,22 @@ void main() {
expect(result, false);
verify(() => syncService.removeAllLocalAlbumsAndAssets());
});
test('one selected albums, two on device', () async {
when(() => backupRepository.getIdsBySelection(BackupSelection.exclude))
.thenAnswer((_) async => []);
when(() => backupRepository.getIdsBySelection(BackupSelection.select))
.thenAnswer((_) async => [AlbumStub.oneAsset.localId!]);
when(() => albumMediaRepository.getAll())
.thenAnswer((_) async => [AlbumStub.oneAsset, AlbumStub.twoAsset]);
when(() => syncService.syncLocalAlbumAssetsToDb(any(), any()))
.thenAnswer((_) async => true);
final result = await sut.refreshDeviceAlbums();
expect(result, true);
verify(
() => syncService.syncLocalAlbumAssetsToDb([AlbumStub.oneAsset], null),
).called(1);
verifyNoMoreInteractions(syncService);
});
});
}