diff --git a/code/backend/Cleanuparr.Infrastructure.Tests/Features/Arr/LidarrClientTests.cs b/code/backend/Cleanuparr.Infrastructure.Tests/Features/Arr/LidarrClientTests.cs index 24dbd191..c37eb5d0 100644 --- a/code/backend/Cleanuparr.Infrastructure.Tests/Features/Arr/LidarrClientTests.cs +++ b/code/backend/Cleanuparr.Infrastructure.Tests/Features/Arr/LidarrClientTests.cs @@ -459,11 +459,21 @@ public class LidarrClientTests } [Fact] - public async Task GetAlbumsAsync_NullBody_ReturnsEmpty() + public async Task GetAlbumsAsync_NullBody_Throws() { // Arrange _httpMessageHandler.SetupResponse((_, _) => Task.FromResult(JsonNullResponse())); + // Act & Assert + await Should.ThrowAsync(() => _client.GetAlbumsAsync(_arrInstance, 7)); + } + + [Fact] + public async Task GetAlbumsAsync_EmptyArray_ReturnsEmpty() + { + // Arrange + _httpMessageHandler.SetupResponse((_, _) => Task.FromResult(RawJsonResponse("[]"))); + // Act List albums = await _client.GetAlbumsAsync(_arrInstance, 7); diff --git a/code/backend/Cleanuparr.Infrastructure/Features/Arr/LidarrClient.cs b/code/backend/Cleanuparr.Infrastructure/Features/Arr/LidarrClient.cs index 5d300d4f..f0f21116 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/Arr/LidarrClient.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/Arr/LidarrClient.cs @@ -226,7 +226,9 @@ public class LidarrClient : ArrClient, ILidarrClient using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); response.EnsureSuccessStatusCode(); - return await DeserializeStreamAsync>(response, cancellationToken) ?? []; + // An empty list would make the CF syncer delete every album entry of the artist + return await DeserializeStreamAsync>(response, cancellationToken) + ?? throw new InvalidOperationException($"Lidarr returned null albums for artist {artistId}"); } public async Task> GetTrackFilesAsync(ArrInstance arrInstance, long artistId, CancellationToken cancellationToken = default)