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.
pull/47/head
Robert Dailey 2 years ago
parent 546bd3bf5e
commit cbdd8bc469

@ -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

@ -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<string> {"term"}};
var data = new Dictionary<string, ProfileData> {{"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<string> {"term"}};
var data = new Dictionary<string, ProfileData> {{"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<int, List<string>>
{
{100, new List<string> {"term"}}
}
};
var data = new Dictionary<string, ProfileData> {{"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<string> {"term"}
}
};
var data = new Dictionary<string, ProfileData> {{"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<string> {"required1"}
}
};
var data = new Dictionary<string, ProfileData>
{
{"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<int, List<string>>
{
{100, new List<string> {"term"}}
}
}
};
var data = new Dictionary<string, ProfileData> {{"actualData", profileData}};
var filteredData = Utils.FilterProfiles(data);
filteredData.Should().BeEquivalentTo(data);
}
[Test]
public void Empty_profiles_should_be_filtered_out()
{
var data = new Dictionary<string, ProfileData>
{
{"emptyData", new ProfileData()}
};
var filteredData = Utils.FilterProfiles(data);
filteredData.Should().NotContainKey("emptyData");
}
}

@ -1,13 +1,13 @@
namespace TrashLib.Sonarr.ReleaseProfile;
public class ProfileDataOptional
public record ProfileDataOptional
{
public ICollection<string> Required { get; init; } = new List<string>();
public ICollection<string> Ignored { get; init; } = new List<string>();
public IDictionary<int, List<string>> Preferred { get; init; } = new Dictionary<int, List<string>>();
}
public class ProfileData
public record ProfileData
{
public ICollection<string> Required { get; init; } = new List<string>();
public ICollection<string> Ignored { get; init; } = new List<string>();

@ -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

Loading…
Cancel
Save