Browse Source

Accept default operator.

pull/848/head
Sebastian 4 years ago
parent
commit
2c78baf399
  1. 4
      backend/src/Squidex.Infrastructure/Queries/Json/JsonFilterSurrogate.cs
  2. 18
      backend/tests/Squidex.Infrastructure.Tests/Queries/QueryJsonTests.cs

4
backend/src/Squidex.Infrastructure/Queries/Json/JsonFilterSurrogate.cs

@ -46,9 +46,9 @@ namespace Squidex.Infrastructure.Queries.Json
return new LogicalFilter<IJsonValue>(LogicalFilterType.Or, Or);
}
if (!string.IsNullOrWhiteSpace(Path) && Op != null)
if (!string.IsNullOrWhiteSpace(Path))
{
return new CompareFilter<IJsonValue>(Path, Op.Value, Value ?? JsonValue.Null);
return new CompareFilter<IJsonValue>(Path, Op ?? CompareOperator.Equals, Value ?? JsonValue.Null);
}
throw new JsonException(Errors.InvalidJsonStructure());

18
backend/tests/Squidex.Infrastructure.Tests/Queries/QueryJsonTests.cs

@ -38,6 +38,16 @@ namespace Squidex.Infrastructure.Queries
Assert.Equal(expected, filter.ToString());
}
[Fact]
public void Should_convert_comparison_without_operator()
{
var json = new { path = "property" };
var filter = SerializeAndDeserialize(json);
Assert.Equal("property == null", filter.ToString());
}
[Fact]
public void Should_convert_comparison_empty()
{
@ -141,14 +151,6 @@ namespace Squidex.Infrastructure.Queries
Assert.ThrowsAny<JsonException>(() => SerializeAndDeserialize(json));
}
[Fact]
public void Should_throw_exception_for_missing_operator()
{
var json = new { path = "property", value = 12 };
Assert.ThrowsAny<JsonException>(() => SerializeAndDeserialize(json));
}
[Fact]
public void Should_throw_exception_for_missing_value()
{

Loading…
Cancel
Save