From cbdd8bc4695275f44630c57657cc9a6e1acb37df Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 4 Mar 2022 17:08:52 -0600 Subject: [PATCH] fix(sonarr): Do not throw away optionals release profile The Trash sonarr guide was restructured so that optionals were in a dedicated release profile that had no non-optional terms in it. Logic was only checking if a profile had non-optional terms in it, and if not, it got tossed out. Logic now also checks to make sure there are no optional terms as well. --- CHANGELOG.md | 4 + .../Sonarr/ReleaseProfile/UtilsTest.cs | 123 ++++++++++++++++++ .../Sonarr/ReleaseProfile/ProfileData.cs | 4 +- src/TrashLib/Sonarr/ReleaseProfile/Utils.cs | 13 +- 4 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 src/TrashLib.Tests/Sonarr/ReleaseProfile/UtilsTest.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c741845..6267defc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Unrecognized or unwanted YAML properties in configuration YAML (`trash.yml`) now result in an error. This is to help users more easily identify mistakes. +### Fixed + +- Sonarr: Optionals release profile is now properly synced + ## [1.8.0] - 2022-02-13 ### Added diff --git a/src/TrashLib.Tests/Sonarr/ReleaseProfile/UtilsTest.cs b/src/TrashLib.Tests/Sonarr/ReleaseProfile/UtilsTest.cs new file mode 100644 index 00000000..f19dea2f --- /dev/null +++ b/src/TrashLib.Tests/Sonarr/ReleaseProfile/UtilsTest.cs @@ -0,0 +1,123 @@ +using FluentAssertions; +using NUnit.Framework; +using TrashLib.Sonarr.ReleaseProfile; + +namespace TrashLib.Tests.Sonarr.ReleaseProfile; + +[TestFixture] +[Parallelizable(ParallelScope.All)] +public class UtilsTest +{ + [Test] + public void Profile_with_only_ignored_should_not_be_filtered_out() + { + var profileData = new ProfileData {Ignored = new List {"term"}}; + var data = new Dictionary {{"actualData", profileData}}; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Profile_with_only_required_should_not_be_filtered_out() + { + var profileData = new ProfileData {Required = new List {"term"}}; + var data = new Dictionary {{"actualData", profileData}}; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Profile_with_only_preferred_should_not_be_filtered_out() + { + var profileData = new ProfileData + { + Preferred = new Dictionary> + { + {100, new List {"term"}} + } + }; + + var data = new Dictionary {{"actualData", profileData}}; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Profile_with_only_optional_ignored_should_not_be_filtered_out() + { + var profileData = new ProfileData + { + Optional = new ProfileDataOptional + { + Ignored = new List {"term"} + } + }; + + var data = new Dictionary {{"actualData", profileData}}; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Profile_with_only_optional_required_should_not_be_filtered_out() + { + var profileData = new ProfileData + { + Optional = new ProfileDataOptional + { + Required = new List {"required1"} + } + }; + + var data = new Dictionary + { + {"actualData", profileData} + }; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Profile_with_only_optional_preferred_should_not_be_filtered_out() + { + var profileData = new ProfileData + { + Optional = new ProfileDataOptional + { + Preferred = new Dictionary> + { + {100, new List {"term"}} + } + } + }; + + var data = new Dictionary {{"actualData", profileData}}; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().BeEquivalentTo(data); + } + + [Test] + public void Empty_profiles_should_be_filtered_out() + { + var data = new Dictionary + { + {"emptyData", new ProfileData()} + }; + + var filteredData = Utils.FilterProfiles(data); + + filteredData.Should().NotContainKey("emptyData"); + } +} diff --git a/src/TrashLib/Sonarr/ReleaseProfile/ProfileData.cs b/src/TrashLib/Sonarr/ReleaseProfile/ProfileData.cs index e95adcc4..b893bc38 100644 --- a/src/TrashLib/Sonarr/ReleaseProfile/ProfileData.cs +++ b/src/TrashLib/Sonarr/ReleaseProfile/ProfileData.cs @@ -1,13 +1,13 @@ namespace TrashLib.Sonarr.ReleaseProfile; -public class ProfileDataOptional +public record ProfileDataOptional { public ICollection Required { get; init; } = new List(); public ICollection Ignored { get; init; } = new List(); public IDictionary> Preferred { get; init; } = new Dictionary>(); } -public class ProfileData +public record ProfileData { public ICollection Required { get; init; } = new List(); public ICollection Ignored { get; init; } = new List(); diff --git a/src/TrashLib/Sonarr/ReleaseProfile/Utils.cs b/src/TrashLib/Sonarr/ReleaseProfile/Utils.cs index fda97474..282a2e77 100644 --- a/src/TrashLib/Sonarr/ReleaseProfile/Utils.cs +++ b/src/TrashLib/Sonarr/ReleaseProfile/Utils.cs @@ -8,7 +8,18 @@ public static class Utils { static bool IsEmpty(ProfileData data) { - return data.Required.Count == 0 && data.Ignored.Count == 0 && data.Preferred.Count == 0; + return data is + { + // Non-optional + Required.Count: 0, + Ignored.Count: 0, + Preferred.Count: 0, + + // Optional + Optional.Required.Count: 0, + Optional.Ignored.Count: 0, + Optional.Preferred.Count: 0 + }; } // A few false-positive profiles are added sometimes. We filter these out by checking if they