diff --git a/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs index ea9208cf7..11860ce28 100644 --- a/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs @@ -130,5 +130,76 @@ namespace Ombi.Core.Tests.Rule.Search Assert.False(search.Approved); Assert.False(search.Requested); } + + [Test] + public async Task ShouldBeFullyAvailable_NoFutureAiredEpisodes_NoRequest() + { + var search = new SearchTvShowViewModel() + { + Id = 999, + SeasonRequests = new List + { + new SeasonRequests + { + Episodes = new List + { + new EpisodeRequests + { + Available = true, + AirDate = new System.DateTime(2020,01,01) + }, + new EpisodeRequests + { + Available = true, + AirDate = new System.DateTime(2020,01,02) + }, + } + } + } + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.That(search.FullyAvailable, Is.True); + Assert.That(search.PartlyAvailable, Is.False); + } + + [Test] + public async Task ShouldBeFullyAvailable_AndPartly_FutureAiredEpisodes_NoRequest() + { + var search = new SearchTvShowViewModel() + { + Id = 999, + SeasonRequests = new List + { + new SeasonRequests + { + Episodes = new List + { + new EpisodeRequests + { + Available = true, + AirDate = new System.DateTime(2020,01,01) + }, + new EpisodeRequests + { + Available = true, + AirDate = new System.DateTime(2020,01,02) + }, + new EpisodeRequests + { + Available = true, + AirDate = new System.DateTime(2029,01,02) + }, + } + } + } + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.That(search.FullyAvailable, Is.True); + Assert.That(search.PartlyAvailable, Is.True); + } } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs index a7cd43336..58c2508a6 100644 --- a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs @@ -85,11 +85,18 @@ namespace Ombi.Core.Rule.Rules.Search { request.FullyAvailable = true; } - if (request.SeasonRequests.Any() && request.SeasonRequests.All(x => x.Episodes.Any(e => e.Available && e.AirDate > DateTime.MinValue))) + if (request.SeasonRequests.Any() && request.SeasonRequests.All(x => x.Episodes.Any(e => e.Available && e.AirDate > DateTime.MinValue && e.AirDate <= DateTime.UtcNow))) { request.PartlyAvailable = true; } + var hasUnairedRequests = request.SeasonRequests.Any() && request.SeasonRequests.All(x => x.Episodes.Any(e => e.AirDate >= DateTime.UtcNow)); + + if (request.FullyAvailable) + { + request.PartlyAvailable = hasUnairedRequests; + } + return Success(); } if (obj.Type == RequestType.Album) diff --git a/src/Ombi/.vscode/settings.json b/src/Ombi/.vscode/settings.json index 5862f9a19..23bdd881e 100644 --- a/src/Ombi/.vscode/settings.json +++ b/src/Ombi/.vscode/settings.json @@ -19,6 +19,7 @@ "newsletter", "mass-email", "issues", - "emby" + "emby", + "availability-rules" ] }