For most CF specifications, there is only one element in the `fields` array, which has a `value` property inside of each of its objects. One particular specification, however, deviates from this assumption. The "SizeSpecification" has been observed with *two* field objects. Logic for parsing custom format CFs no longer assumes that the fields property may only have one element in it. Fixes #178pull/201/head
parent
bebd28bc11
commit
9d53fd0152
@ -0,0 +1,27 @@
|
|||||||
|
using Flurl.Http.Testing;
|
||||||
|
using Recyclarr.Cli.TestLibrary;
|
||||||
|
using Recyclarr.Common;
|
||||||
|
using Recyclarr.TrashLib.Config.Services;
|
||||||
|
using Recyclarr.TrashLib.Pipelines.CustomFormat.Api;
|
||||||
|
|
||||||
|
namespace Recyclarr.TrashLib.Tests.Pipelines.CustomFormat.Api;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
[Parallelizable(ParallelScope.All)]
|
||||||
|
public class CustomFormatServiceTest : IntegrationFixture
|
||||||
|
{
|
||||||
|
[Test, AutoMockData]
|
||||||
|
public async Task Get_can_parse_json(IServiceConfiguration config)
|
||||||
|
{
|
||||||
|
var resourceData = new ResourceDataReader(typeof(CustomFormatServiceTest), "Data");
|
||||||
|
var jsonBody = resourceData.ReadData("issue_178.json");
|
||||||
|
|
||||||
|
using var http = new HttpTest();
|
||||||
|
http.RespondWith(jsonBody);
|
||||||
|
|
||||||
|
var sut = Resolve<CustomFormatService>();
|
||||||
|
var result = await sut.GetCustomFormats(config);
|
||||||
|
|
||||||
|
result.Should().HaveCountGreaterThan(5);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
|||||||
|
using Flurl.Http.Configuration;
|
||||||
|
using Recyclarr.TrashLib.Json;
|
||||||
|
using Recyclarr.TrashLib.Pipelines.CustomFormat.Models;
|
||||||
|
|
||||||
|
namespace Recyclarr.TrashLib.Tests.Pipelines.CustomFormat.Models;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
[Parallelizable(ParallelScope.All)]
|
||||||
|
public class FieldsArrayJsonConverterTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Read_multiple_as_array()
|
||||||
|
{
|
||||||
|
var serializer = new NewtonsoftJsonSerializer(ServiceJsonSerializerFactory.Settings);
|
||||||
|
|
||||||
|
const string json = @"
|
||||||
|
{
|
||||||
|
'fields': [
|
||||||
|
{
|
||||||
|
'order': 0,
|
||||||
|
'name': 'min',
|
||||||
|
'label': 'Minimum Size',
|
||||||
|
'unit': 'GB',
|
||||||
|
'helpText': 'Release must be greater than this size',
|
||||||
|
'value': 25,
|
||||||
|
'type': 'number',
|
||||||
|
'advanced': false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'order': 1,
|
||||||
|
'name': 'max',
|
||||||
|
'label': 'Maximum Size',
|
||||||
|
'unit': 'GB',
|
||||||
|
'helpText': 'Release must be less than or equal to this size',
|
||||||
|
'value': 40,
|
||||||
|
'type': 'number',
|
||||||
|
'advanced': false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
";
|
||||||
|
var result = serializer.Deserialize<CustomFormatSpecificationData>(json);
|
||||||
|
|
||||||
|
result.Fields.Should().BeEquivalentTo(new[]
|
||||||
|
{
|
||||||
|
new CustomFormatFieldData
|
||||||
|
{
|
||||||
|
Value = 25
|
||||||
|
},
|
||||||
|
new CustomFormatFieldData
|
||||||
|
{
|
||||||
|
Value = 40
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Read_single_as_array()
|
||||||
|
{
|
||||||
|
var serializer = new NewtonsoftJsonSerializer(ServiceJsonSerializerFactory.Settings);
|
||||||
|
|
||||||
|
const string json = @"
|
||||||
|
{
|
||||||
|
'fields': {
|
||||||
|
'order': 0,
|
||||||
|
'name': 'min',
|
||||||
|
'label': 'Minimum Size',
|
||||||
|
'unit': 'GB',
|
||||||
|
'helpText': 'Release must be greater than this size',
|
||||||
|
'value': 25,
|
||||||
|
'type': 'number',
|
||||||
|
'advanced': false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
var result = serializer.Deserialize<CustomFormatSpecificationData>(json);
|
||||||
|
|
||||||
|
result.Fields.Should().BeEquivalentTo(new[]
|
||||||
|
{
|
||||||
|
new CustomFormatFieldData
|
||||||
|
{
|
||||||
|
Value = 25
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Read_throws_on_unsupported_token_type()
|
||||||
|
{
|
||||||
|
var serializer = new NewtonsoftJsonSerializer(ServiceJsonSerializerFactory.Settings);
|
||||||
|
|
||||||
|
const string json = @"
|
||||||
|
{
|
||||||
|
'fields': 0
|
||||||
|
}
|
||||||
|
";
|
||||||
|
var act = () => serializer.Deserialize<CustomFormatSpecificationData>(json);
|
||||||
|
|
||||||
|
act.Should().Throw<InvalidOperationException>();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue