fixed lidarr null albums wiping cf entries

This commit is contained in:
Flaminel committed 2026-10-27 11:08:13 +02:00
1 parent cf8c92c4a0
commit b51d8323a6
2 files changed
+14 -2

No files matched your search

@@ -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<InvalidOperationException>(() => _client.GetAlbumsAsync(_arrInstance, 7));
}
[Fact]
public async Task GetAlbumsAsync_EmptyArray_ReturnsEmpty()
{
// Arrange
_httpMessageHandler.SetupResponse((_, _) => Task.FromResult(RawJsonResponse("[]")));
// Act
List<SearchableAlbum> albums = await _client.GetAlbumsAsync(_arrInstance, 7);
@@ -226,7 +226,9 @@ public class LidarrClient : ArrClient, ILidarrClient
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
response.EnsureSuccessStatusCode();
return await DeserializeStreamAsync<List<SearchableAlbum>>(response, cancellationToken) ?? [];
// An empty list would make the CF syncer delete every album entry of the artist
return await DeserializeStreamAsync<List<SearchableAlbum>>(response, cancellationToken)
?? throw new InvalidOperationException($"Lidarr returned null albums for artist {artistId}");
}
public async Task<List<ArrTrackFile>> GetTrackFilesAsync(ArrInstance arrInstance, long artistId, CancellationToken cancellationToken = default)