From 78697ac0cd3d852c4e2127066f04636ceafcbb4d Mon Sep 17 00:00:00 2001 From: Flaminel Date: Sat, 12 Sep 2026 03:07:40 +0300 Subject: [PATCH] added 404 and empty client coverage for torrent lists --- .../TorrentListErrorSurfacingTests.cs | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/TorrentListErrorSurfacingTests.cs b/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/TorrentListErrorSurfacingTests.cs index b27f3404..4bcde44a 100644 --- a/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/TorrentListErrorSurfacingTests.cs +++ b/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/TorrentListErrorSurfacingTests.cs @@ -1,6 +1,8 @@ using System.Net; using System.Text; +using Cleanuparr.Domain.Entities; using Cleanuparr.Domain.Enums; +using Cleanuparr.Infrastructure.Features.DownloadClient; using Cleanuparr.Infrastructure.Features.DownloadClient.Deluge; using Cleanuparr.Infrastructure.Features.DownloadClient.QBittorrent; using Cleanuparr.Infrastructure.Features.DownloadClient.RTorrent; @@ -52,6 +54,7 @@ public sealed class TorrentListErrorSurfacingTests [InlineData(HttpStatusCode.Unauthorized)] [InlineData(HttpStatusCode.Forbidden)] [InlineData(HttpStatusCode.BadGateway)] + [InlineData(HttpStatusCode.NotFound)] public async Task RTorrent_ListCallReturnsErrorStatus_Throws(HttpStatusCode status) { FakeHttpMessageHandler handler = new(); @@ -157,6 +160,7 @@ public sealed class TorrentListErrorSurfacingTests [InlineData(HttpStatusCode.Unauthorized)] [InlineData(HttpStatusCode.Forbidden)] [InlineData(HttpStatusCode.BadGateway)] + [InlineData(HttpStatusCode.NotFound)] public async Task Deluge_ListCallReturnsErrorStatus_Throws(HttpStatusCode status) { FakeHttpMessageHandler handler = new(); @@ -240,6 +244,7 @@ public sealed class TorrentListErrorSurfacingTests [InlineData(HttpStatusCode.Unauthorized)] [InlineData(HttpStatusCode.Forbidden)] [InlineData(HttpStatusCode.BadGateway)] + [InlineData(HttpStatusCode.NotFound)] public async Task QBit_ListCallReturnsErrorStatus_Throws(HttpStatusCode status) { FakeHttpMessageHandler handler = new(); @@ -303,6 +308,7 @@ public sealed class TorrentListErrorSurfacingTests [InlineData(HttpStatusCode.Unauthorized)] [InlineData(HttpStatusCode.Forbidden)] [InlineData(HttpStatusCode.BadGateway)] + [InlineData(HttpStatusCode.NotFound)] public async Task Transmission_ListCallReturnsErrorStatus_Throws(HttpStatusCode status) { FakeHttpMessageHandler handler = new(); @@ -346,6 +352,7 @@ public sealed class TorrentListErrorSurfacingTests [InlineData(HttpStatusCode.Unauthorized)] [InlineData(HttpStatusCode.Forbidden)] [InlineData(HttpStatusCode.BadGateway)] + [InlineData(HttpStatusCode.NotFound)] public async Task UTorrent_ListCallReturnsErrorStatus_Throws(HttpStatusCode status) { FakeHttpMessageHandler handler = new(); @@ -484,4 +491,76 @@ public sealed class TorrentListErrorSurfacingTests } #endregion + + #region Empty client + + // The counterpart to the guard above: a client holding nothing is not a faulty client. + // Issue #746 came from reading these two states as one. + + [Fact] + public async Task RTorrent_ReportsNoTorrents_ReturnsEmpty() + { + using RTorrentServiceFixture fixture = new(); + RTorrentService sut = fixture.CreateSut(); + fixture.ClientWrapper.GetAllTorrentsAsync() + .Returns(new List()); + + List torrents = await sut.GetAllTorrentsLite(); + + torrents.ShouldBeEmpty(); + } + + [Fact] + public async Task Deluge_ReportsNoTorrents_ReturnsEmpty() + { + using DelugeServiceFixture fixture = new(); + DelugeService sut = fixture.CreateSut(); + fixture.ClientWrapper.GetStatusForAllTorrents() + .Returns(new List()); + + List torrents = await sut.GetAllTorrentsLite(); + + torrents.ShouldBeEmpty(); + } + + [Fact] + public async Task QBit_ReportsNoTorrents_ReturnsEmpty() + { + using QBitServiceFixture fixture = new(); + QBitService sut = fixture.CreateSut(); + fixture.ClientWrapper.GetTorrentListAsync(Arg.Any()) + .Returns(new List()); + + List torrents = await sut.GetAllTorrentsLite(); + + torrents.ShouldBeEmpty(); + } + + [Fact] + public async Task Transmission_ReportsNoTorrents_ReturnsEmpty() + { + using TransmissionServiceFixture fixture = new(); + TransmissionService sut = fixture.CreateSut(); + fixture.ClientWrapper.TorrentGetAsync(Arg.Any(), Arg.Any()) + .Returns(new Transmission.API.RPC.Entity.TransmissionTorrents { Torrents = [] }); + + List torrents = await sut.GetAllTorrentsLite(); + + torrents.ShouldBeEmpty(); + } + + [Fact] + public async Task UTorrent_ReportsNoTorrents_ReturnsEmpty() + { + using UTorrentServiceFixture fixture = new(); + UTorrentService sut = fixture.CreateSut(); + fixture.ClientWrapper.GetTorrentsAsync() + .Returns(new List()); + + List torrents = await sut.GetAllTorrentsLite(); + + torrents.ShouldBeEmpty(); + } + + #endregion }