Fixed: PRevent import if potential bulk season release doesn't have air date for all episodes

Closes #5021
This commit is contained in:
Mark McDowall 2022-05-22 17:18:19 -07:00
parent d48950ec3c
commit f9b2c2d843
2 changed files with 26 additions and 3 deletions

View File

@ -136,7 +136,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
}
[Test]
public void should_reject_if_episode_title_is_required_for_bulk_season_releases_and_it_is_mising()
public void should_reject_if_episode_title_is_required_for_bulk_season_releases_and_it_is_missing()
{
_localEpisode.Episodes.First().Title = "TBA";
@ -154,5 +154,28 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_reject_if_episode_title_is_required_for_bulk_season_releases_and_some_episodes_do_not_have_air_date()
{
_localEpisode.Episodes.First().Title = "TBA";
Mocker.GetMock<IConfigService>()
.Setup(s => s.EpisodeTitleRequired)
.Returns(EpisodeTitleRequiredType.BulkSeasonReleases);
Mocker.GetMock<IEpisodeService>()
.Setup(s => s.GetEpisodesBySeason(It.IsAny<int>(), It.IsAny<int>()))
.Returns(Builder<Episode>.CreateListOfSize(5)
.All()
.With(e => e.Title = "TBA")
.With(e => e.AirDateUtc = null)
.TheFirst(1)
.With(e => e.AirDateUtc = _localEpisode.Episodes.First().AirDateUtc)
.BuildList());
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
}
}

View File

@ -55,12 +55,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
var firstEpisode = episodes.First();
var episodesInSeason = _episodeService.GetEpisodesBySeason(firstEpisode.SeriesId, firstEpisode.EpisodeNumber);
var allEpisodesOnTheSameDay = firstEpisode.AirDateUtc.HasValue && episodes.All(e =>
e.AirDateUtc.HasValue &&
!e.AirDateUtc.HasValue ||
e.AirDateUtc.Value == firstEpisode.AirDateUtc.Value);
if (episodeTitleRequired == EpisodeTitleRequiredType.BulkSeasonReleases &&
allEpisodesOnTheSameDay &&
episodesInSeason.Count(e => e.AirDateUtc.HasValue &&
episodesInSeason.Count(e => !e.AirDateUtc.HasValue ||
e.AirDateUtc.Value == firstEpisode.AirDateUtc.Value
) < 4
)