From c033dd8a1391b764cfe0b8e27b9e12030c53fd79 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 20 Aug 2023 09:51:14 -0500 Subject: [PATCH] refactor: Change structure of processed QP object --- .../QualityProfileConfigPhase.cs | 8 ++++-- src/tests/Recyclarr.Cli.TestLibrary/NewQp.cs | 14 ++++++++-- .../QualityProfileTransactionPhaseTest.cs | 13 +++++---- .../UpdatedQualityProfileTest.cs | 28 +++++++------------ .../UpdatedQualityProfileValidatorTest.cs | 8 +++--- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs index 711f730b..bef709d3 100644 --- a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs @@ -7,8 +7,9 @@ namespace Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases; public record ProcessedQualityProfileScore(string TrashId, string CfName, int FormatId, int Score); -public record ProcessedQualityProfileData(QualityProfileConfig Profile) +public record ProcessedQualityProfileData { + public required QualityProfileConfig Profile { get; init; } public bool ShouldCreate { get; init; } = true; public IList CfScores { get; init; } = new List(); } @@ -39,7 +40,7 @@ public class QualityProfileConfigPhase .Select(y => (x.Profile, Cf: y))); var allProfiles = config.QualityProfiles - .Select(x => new ProcessedQualityProfileData(x)) + .Select(x => new ProcessedQualityProfileData {Profile = x}) .ToDictionary(x => x.Profile.Name, x => x, StringComparer.InvariantCultureIgnoreCase); foreach (var (profile, cf) in profileAndCfs) @@ -51,8 +52,9 @@ public class QualityProfileConfigPhase // If the user did not specify a quality profile in their config, we still create the QP object // for consistency (at the very least for the name). allProfiles[profile.Name] = profileCfs = - new ProcessedQualityProfileData(new QualityProfileConfig {Name = profile.Name}) + new ProcessedQualityProfileData { + Profile = new QualityProfileConfig {Name = profile.Name}, // The user must explicitly specify a profile in the top-level `quality_profiles` section of // their config, otherwise we do not implicitly create them in the service. ShouldCreate = false diff --git a/src/tests/Recyclarr.Cli.TestLibrary/NewQp.cs b/src/tests/Recyclarr.Cli.TestLibrary/NewQp.cs index 62b94249..4f4b530a 100644 --- a/src/tests/Recyclarr.Cli.TestLibrary/NewQp.cs +++ b/src/tests/Recyclarr.Cli.TestLibrary/NewQp.cs @@ -29,12 +29,22 @@ public static class NewQp bool resetUnmatchedScores, params (string CfName, string TrashId, int FormatId, int Score)[] scores) { - return new ProcessedQualityProfileData(new QualityProfileConfig + var profileConfig = new QualityProfileConfig { Name = profileName, ResetUnmatchedScores = resetUnmatchedScores - }) + }; + + return Processed(profileConfig, scores); + } + + public static ProcessedQualityProfileData Processed( + QualityProfileConfig profileConfig, + params (string CfName, string TrashId, int FormatId, int Score)[] scores) + { + return new ProcessedQualityProfileData { + Profile = profileConfig, CfScores = scores .Select(x => new ProcessedQualityProfileScore(x.TrashId, x.CfName, x.FormatId, x.Score)) .ToList() diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/PipelinePhases/QualityProfileTransactionPhaseTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/PipelinePhases/QualityProfileTransactionPhaseTest.cs index 9b4ca2d7..2c29f207 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/PipelinePhases/QualityProfileTransactionPhaseTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/PipelinePhases/QualityProfileTransactionPhaseTest.cs @@ -53,14 +53,17 @@ public class QualityProfileTransactionPhaseTest { var configData = new[] { - new ProcessedQualityProfileData(new QualityProfileConfig + new ProcessedQualityProfileData { - Name = "profile1", - Qualities = new[] + Profile = new QualityProfileConfig { - new QualityProfileQualityConfig {Name = "quality1", Enabled = true} + Name = "profile1", + Qualities = new[] + { + new QualityProfileQualityConfig {Name = "quality1", Enabled = true} + } } - }) + } }; var dtos = new[] diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs index 4cf2d413..07e7b1f1 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs @@ -15,14 +15,8 @@ public class UpdatedQualityProfileTest { var profile = new UpdatedQualityProfile { - ProfileDto = new QualityProfileDto - { - Name = "dto_name" - }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig - { - Name = "config_name" - }), + ProfileDto = new QualityProfileDto {Name = "dto_name"}, + ProfileConfig = NewQp.Processed("config_name"), UpdateReason = QualityProfileUpdateReason.New }; @@ -35,10 +29,7 @@ public class UpdatedQualityProfileTest var profile = new UpdatedQualityProfile { ProfileDto = new QualityProfileDto(), - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig - { - Name = "config_name" - }), + ProfileConfig = NewQp.Processed("config_name"), UpdateReason = QualityProfileUpdateReason.New }; @@ -59,7 +50,7 @@ public class UpdatedQualityProfileTest UpgradeAllowed = false, Cutoff = 1 }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig + ProfileConfig = NewQp.Processed(new QualityProfileConfig { Name = "config_name", MinFormatScore = 110, @@ -109,7 +100,7 @@ public class UpdatedQualityProfileTest NewQp.QualityDto(9, "Quality Item 9", true) } }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig()), + ProfileConfig = NewQp.Processed(""), UpdatedQualities = new UpdatedQualities { NumWantedItems = 0, @@ -135,7 +126,7 @@ public class UpdatedQualityProfileTest var profile = new UpdatedQualityProfile { ProfileDto = new QualityProfileDto {Name = ""}, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig {Name = "config_name"}), + ProfileConfig = NewQp.Processed("config_name"), UpdatedQualities = new UpdatedQualities { Items = new[] @@ -164,7 +155,7 @@ public class UpdatedQualityProfileTest NewQp.QualityDto(9, "Quality Item 9", true) } }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig + ProfileConfig = NewQp.Processed(new QualityProfileConfig { UpgradeUntilQuality = "Quality Item 2" }), @@ -200,7 +191,7 @@ public class UpdatedQualityProfileTest NewQp.QualityDto(9, "Quality Item 9", true) } }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig + ProfileConfig = NewQp.Processed(new QualityProfileConfig { UpgradeUntilQuality = "Quality Item 9" }), @@ -236,8 +227,9 @@ public class UpdatedQualityProfileTest NewQp.QualityDto(9, "Quality Item 9", true) } }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig + ProfileConfig = NewQp.Processed(new QualityProfileConfig { + // todo: Why is this commented out? // UpgradeUntilQuality = "Quality Item 9" }), UpdatedQualities = new UpdatedQualities diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileValidatorTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileValidatorTest.cs index 392c7ac6..81c1aa5b 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileValidatorTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileValidatorTest.cs @@ -28,7 +28,7 @@ public class UpdatedQualityProfileValidatorTest NewQp.UpdatedScore("foo4", 0, 100, FormatScoreUpdateReason.Reset) }, ProfileDto = new QualityProfileDto {Name = "ProfileName"}, - ProfileConfig = new ProcessedQualityProfileData(profileConfig), + ProfileConfig = NewQp.Processed(profileConfig), UpdateReason = QualityProfileUpdateReason.Changed }; @@ -65,7 +65,7 @@ public class UpdatedQualityProfileValidatorTest InvalidQualityNames = new[] {"foo1"} }, ProfileDto = new QualityProfileDto(), - ProfileConfig = new ProcessedQualityProfileData(profileConfig), + ProfileConfig = NewQp.Processed(profileConfig), UpdateReason = QualityProfileUpdateReason.New }; @@ -84,7 +84,7 @@ public class UpdatedQualityProfileValidatorTest var updatedProfile = new UpdatedQualityProfile { ProfileDto = new QualityProfileDto(), - ProfileConfig = new ProcessedQualityProfileData(profileConfig), + ProfileConfig = NewQp.Processed(profileConfig), UpdateReason = QualityProfileUpdateReason.New }; @@ -112,7 +112,7 @@ public class UpdatedQualityProfileValidatorTest NewQp.QualityDto(1, "disabled_quality", false) } }, - ProfileConfig = new ProcessedQualityProfileData(profileConfig), + ProfileConfig = NewQp.Processed(profileConfig), UpdateReason = QualityProfileUpdateReason.New };