diff --git a/src/NzbDrone.Integration.Test/ApiTests/QueueFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/QueueFixture.cs new file mode 100644 index 000000000..8dfa62872 --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/QueueFixture.cs @@ -0,0 +1,73 @@ +using System.IO; +using System.Linq; +using System.Threading; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Integration.Test.Client; +using Sonarr.Api.V3.Queue; +using Sonarr.Http; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class QueueFixture : IntegrationTest + { + private PagingResource GetFirstPage() + { + var request = Queue.BuildRequest(); + request.AddParameter("includeUnknownSeriesItems", true); + + return Queue.Get>(request); + } + + private void RefreshQueue() + { + var command = Commands.Post(new SimpleCommandResource { Name = "RefreshMonitoredDownloads" }); + + for (var i = 0; i < 30; i++) + { + var updatedCommand = Commands.Get(command.Id); + + if (updatedCommand.Status == CommandStatus.Completed) + { + return; + } + + Thread.Sleep(1000); + i++; + } + } + + [Test] + [Order(0)] + public void ensure_queue_is_empty_when_download_client_is_configured() + { + EnsureNoDownloadClient(); + EnsureDownloadClient(); + + var queue = GetFirstPage(); + + queue.TotalRecords.Should().Be(0); + queue.Records.Should().BeEmpty(); + } + + [Test] + [Order(1)] + public void ensure_queue_is_not_empty() + { + EnsureNoDownloadClient(); + + var client = EnsureDownloadClient(); + var directory = client.Fields.First(v => v.Name == "watchFolder").Value as string; + + File.WriteAllText(Path.Combine(directory, "Series.Title.S01E01.mkv"), "Test Download"); + RefreshQueue(); + + var queue = GetFirstPage(); + + queue.TotalRecords.Should().Be(1); + queue.Records.Should().NotBeEmpty(); + } + } +} diff --git a/src/NzbDrone.Integration.Test/Client/QueueClient.cs b/src/NzbDrone.Integration.Test/Client/QueueClient.cs new file mode 100644 index 000000000..f35869b52 --- /dev/null +++ b/src/NzbDrone.Integration.Test/Client/QueueClient.cs @@ -0,0 +1,13 @@ +using RestSharp; +using Sonarr.Api.V3.Queue; + +namespace NzbDrone.Integration.Test.Client +{ + public class QueueClient : ClientBase + { + public QueueClient(IRestClient restClient, string apiKey) + : base(restClient, apiKey) + { + } + } +} diff --git a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs index 3e8a8a2b0..c9786bdd3 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs @@ -57,6 +57,7 @@ namespace NzbDrone.Integration.Test public ClientBase Tags; public ClientBase WantedMissing; public ClientBase WantedCutoffUnmet; + public QueueClient Queue; private List _signalRReceived; @@ -121,6 +122,7 @@ namespace NzbDrone.Integration.Test Tags = new ClientBase(RestClient, ApiKey); WantedMissing = new ClientBase(RestClient, ApiKey, "wanted/missing"); WantedCutoffUnmet = new ClientBase(RestClient, ApiKey, "wanted/cutoff"); + Queue = new QueueClient(RestClient, ApiKey); } [OneTimeTearDown] diff --git a/src/Sonarr.Api.V3/Queue/QueueResource.cs b/src/Sonarr.Api.V3/Queue/QueueResource.cs index 06e614aeb..f209a3ccc 100644 --- a/src/Sonarr.Api.V3/Queue/QueueResource.cs +++ b/src/Sonarr.Api.V3/Queue/QueueResource.cs @@ -26,8 +26,11 @@ namespace Sonarr.Api.V3.Queue public int CustomFormatScore { get; set; } public decimal Size { get; set; } public string Title { get; set; } - public decimal SizeLeft { get; set; } - public TimeSpan? TimeLeft { get; set; } + + // Collides with existing properties due to case-insensitive deserialization + // public decimal SizeLeft { get; set; } + // public TimeSpan? TimeLeft { get; set; } + public DateTime? EstimatedCompletionTime { get; set; } public DateTime? Added { get; set; } public QueueStatus Status { get; set; } @@ -43,9 +46,10 @@ namespace Sonarr.Api.V3.Queue public string OutputPath { get; set; } public bool EpisodeHasFile { get; set; } - [Obsolete] + [Obsolete("Will be replaced by SizeLeft")] public decimal Sizeleft { get; set; } - [Obsolete] + + [Obsolete("Will be replaced by TimeLeft")] public TimeSpan? Timeleft { get; set; } } @@ -75,8 +79,11 @@ namespace Sonarr.Api.V3.Queue CustomFormatScore = customFormatScore, Size = model.Size, Title = model.Title, - SizeLeft = model.SizeLeft, - TimeLeft = model.TimeLeft, + + // Collides with existing properties due to case-insensitive deserialization + // SizeLeft = model.SizeLeft, + // TimeLeft = model.TimeLeft, + EstimatedCompletionTime = model.EstimatedCompletionTime, Added = model.Added, Status = model.Status, @@ -92,10 +99,10 @@ namespace Sonarr.Api.V3.Queue OutputPath = model.OutputPath, EpisodeHasFile = model.Episode?.HasFile ?? false, - #pragma warning disable CS0612 + #pragma warning disable CS0618 Sizeleft = model.SizeLeft, Timeleft = model.TimeLeft, - #pragma warning restore CS0612 + #pragma warning restore CS0618 }; }