fix(radarr): Remove all trash properties from guide CFs

Any property starting with `trash_` is now removed from guide CFs.

Fixes #109.
pull/124/head
Robert Dailey 2 years ago
parent 609244e8c9
commit 98e6b4ce59

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Radarr: Custom formats were always showing up as changed in the logs (#109)
## [2.4.0] - 2022-08-25
### Added

@ -2,9 +2,11 @@ using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using AutoFixture.NUnit3;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NSubstitute;
using NUnit.Framework;
using TestLibrary.AutoFixture;
using TestLibrary.FluentAssertions;
using TrashLib.Repo;
using TrashLib.Services.Radarr.CustomFormat.Guide;
using TrashLib.Startup;
@ -41,4 +43,36 @@ public class LocalRepoRadarrGuideServiceTest
NewCf.Data("second", "2")
});
}
[Test, AutoMockData]
public void Trash_properties_are_removed(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] IAppPaths appPaths,
[Frozen] IRepoPaths repoPaths,
LocalRepoRadarrGuideService sut)
{
var jsonDir = appPaths.RepoDirectory
.SubDirectory("docs")
.SubDirectory("json")
.SubDirectory("radarr");
fs.AddFile(jsonDir.File("first.json").FullName, new MockFileData(@"
{
'name':'first',
'trash_id':'1',
'trash_foo': 'foo',
'trash_bar': 'bar',
'extra': 'e1'
}"));
repoPaths.RadarrCustomFormatPaths.Returns(new[] {jsonDir});
var results = sut.GetCustomFormatData();
const string expectedExtraJson = @"{'name':'first','extra': 'e1'}";
results.Should()
.ContainSingle().Which.ExtraJson.Should()
.BeEquivalentTo(JObject.Parse(expectedExtraJson), op => op.Using(new JsonEquivalencyStep()));
}
}

@ -1,6 +1,7 @@
using System.IO.Abstractions;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Text.RegularExpressions;
using Common.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -65,12 +66,16 @@ public class LocalRepoRadarrGuideService : IRadarrGuideService
if (obj.TryGetValue("trash_score", out var score))
{
finalScore = (int) score;
obj.Property("trash_score")?.Remove();
}
// Remove trash_id, it's metadata that is not meant for Radarr itself
// Radarr supposedly drops this anyway, but I prefer it to be removed.
obj.Property("trash_id")?.Remove();
// Remove any properties starting with "trash_". Those are metadata that are not meant for Radarr itself Radarr
// supposedly drops this anyway, but I prefer it to be removed. ToList() is important here since removing the
// property itself modifies the collection, and we don't want the collection to get modified while still looping
// over it.
foreach (var trashProperty in obj.Properties().Where(x => Regex.IsMatch(x.Name, @"^trash_")).ToList())
{
trashProperty.Remove();
}
return new CustomFormatData(name, trashId, finalScore, obj);
}

Loading…
Cancel
Save