You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
449 lines
14 KiB
449 lines
14 KiB
2 years ago
|
using Recyclarr.Cli.Pipelines.QualityProfile;
|
||
|
using Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases;
|
||
1 year ago
|
using Recyclarr.Config.Models;
|
||
1 year ago
|
using Recyclarr.ServarrApi.QualityProfile;
|
||
2 years ago
|
|
||
2 years ago
|
namespace Recyclarr.Cli.Tests.Pipelines.QualityProfile.PipelinePhases;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
|
public class QualityProfileTransactionPhaseTest
|
||
|
{
|
||
|
[Test, AutoMockData]
|
||
2 years ago
|
public void Non_existent_profile_names_with_updated(
|
||
2 years ago
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
1 year ago
|
NewQp.Processed("invalid_profile_name") with
|
||
2 years ago
|
{
|
||
|
ShouldCreate = false
|
||
|
},
|
||
1 year ago
|
NewQp.Processed("profile1")
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new QualityProfileDto {Name = "profile1"}
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new QualityProfileTransactionData
|
||
1 year ago
|
{
|
||
|
NonExistentProfiles = new[] {"invalid_profile_name"},
|
||
|
UpdatedProfiles =
|
||
2 years ago
|
{
|
||
1 year ago
|
new UpdatedQualityProfile
|
||
2 years ago
|
{
|
||
1 year ago
|
ProfileConfig = guideData[1],
|
||
|
ProfileDto = dtos[0],
|
||
|
UpdateReason = QualityProfileUpdateReason.Changed
|
||
2 years ago
|
}
|
||
1 year ago
|
}
|
||
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void New_profiles(
|
||
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
1 year ago
|
var configData = new[]
|
||
2 years ago
|
{
|
||
1 year ago
|
new ProcessedQualityProfileData
|
||
1 year ago
|
{
|
||
1 year ago
|
Profile = new QualityProfileConfig
|
||
1 year ago
|
{
|
||
1 year ago
|
Name = "profile1",
|
||
|
Qualities = new[]
|
||
|
{
|
||
|
new QualityProfileQualityConfig {Name = "quality1", Enabled = true}
|
||
|
}
|
||
1 year ago
|
}
|
||
1 year ago
|
}
|
||
2 years ago
|
};
|
||
|
|
||
|
var dtos = new[]
|
||
|
{
|
||
|
new QualityProfileDto {Name = "irrelevant_profile"}
|
||
|
};
|
||
|
|
||
1 year ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto())
|
||
|
{
|
||
|
Schema = new QualityProfileDto
|
||
|
{
|
||
|
Items = new[]
|
||
|
{
|
||
|
new ProfileItemDto {Quality = new ProfileItemQualityDto {Name = "quality1"}}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
2 years ago
|
|
||
1 year ago
|
var result = sut.Execute(configData, serviceData);
|
||
2 years ago
|
|
||
|
result.Should().BeEquivalentTo(new QualityProfileTransactionData
|
||
1 year ago
|
{
|
||
|
UpdatedProfiles =
|
||
2 years ago
|
{
|
||
1 year ago
|
new UpdatedQualityProfile
|
||
2 years ago
|
{
|
||
1 year ago
|
ProfileConfig = configData[0],
|
||
|
ProfileDto = serviceData.Schema,
|
||
|
UpdateReason = QualityProfileUpdateReason.New,
|
||
|
UpdatedQualities = new UpdatedQualities
|
||
2 years ago
|
{
|
||
1 year ago
|
NumWantedItems = 1,
|
||
|
Items = new[]
|
||
|
{
|
||
|
new ProfileItemDto
|
||
|
{
|
||
|
Allowed = true,
|
||
|
Quality = new ProfileItemQualityDto
|
||
|
{
|
||
|
Name = "quality1"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
1 year ago
|
}
|
||
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Updated_scores(
|
||
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
2 years ago
|
NewQp.Processed("profile1", ("id1", 1, 100), ("id2", 2, 500))
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
2 years ago
|
FormatItems = new[]
|
||
2 years ago
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
2 years ago
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.UpdatedScores.Should()
|
||
|
.BeEquivalentTo(new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
NewQp.UpdatedScore("quality1", 200, 100, FormatScoreUpdateReason.Updated),
|
||
|
NewQp.UpdatedScore("quality2", 300, 500, FormatScoreUpdateReason.Updated)
|
||
|
}, o => o.Excluding(x => x.Dto.Format));
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void No_updated_profiles_when_no_custom_formats(
|
||
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = Array.Empty<ProcessedQualityProfileData>();
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
2 years ago
|
FormatItems = new[]
|
||
2 years ago
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
|
result.Should().BeEquivalentTo(new QualityProfileTransactionData());
|
||
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
2 years ago
|
public void Unchanged_scores(
|
||
2 years ago
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
// Must simulate at least 1 custom format coming from configuration otherwise processing doesn't happen.
|
||
|
// Profile name must match but the format IDs for each quality should not
|
||
|
var guideData = new[]
|
||
|
{
|
||
2 years ago
|
NewQp.Processed("profile1", ("id1", 1, 200), ("id2", 2, 300))
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
2 years ago
|
FormatItems = new[]
|
||
2 years ago
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
2 years ago
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.UpdatedScores.Should()
|
||
|
.BeEquivalentTo(new[]
|
||
|
{
|
||
|
NewQp.UpdatedScore("quality1", 200, 200, FormatScoreUpdateReason.NoChange),
|
||
|
NewQp.UpdatedScore("quality2", 300, 300, FormatScoreUpdateReason.NoChange)
|
||
|
}, o => o.Excluding(x => x.Dto.Format));
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
2 years ago
|
public void Reset_scores_with_reset_unmatched_true(
|
||
2 years ago
|
QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
2 years ago
|
NewQp.Processed("profile1", true, ("quality3", "id3", 3, 100), ("quality4", "id4", 4, 500))
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
2 years ago
|
FormatItems = new[]
|
||
2 years ago
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "quality2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
2 years ago
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.UpdatedScores.Should()
|
||
|
.BeEquivalentTo(new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
NewQp.UpdatedScore("quality1", 200, 0, FormatScoreUpdateReason.Reset),
|
||
|
NewQp.UpdatedScore("quality2", 300, 0, FormatScoreUpdateReason.Reset),
|
||
|
NewQp.UpdatedScore("quality3", 0, 100, FormatScoreUpdateReason.New),
|
||
|
NewQp.UpdatedScore("quality4", 0, 500, FormatScoreUpdateReason.New)
|
||
|
}, o => o.Excluding(x => x.Dto.Format));
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Reset_scores_with_reset_unmatched_false(QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
1 year ago
|
NewQp.Processed(new QualityProfileConfig
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
ResetUnmatchedScores = new ResetUnmatchedScoresConfig
|
||
|
{
|
||
|
Enabled = false,
|
||
|
// Throw in some exceptions here, just to test whether or not these somehow affect the result
|
||
|
// despite Enable being set to false.
|
||
|
Except = new[] {"cf1"}
|
||
|
}
|
||
|
},
|
||
|
("cf3", "id3", 3, 100), ("cf4", "id4", 4, 500))
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
var dtos = new[]
|
||
2 years ago
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
FormatItems = new[]
|
||
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
1 year ago
|
Name = "cf1",
|
||
2 years ago
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
1 year ago
|
Name = "cf2",
|
||
2 years ago
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
2 years ago
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.UpdatedScores.Should()
|
||
|
.BeEquivalentTo(new[]
|
||
|
{
|
||
1 year ago
|
NewQp.UpdatedScore("cf1", 200, 200, FormatScoreUpdateReason.NoChange),
|
||
|
NewQp.UpdatedScore("cf2", 300, 300, FormatScoreUpdateReason.NoChange),
|
||
|
NewQp.UpdatedScore("cf3", 0, 100, FormatScoreUpdateReason.New),
|
||
|
NewQp.UpdatedScore("cf4", 0, 500, FormatScoreUpdateReason.New)
|
||
|
}, o => o.Excluding(x => x.Dto.Format));
|
||
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Reset_scores_with_reset_exceptions(QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
|
NewQp.Processed(new QualityProfileConfig
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
ResetUnmatchedScores = new ResetUnmatchedScoresConfig
|
||
|
{
|
||
|
Enabled = true,
|
||
|
Except = new[] {"cf1"}
|
||
|
}
|
||
|
},
|
||
|
("cf3", "id3", 3, 100), ("cf4", "id4", 4, 500))
|
||
|
};
|
||
|
|
||
|
var dtos = new[]
|
||
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
FormatItems = new[]
|
||
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "cf1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "cf2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.UpdatedScores.Should()
|
||
|
.BeEquivalentTo(new[]
|
||
|
{
|
||
|
NewQp.UpdatedScore("cf1", 200, 200, FormatScoreUpdateReason.NoChange),
|
||
|
NewQp.UpdatedScore("cf2", 300, 0, FormatScoreUpdateReason.Reset),
|
||
|
NewQp.UpdatedScore("cf3", 0, 100, FormatScoreUpdateReason.New),
|
||
|
NewQp.UpdatedScore("cf4", 0, 500, FormatScoreUpdateReason.New)
|
||
2 years ago
|
}, o => o.Excluding(x => x.Dto.Format));
|
||
|
}
|
||
1 year ago
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Reset_scores_with_invalid_except_list_items(QualityProfileTransactionPhase sut)
|
||
|
{
|
||
|
var guideData = new[]
|
||
|
{
|
||
|
NewQp.Processed(new QualityProfileConfig
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
ResetUnmatchedScores = new ResetUnmatchedScoresConfig
|
||
|
{
|
||
|
Enabled = true,
|
||
|
Except = new[] {"cf50"}
|
||
|
}
|
||
|
})
|
||
|
};
|
||
|
|
||
|
var dtos = new[]
|
||
|
{
|
||
|
new QualityProfileDto
|
||
|
{
|
||
|
Name = "profile1",
|
||
|
FormatItems = new[]
|
||
|
{
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "cf1",
|
||
|
Format = 1,
|
||
|
Score = 200
|
||
|
},
|
||
|
new ProfileFormatItemDto
|
||
|
{
|
||
|
Name = "cf2",
|
||
|
Format = 2,
|
||
|
Score = 300
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var serviceData = new QualityProfileServiceData(dtos, new QualityProfileDto());
|
||
|
|
||
|
var result = sut.Execute(guideData, serviceData);
|
||
|
|
||
|
result.UpdatedProfiles.Should()
|
||
|
.ContainSingle().Which.InvalidExceptCfNames.Should()
|
||
|
.BeEquivalentTo("cf50");
|
||
|
}
|
||
2 years ago
|
}
|