diff --git a/mobile/test/medium/repositories/remote_album_repository_test.dart b/mobile/test/medium/repositories/remote_album_repository_test.dart index 2ae84039e0..8ed3c75d14 100644 --- a/mobile/test/medium/repositories/remote_album_repository_test.dart +++ b/mobile/test/medium/repositories/remote_album_repository_test.dart @@ -191,12 +191,14 @@ void main() { ); final active1 = await ctx.newRemoteAsset( ownerId: user.id, - createdAt: DateTime(2024, 5, 1), + createdAt: DateTime(2024, 5, 10), + localDateTime: DateTime(2024, 5, 1), visibility: AssetVisibility.timeline, ); final active2 = await ctx.newRemoteAsset( ownerId: user.id, - createdAt: DateTime(2024, 10, 1), + createdAt: DateTime(2024, 10, 10), + localDateTime: DateTime(2024, 10, 1), visibility: AssetVisibility.archive, ); final hidden = await ctx.newRemoteAsset( @@ -212,8 +214,35 @@ void main() { final range = await sut.watchDateRange(album.id).first; - expect(range.$1.toUtc(), active1.createdAt.toUtc()); - expect(range.$2.toUtc(), active2.createdAt.toUtc()); + expect(range.$1.toUtc(), active1.localDateTime!.toUtc()); + expect(range.$2.toUtc(), active2.localDateTime!.toUtc()); + }); + + test('prioritizes localDateTime over createdAt for date range calculation', () async { + final user = await ctx.newUser(); + final album = await ctx.newRemoteAlbum(ownerId: user.id); + + final asset1 = await ctx.newRemoteAsset( + ownerId: user.id, + createdAt: DateTime(2024, 5, 10), + localDateTime: DateTime(2024, 5, 1), + visibility: AssetVisibility.timeline, + ); + final asset2 = await ctx.newRemoteAsset( + ownerId: user.id, + createdAt: DateTime(2024, 10, 10), + localDateTime: DateTime(2024, 10, 1), + visibility: AssetVisibility.archive, + ); + + await ctx.newRemoteAlbumAsset(albumId: album.id, assetId: asset1.id); + await ctx.newRemoteAlbumAsset(albumId: album.id, assetId: asset2.id); + + final range = await sut.watchDateRange(album.id).first; + + // Dates should match localDateTime, not createdAt + expect(range.$1.toUtc(), DateTime(2024, 5, 1).toUtc()); + expect(range.$2.toUtc(), DateTime(2024, 10, 1).toUtc()); }); }); diff --git a/mobile/test/medium/repository_context.dart b/mobile/test/medium/repository_context.dart index ed06774e82..747de312c2 100644 --- a/mobile/test/medium/repository_context.dart +++ b/mobile/test/medium/repository_context.dart @@ -102,6 +102,7 @@ class MediumRepositoryContext { String? stackId, String? thumbHash, String? libraryId, + DateTime? localDateTime, }) async { id ??= TestUtils.uuid(); createdAt ??= TestUtils.date(); @@ -109,25 +110,25 @@ class MediumRepositoryContext { .into(db.remoteAssetEntity) .insertReturning( RemoteAssetEntityCompanion( - id: .new(id), - name: .new('remote_$id.jpg'), - checksum: .new(TestUtils.uuid(checksum)), - type: .new(type ?? .image), - createdAt: .new(createdAt), - updatedAt: .new(TestUtils.date(updatedAt)), - ownerId: .new(TestUtils.uuid(ownerId)), - visibility: .new(visibility ?? .timeline), - deletedAt: .new(deletedAt), - durationMs: .new(durationMs ?? 0), - width: .new(width ?? TestUtils.randInt(1000)), - height: .new(height ?? TestUtils.randInt(1000)), - isFavorite: .new(isFavorite ?? false), - isEdited: .new(isEdited ?? false), - livePhotoVideoId: .new(livePhotoVideoId), - stackId: .new(stackId), - localDateTime: .new(createdAt.toLocal()), - thumbHash: .new(TestUtils.uuid(thumbHash)), - libraryId: .new(TestUtils.uuid(libraryId)), + id: Value(id), + name: Value('remote_$id.jpg'), + checksum: Value(TestUtils.uuid(checksum)), + type: Value(type ?? AssetType.image), + createdAt: Value(createdAt), + updatedAt: Value(TestUtils.date(updatedAt)), + ownerId: Value(TestUtils.uuid(ownerId)), + visibility: Value(visibility ?? AssetVisibility.timeline), + deletedAt: Value(deletedAt), + durationMs: Value(durationMs ?? 0), + width: Value(width ?? TestUtils.randInt(1000)), + height: Value(height ?? TestUtils.randInt(1000)), + isFavorite: Value(isFavorite ?? false), + isEdited: Value(isEdited ?? false), + livePhotoVideoId: Value(livePhotoVideoId), + stackId: Value(stackId), + localDateTime: Value(localDateTime ?? createdAt.toLocal()), + thumbHash: Value(TestUtils.uuid(thumbHash)), + libraryId: Value(TestUtils.uuid(libraryId)), ), ); }