chore: bump line length to 120 (#20191)
This commit is contained in:
@@ -54,28 +54,22 @@ void main() {
|
||||
|
||||
group('refreshDeviceAlbums', () {
|
||||
test('empty selection with one album in db', () async {
|
||||
when(() => backupRepository.getIdsBySelection(BackupSelection.exclude))
|
||||
.thenAnswer((_) async => []);
|
||||
when(() => backupRepository.getIdsBySelection(BackupSelection.select))
|
||||
.thenAnswer((_) async => []);
|
||||
when(() => backupRepository.getIdsBySelection(BackupSelection.exclude)).thenAnswer((_) async => []);
|
||||
when(() => backupRepository.getIdsBySelection(BackupSelection.select)).thenAnswer((_) async => []);
|
||||
when(() => albumMediaRepository.getAll()).thenAnswer((_) async => []);
|
||||
when(() => albumRepository.count(local: true)).thenAnswer((_) async => 1);
|
||||
when(() => syncService.removeAllLocalAlbumsAndAssets())
|
||||
.thenAnswer((_) async => true);
|
||||
when(() => syncService.removeAllLocalAlbumsAndAssets()).thenAnswer((_) async => true);
|
||||
final result = await sut.refreshDeviceAlbums();
|
||||
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.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);
|
||||
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(
|
||||
@@ -88,10 +82,8 @@ void main() {
|
||||
group('refreshRemoteAlbums', () {
|
||||
test('is working', () async {
|
||||
when(() => syncService.getUsersFromServer()).thenAnswer((_) async => []);
|
||||
when(() => syncService.syncUsersFromServer(any()))
|
||||
.thenAnswer((_) async => true);
|
||||
when(() => albumApiRepository.getAll(shared: true))
|
||||
.thenAnswer((_) async => [AlbumStub.sharedWithUser]);
|
||||
when(() => syncService.syncUsersFromServer(any())).thenAnswer((_) async => true);
|
||||
when(() => albumApiRepository.getAll(shared: true)).thenAnswer((_) async => [AlbumStub.sharedWithUser]);
|
||||
|
||||
when(() => albumApiRepository.getAll(shared: null))
|
||||
.thenAnswer((_) async => [AlbumStub.oneAsset, AlbumStub.twoAsset]);
|
||||
@@ -142,8 +134,7 @@ void main() {
|
||||
() => albumRepository.create(AlbumStub.oneAsset),
|
||||
).thenAnswer((_) async => AlbumStub.twoAsset);
|
||||
|
||||
final result =
|
||||
await sut.createAlbum("name", [AssetStub.image1], [UserStub.user1]);
|
||||
final result = await sut.createAlbum("name", [AssetStub.image1], [UserStub.user1]);
|
||||
expect(result, AlbumStub.twoAsset);
|
||||
verify(
|
||||
() => albumApiRepository.create(
|
||||
@@ -163,10 +154,7 @@ void main() {
|
||||
when(
|
||||
() => albumApiRepository.addAssets(AlbumStub.oneAsset.remoteId!, any()),
|
||||
).thenAnswer(
|
||||
(_) async => (
|
||||
added: [AssetStub.image2.remoteId!],
|
||||
duplicates: [AssetStub.image1.remoteId!]
|
||||
),
|
||||
(_) async => (added: [AssetStub.image2.remoteId!], duplicates: [AssetStub.image1.remoteId!]),
|
||||
);
|
||||
when(
|
||||
() => albumRepository.get(AlbumStub.oneAsset.id),
|
||||
@@ -198,8 +186,7 @@ void main() {
|
||||
group('addAdditionalUserToAlbum', () {
|
||||
test('one added', () async {
|
||||
when(
|
||||
() =>
|
||||
albumApiRepository.addUsers(AlbumStub.emptyAlbum.remoteId!, any()),
|
||||
() => albumApiRepository.addUsers(AlbumStub.emptyAlbum.remoteId!, any()),
|
||||
).thenAnswer(
|
||||
(_) async => AlbumStub.sharedWithUser,
|
||||
);
|
||||
|
||||
@@ -69,8 +69,7 @@ void main() {
|
||||
setUp(() {
|
||||
assetsApi = MockAssetsApi();
|
||||
when(() => apiService.assetsApi).thenReturn(assetsApi);
|
||||
when(() => assetsApi.updateAssets(any()))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(() => assetsApi.updateAssets(any())).thenAnswer((_) async => Future.value());
|
||||
});
|
||||
|
||||
test("asset is updated with DateTime", () async {
|
||||
@@ -79,11 +78,9 @@ void main() {
|
||||
await sut.changeDateTime(assets, dateTime.toIso8601String());
|
||||
|
||||
verify(() => assetsApi.updateAssets(any())).called(1);
|
||||
final upsertExifCallback =
|
||||
verify(() => syncService.upsertAssetsWithExif(captureAny()));
|
||||
final upsertExifCallback = verify(() => syncService.upsertAssetsWithExif(captureAny()));
|
||||
upsertExifCallback.called(1);
|
||||
final receivedAssets =
|
||||
upsertExifCallback.captured.firstOrNull as List<Object>? ?? [];
|
||||
final receivedAssets = upsertExifCallback.captured.firstOrNull as List<Object>? ?? [];
|
||||
final receivedDatetime = receivedAssets.cast<Asset>().map(
|
||||
(a) => a.exifInfo?.dateTimeOriginal ?? DateTime(0),
|
||||
);
|
||||
@@ -96,14 +93,11 @@ void main() {
|
||||
await sut.changeLocation(assets, latLng);
|
||||
|
||||
verify(() => assetsApi.updateAssets(any())).called(1);
|
||||
final upsertExifCallback =
|
||||
verify(() => syncService.upsertAssetsWithExif(captureAny()));
|
||||
final upsertExifCallback = verify(() => syncService.upsertAssetsWithExif(captureAny()));
|
||||
upsertExifCallback.called(1);
|
||||
final receivedAssets =
|
||||
upsertExifCallback.captured.firstOrNull as List<Object>? ?? [];
|
||||
final receivedAssets = upsertExifCallback.captured.firstOrNull as List<Object>? ?? [];
|
||||
final receivedCoords = receivedAssets.cast<Asset>().map(
|
||||
(a) =>
|
||||
LatLng(a.exifInfo?.latitude ?? 0, a.exifInfo?.longitude ?? 0),
|
||||
(a) => LatLng(a.exifInfo?.latitude ?? 0, a.exifInfo?.longitude ?? 0),
|
||||
);
|
||||
expect(receivedCoords.every((l) => l == latLng), isTrue);
|
||||
});
|
||||
|
||||
@@ -58,8 +58,7 @@ void main() {
|
||||
const testUrl = 'http://ip:2283';
|
||||
const resolvedUrl = 'http://ip:2283/api';
|
||||
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl))
|
||||
.thenAnswer((_) async => resolvedUrl);
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl)).thenAnswer((_) async => resolvedUrl);
|
||||
when(() => apiService.setDeviceInfoHeader()).thenAnswer((_) async => {});
|
||||
|
||||
final result = await sut.validateServerUrl(testUrl);
|
||||
@@ -74,8 +73,7 @@ void main() {
|
||||
const testUrl = 'https://immich.domain.com';
|
||||
const resolvedUrl = 'https://immich.domain.com/api';
|
||||
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl))
|
||||
.thenAnswer((_) async => resolvedUrl);
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl)).thenAnswer((_) async => resolvedUrl);
|
||||
when(() => apiService.setDeviceInfoHeader()).thenAnswer((_) async => {});
|
||||
|
||||
final result = await sut.validateServerUrl(testUrl);
|
||||
@@ -89,8 +87,7 @@ void main() {
|
||||
test('Should throw error on invalid URL', () async {
|
||||
const testUrl = 'invalid-url';
|
||||
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl))
|
||||
.thenThrow(Exception('Invalid URL'));
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl)).thenThrow(Exception('Invalid URL'));
|
||||
|
||||
expect(
|
||||
() async => await sut.validateServerUrl(testUrl),
|
||||
@@ -104,8 +101,7 @@ void main() {
|
||||
test('Should throw error on unreachable server', () async {
|
||||
const testUrl = 'https://unreachable.server';
|
||||
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl))
|
||||
.thenThrow(Exception('Server is not reachable'));
|
||||
when(() => apiService.resolveAndSetEndpoint(testUrl)).thenThrow(Exception('Server is not reachable'));
|
||||
|
||||
expect(
|
||||
() async => await sut.validateServerUrl(testUrl),
|
||||
@@ -121,8 +117,7 @@ void main() {
|
||||
test('Should logout user', () async {
|
||||
when(() => authApiRepository.logout()).thenAnswer((_) async => {});
|
||||
when(() => backgroundSyncManager.cancel()).thenAnswer((_) async => {});
|
||||
when(() => authRepository.clearLocalData())
|
||||
.thenAnswer((_) => Future.value(null));
|
||||
when(() => authRepository.clearLocalData()).thenAnswer((_) => Future.value(null));
|
||||
|
||||
await sut.logout();
|
||||
|
||||
@@ -132,11 +127,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('Should clear local data even on server error', () async {
|
||||
when(() => authApiRepository.logout())
|
||||
.thenThrow(Exception('Server error'));
|
||||
when(() => authApiRepository.logout()).thenThrow(Exception('Server error'));
|
||||
when(() => backgroundSyncManager.cancel()).thenAnswer((_) async => {});
|
||||
when(() => authRepository.clearLocalData())
|
||||
.thenAnswer((_) => Future.value(null));
|
||||
when(() => authRepository.clearLocalData()).thenAnswer((_) => Future.value(null));
|
||||
|
||||
await sut.logout();
|
||||
|
||||
@@ -148,13 +141,11 @@ void main() {
|
||||
|
||||
group('setOpenApiServiceEndpoint', () {
|
||||
setUp(() {
|
||||
when(() => networkService.getWifiName())
|
||||
.thenAnswer((_) async => 'TestWifi');
|
||||
when(() => networkService.getWifiName()).thenAnswer((_) async => 'TestWifi');
|
||||
});
|
||||
|
||||
test('Should return null if auto endpoint switching is disabled', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature())
|
||||
.thenReturn((false));
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn((false));
|
||||
|
||||
final result = await sut.setOpenApiServiceEndpoint();
|
||||
|
||||
@@ -166,8 +157,7 @@ void main() {
|
||||
test('Should set local connection if wifi name matches', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('TestWifi');
|
||||
when(() => authRepository.getLocalEndpoint())
|
||||
.thenReturn('http://local.endpoint');
|
||||
when(() => authRepository.getLocalEndpoint()).thenReturn('http://local.endpoint');
|
||||
when(() => apiService.resolveAndSetEndpoint('http://local.endpoint'))
|
||||
.thenAnswer((_) async => 'http://local.endpoint');
|
||||
|
||||
@@ -178,14 +168,12 @@ void main() {
|
||||
verify(() => networkService.getWifiName()).called(1);
|
||||
verify(() => authRepository.getPreferredWifiName()).called(1);
|
||||
verify(() => authRepository.getLocalEndpoint()).called(1);
|
||||
verify(() => apiService.resolveAndSetEndpoint('http://local.endpoint'))
|
||||
.called(1);
|
||||
verify(() => apiService.resolveAndSetEndpoint('http://local.endpoint')).called(1);
|
||||
});
|
||||
|
||||
test('Should set external endpoint if wifi name not matching', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName())
|
||||
.thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getExternalEndpointList()).thenReturn([
|
||||
const AuxilaryEndpoint(
|
||||
url: 'https://external.endpoint',
|
||||
@@ -208,11 +196,9 @@ void main() {
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('Should set second external endpoint if the first throw any error',
|
||||
() async {
|
||||
test('Should set second external endpoint if the first throw any error', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName())
|
||||
.thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getExternalEndpointList()).thenReturn([
|
||||
const AuxilaryEndpoint(
|
||||
url: 'https://external.endpoint',
|
||||
@@ -243,11 +229,9 @@ void main() {
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('Should set second external endpoint if the first throw ApiException',
|
||||
() async {
|
||||
test('Should set second external endpoint if the first throw ApiException', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName())
|
||||
.thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getExternalEndpointList()).thenReturn([
|
||||
const AuxilaryEndpoint(
|
||||
url: 'https://external.endpoint',
|
||||
@@ -281,8 +265,7 @@ void main() {
|
||||
test('Should handle error when setting local connection', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('TestWifi');
|
||||
when(() => authRepository.getLocalEndpoint())
|
||||
.thenReturn('http://local.endpoint');
|
||||
when(() => authRepository.getLocalEndpoint()).thenReturn('http://local.endpoint');
|
||||
when(() => apiService.resolveAndSetEndpoint('http://local.endpoint'))
|
||||
.thenThrow(Exception('Local endpoint error'));
|
||||
|
||||
@@ -293,14 +276,12 @@ void main() {
|
||||
verify(() => networkService.getWifiName()).called(1);
|
||||
verify(() => authRepository.getPreferredWifiName()).called(1);
|
||||
verify(() => authRepository.getLocalEndpoint()).called(1);
|
||||
verify(() => apiService.resolveAndSetEndpoint('http://local.endpoint'))
|
||||
.called(1);
|
||||
verify(() => apiService.resolveAndSetEndpoint('http://local.endpoint')).called(1);
|
||||
});
|
||||
|
||||
test('Should handle error when setting external connection', () async {
|
||||
when(() => authRepository.getEndpointSwitchingFeature()).thenReturn(true);
|
||||
when(() => authRepository.getPreferredWifiName())
|
||||
.thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getPreferredWifiName()).thenReturn('DifferentWifi');
|
||||
when(() => authRepository.getExternalEndpointList()).thenReturn([
|
||||
const AuxilaryEndpoint(
|
||||
url: 'https://external.endpoint',
|
||||
|
||||
@@ -21,8 +21,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('fillAlbumWithDatabaseEntities', () {
|
||||
test('remote album with owner, thumbnail, sharedUsers and assets',
|
||||
() async {
|
||||
test('remote album with owner, thumbnail, sharedUsers and assets', () async {
|
||||
final Album album = Album(
|
||||
name: "album-with-two-assets-and-two-users",
|
||||
localId: "album-with-two-assets-and-two-users-local",
|
||||
@@ -41,19 +40,14 @@ void main() {
|
||||
[User.fromDto(UserStub.admin), User.fromDto(UserStub.admin)],
|
||||
);
|
||||
|
||||
when(() => userRepository.getByUserId(any()))
|
||||
.thenAnswer((_) async => UserStub.admin);
|
||||
when(() => userRepository.getByUserId(any()))
|
||||
.thenAnswer((_) async => UserStub.admin);
|
||||
when(() => userRepository.getByUserId(any())).thenAnswer((_) async => UserStub.admin);
|
||||
when(() => userRepository.getByUserId(any())).thenAnswer((_) async => UserStub.admin);
|
||||
|
||||
when(() => assetRepository.getByRemoteId(AssetStub.image1.remoteId!))
|
||||
.thenAnswer((_) async => AssetStub.image1);
|
||||
when(() => assetRepository.getByRemoteId(AssetStub.image1.remoteId!)).thenAnswer((_) async => AssetStub.image1);
|
||||
|
||||
when(() => userRepository.getByUserIds(any()))
|
||||
.thenAnswer((_) async => [UserStub.user1, UserStub.user2]);
|
||||
when(() => userRepository.getByUserIds(any())).thenAnswer((_) async => [UserStub.user1, UserStub.user2]);
|
||||
|
||||
when(() => assetRepository.getAllByRemoteId(any()))
|
||||
.thenAnswer((_) async => [AssetStub.image1, AssetStub.image2]);
|
||||
when(() => assetRepository.getAllByRemoteId(any())).thenAnswer((_) async => [AssetStub.image1, AssetStub.image2]);
|
||||
|
||||
await sut.fillAlbumWithDatabaseEntities(album);
|
||||
expect(album.owner.value?.toDto(), UserStub.admin);
|
||||
|
||||
@@ -36,27 +36,22 @@ void main() {
|
||||
backgroundService: mockBackgroundService,
|
||||
);
|
||||
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any()))
|
||||
.thenAnswer((_) async {
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any())).thenAnswer((_) async {
|
||||
final capturedCallback = verify(
|
||||
() => mockDeviceAssetRepository.transaction<Null>(captureAny()),
|
||||
).captured;
|
||||
// Invoke the transaction callback
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)?.call();
|
||||
});
|
||||
when(() => mockDeviceAssetRepository.updateAll(any()))
|
||||
.thenAnswer((_) async => true);
|
||||
when(() => mockDeviceAssetRepository.deleteIds(any()))
|
||||
.thenAnswer((_) async => true);
|
||||
when(() => mockDeviceAssetRepository.updateAll(any())).thenAnswer((_) async => true);
|
||||
when(() => mockDeviceAssetRepository.deleteIds(any())).thenAnswer((_) async => true);
|
||||
});
|
||||
|
||||
group("HashService: No DeviceAsset entry", () {
|
||||
test("hash successfully", () async {
|
||||
final (mockAsset, file, deviceAsset, hash) =
|
||||
await _createAssetMock(AssetStub.image1);
|
||||
final (mockAsset, file, deviceAsset, hash) = await _createAssetMock(AssetStub.image1);
|
||||
|
||||
when(() => mockBackgroundService.digestFiles([file.path]))
|
||||
.thenAnswer((_) async => [hash]);
|
||||
when(() => mockBackgroundService.digestFiles([file.path])).thenAnswer((_) async => [hash]);
|
||||
// No DB entries for this asset
|
||||
when(
|
||||
() => mockDeviceAssetRepository.getByIds([AssetStub.image1.localId!]),
|
||||
@@ -65,14 +60,12 @@ void main() {
|
||||
final result = await sut.hashAssets([mockAsset]);
|
||||
|
||||
// Verify we stored the new hash in DB
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any()))
|
||||
.thenAnswer((_) async {
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any())).thenAnswer((_) async {
|
||||
final capturedCallback = verify(
|
||||
() => mockDeviceAssetRepository.transaction<Null>(captureAny()),
|
||||
).captured;
|
||||
// Invoke the transaction callback
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)
|
||||
?.call();
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)?.call();
|
||||
verify(
|
||||
() => mockDeviceAssetRepository.updateAll([
|
||||
deviceAsset.copyWith(modifiedTime: AssetStub.image1.fileModifiedAt),
|
||||
@@ -115,25 +108,21 @@ void main() {
|
||||
});
|
||||
|
||||
test("hashed successful when asset is modified", () async {
|
||||
final (mockAsset, file, deviceAsset, hash) =
|
||||
await _createAssetMock(AssetStub.image1);
|
||||
final (mockAsset, file, deviceAsset, hash) = await _createAssetMock(AssetStub.image1);
|
||||
|
||||
when(() => mockBackgroundService.digestFiles([file.path]))
|
||||
.thenAnswer((_) async => [hash]);
|
||||
when(() => mockBackgroundService.digestFiles([file.path])).thenAnswer((_) async => [hash]);
|
||||
when(
|
||||
() => mockDeviceAssetRepository.getByIds([AssetStub.image1.localId!]),
|
||||
).thenAnswer((_) async => [deviceAsset]);
|
||||
|
||||
final result = await sut.hashAssets([mockAsset]);
|
||||
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any()))
|
||||
.thenAnswer((_) async {
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any())).thenAnswer((_) async {
|
||||
final capturedCallback = verify(
|
||||
() => mockDeviceAssetRepository.transaction<Null>(captureAny()),
|
||||
).captured;
|
||||
// Invoke the transaction callback
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)
|
||||
?.call();
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)?.call();
|
||||
verify(
|
||||
() => mockDeviceAssetRepository.updateAll([
|
||||
deviceAsset.copyWith(modifiedTime: AssetStub.image1.fileModifiedAt),
|
||||
@@ -157,11 +146,9 @@ void main() {
|
||||
late File file;
|
||||
|
||||
setUp(() async {
|
||||
(mockAsset, file, deviceAsset, hash) =
|
||||
await _createAssetMock(AssetStub.image1);
|
||||
(mockAsset, file, deviceAsset, hash) = await _createAssetMock(AssetStub.image1);
|
||||
|
||||
when(() => mockBackgroundService.digestFiles([file.path]))
|
||||
.thenAnswer((_) async => [hash]);
|
||||
when(() => mockBackgroundService.digestFiles([file.path])).thenAnswer((_) async => [hash]);
|
||||
when(
|
||||
() => mockDeviceAssetRepository.getByIds([AssetStub.image1.localId!]),
|
||||
).thenAnswer((_) async => [deviceAsset]);
|
||||
@@ -182,14 +169,12 @@ void main() {
|
||||
});
|
||||
|
||||
test("cleanups DeviceAsset when hashing failed", () async {
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any()))
|
||||
.thenAnswer((_) async {
|
||||
when(() => mockDeviceAssetRepository.transaction<Null>(any())).thenAnswer((_) async {
|
||||
final capturedCallback = verify(
|
||||
() => mockDeviceAssetRepository.transaction<Null>(captureAny()),
|
||||
).captured;
|
||||
// Invoke the transaction callback
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)
|
||||
?.call();
|
||||
await (capturedCallback.firstOrNull as Future<Null> Function()?)?.call();
|
||||
|
||||
// Verify the callback inside the transaction because, doing it outside results
|
||||
// in a small delay before the callback is invoked, resulting in other LOCs getting executed
|
||||
@@ -210,8 +195,7 @@ void main() {
|
||||
// and verify the results inside the transaction stub
|
||||
verify(() => mockDeviceAssetRepository.updateAll([])).called(1);
|
||||
verify(
|
||||
() =>
|
||||
mockDeviceAssetRepository.deleteIds([AssetStub.image1.localId!]),
|
||||
() => mockDeviceAssetRepository.deleteIds([AssetStub.image1.localId!]),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
@@ -240,14 +224,11 @@ void main() {
|
||||
final (asset2, file2, deviceAsset2, hash2) = mock2;
|
||||
final (asset3, file3, deviceAsset3, hash3) = mock3;
|
||||
|
||||
when(() => mockDeviceAssetRepository.getByIds(any()))
|
||||
.thenAnswer((_) async => []);
|
||||
when(() => mockDeviceAssetRepository.getByIds(any())).thenAnswer((_) async => []);
|
||||
|
||||
// Setup for multiple batch processing calls
|
||||
when(() => mockBackgroundService.digestFiles([file1.path, file2.path]))
|
||||
.thenAnswer((_) async => [hash1, hash2]);
|
||||
when(() => mockBackgroundService.digestFiles([file3.path]))
|
||||
.thenAnswer((_) async => [hash3]);
|
||||
when(() => mockBackgroundService.digestFiles([file1.path, file2.path])).thenAnswer((_) async => [hash1, hash2]);
|
||||
when(() => mockBackgroundService.digestFiles([file3.path])).thenAnswer((_) async => [hash3]);
|
||||
|
||||
final size = await file1.length() + await file2.length();
|
||||
|
||||
@@ -259,8 +240,7 @@ void main() {
|
||||
final result = await sut.hashAssets([asset1, asset2, asset3]);
|
||||
|
||||
// Verify multiple batch process calls
|
||||
verify(() => mockBackgroundService.digestFiles([file1.path, file2.path]))
|
||||
.called(1);
|
||||
verify(() => mockBackgroundService.digestFiles([file1.path, file2.path])).called(1);
|
||||
verify(() => mockBackgroundService.digestFiles([file3.path])).called(1);
|
||||
|
||||
expect(
|
||||
@@ -285,15 +265,11 @@ void main() {
|
||||
final (asset2, file2, deviceAsset2, hash2) = mock2;
|
||||
final (asset3, file3, deviceAsset3, hash3) = mock3;
|
||||
|
||||
when(() => mockDeviceAssetRepository.getByIds(any()))
|
||||
.thenAnswer((_) async => []);
|
||||
when(() => mockDeviceAssetRepository.getByIds(any())).thenAnswer((_) async => []);
|
||||
|
||||
when(() => mockBackgroundService.digestFiles([file1.path]))
|
||||
.thenAnswer((_) async => [hash1]);
|
||||
when(() => mockBackgroundService.digestFiles([file2.path]))
|
||||
.thenAnswer((_) async => [hash2]);
|
||||
when(() => mockBackgroundService.digestFiles([file3.path]))
|
||||
.thenAnswer((_) async => [hash3]);
|
||||
when(() => mockBackgroundService.digestFiles([file1.path])).thenAnswer((_) async => [hash1]);
|
||||
when(() => mockBackgroundService.digestFiles([file2.path])).thenAnswer((_) async => [hash2]);
|
||||
when(() => mockBackgroundService.digestFiles([file3.path])).thenAnswer((_) async => [hash3]);
|
||||
|
||||
sut = HashService(
|
||||
deviceAssetRepository: mockDeviceAssetRepository,
|
||||
@@ -318,17 +294,12 @@ void main() {
|
||||
});
|
||||
|
||||
test("HashService: Sort & Process different states", () async {
|
||||
final (asset1, file1, deviceAsset1, hash1) =
|
||||
await _createAssetMock(AssetStub.image1); // Will need rehashing
|
||||
final (asset2, file2, deviceAsset2, hash2) =
|
||||
await _createAssetMock(AssetStub.image2); // Will have matching hash
|
||||
final (asset3, file3, deviceAsset3, hash3) =
|
||||
await _createAssetMock(AssetStub.image3); // No DB entry
|
||||
final asset4 =
|
||||
AssetStub.image3.copyWith(localId: "image4"); // Cannot be hashed
|
||||
final (asset1, file1, deviceAsset1, hash1) = await _createAssetMock(AssetStub.image1); // Will need rehashing
|
||||
final (asset2, file2, deviceAsset2, hash2) = await _createAssetMock(AssetStub.image2); // Will have matching hash
|
||||
final (asset3, file3, deviceAsset3, hash3) = await _createAssetMock(AssetStub.image3); // No DB entry
|
||||
final asset4 = AssetStub.image3.copyWith(localId: "image4"); // Cannot be hashed
|
||||
|
||||
when(() => mockBackgroundService.digestFiles([file1.path, file3.path]))
|
||||
.thenAnswer((_) async => [hash1, hash3]);
|
||||
when(() => mockBackgroundService.digestFiles([file1.path, file3.path])).thenAnswer((_) async => [hash1, hash3]);
|
||||
// DB entries are not sorted and a dummy entry added
|
||||
when(
|
||||
() => mockDeviceAssetRepository.getByIds([
|
||||
@@ -349,8 +320,7 @@ void main() {
|
||||
final result = await sut.hashAssets([asset1, asset2, asset3, asset4]);
|
||||
|
||||
// Verify correct processing of all assets
|
||||
verify(() => mockBackgroundService.digestFiles([file1.path, file3.path]))
|
||||
.called(1);
|
||||
verify(() => mockBackgroundService.digestFiles([file1.path, file3.path])).called(1);
|
||||
expect(result.length, 3);
|
||||
expect(result, [
|
||||
AssetStub.image2.copyWith(checksum: base64.encode(hash2)),
|
||||
@@ -361,8 +331,7 @@ void main() {
|
||||
|
||||
group("HashService: Edge cases", () {
|
||||
test("handles empty list of assets", () async {
|
||||
when(() => mockDeviceAssetRepository.getByIds(any()))
|
||||
.thenAnswer((_) async => []);
|
||||
when(() => mockDeviceAssetRepository.getByIds(any())).thenAnswer((_) async => []);
|
||||
|
||||
final result = await sut.hashAssets([]);
|
||||
|
||||
@@ -398,8 +367,7 @@ Future<(Asset, File, DeviceAsset, Uint8List)> _createAssetMock(
|
||||
Asset asset,
|
||||
) async {
|
||||
final random = Random();
|
||||
final hash =
|
||||
Uint8List.fromList(List.generate(20, (i) => random.nextInt(255)));
|
||||
final hash = Uint8List.fromList(List.generate(20, (i) => random.nextInt(255)));
|
||||
final mockAsset = MockAsset();
|
||||
final mockAssetEntity = MockAssetEntity();
|
||||
final fs = MemoryFileSystem();
|
||||
|
||||
Reference in New Issue
Block a user