fix: support only predicate in params

This commit is contained in:
Zach Daniel 2021-12-05 20:24:08 -05:00
parent 032f7d6850
commit 4c4ca71609
2 changed files with 9 additions and 5 deletions

View file

@ -87,18 +87,18 @@ defmodule AshPhoenix.FilterForm do
At present, no validation actually occurs, but this will eventually be added.
"""
def validate(form, params \\ %{}) do
params = sanitize_params(params)
params =
if is_predicate?(params) do
%{
operator: :and,
components: %{"0" => params}
"operator" => "and",
"components" => %{"0" => params}
}
else
params
end
params = sanitize_params(params)
%{
form
| params: params,

View file

@ -77,7 +77,11 @@ defmodule AshPhoenix.FilterFormTest do
describe "to_filter/1" do
test "An empty form returns the filter `true`" do
form = FilterForm.new(Post)
assert Ash.Query.equivalent_to?(FilterForm.filter!(Post, form), true)
assert Ash.Query.equivalent_to?(
FilterForm.filter!(Post, form),
true
)
end
test "A form with a single predicate returns the corresponding filter" do