mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-19 06:42:47 +12:00
test_case for nested union types (#199)
This commit is contained in:
parent
acc376bf5f
commit
ac622715bb
3 changed files with 83 additions and 0 deletions
|
@ -97,6 +97,38 @@ defmodule AshPhoenix.AutoFormTest do
|
|||
|> AshPhoenix.Form.add_form(:union, params: %{"_union_type" => "bar", "value" => 10})
|
||||
|> AshPhoenix.Form.submit!()
|
||||
end
|
||||
|
||||
test "my test" do
|
||||
AshPhoenix.Test.DeepNestedUnionResource
|
||||
|> AshPhoenix.Form.for_create(:create,
|
||||
domain: Domain,
|
||||
forms: [
|
||||
auto?: true
|
||||
]
|
||||
)
|
||||
|> AshPhoenix.Form.add_form(:items,
|
||||
params: %{"subject" => %{"_union_type" => "predefined"}}
|
||||
)
|
||||
# |> AshPhoenix.Form.add_form(:union_array)
|
||||
|> AshPhoenix.Form.submit!(
|
||||
params: %{
|
||||
"items" => %{
|
||||
"0" => %{
|
||||
"_form_type" => "create",
|
||||
"_persistent_id" => "0",
|
||||
"_touched" => "_form_type,_persistent_id,_touched,subject",
|
||||
"subject" => %{
|
||||
"_form_type" => "create",
|
||||
"_persistent_id" => "0",
|
||||
"_touched" => "_form_type,_persistent_id,_touched,_union_type,value",
|
||||
"_union_type" => "predefined",
|
||||
"value" => "test"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "list unions" do
|
||||
|
|
|
@ -10,5 +10,6 @@ defmodule AshPhoenix.Test.Domain do
|
|||
resource(AshPhoenix.Test.PostLink)
|
||||
resource(AshPhoenix.Test.PostWithDefault)
|
||||
resource(AshPhoenix.Test.User)
|
||||
resource(AshPhoenix.Test.DeepNestedUnionResource)
|
||||
end
|
||||
end
|
||||
|
|
50
test/support/resources/deep_nested_union_resource.ex
Normal file
50
test/support/resources/deep_nested_union_resource.ex
Normal file
|
@ -0,0 +1,50 @@
|
|||
defmodule DeepNestedUnionResource.Union do
|
||||
use Ash.Type.NewType,
|
||||
subtype_of: :union,
|
||||
constraints: [
|
||||
types: [
|
||||
predefined: [
|
||||
type: :atom,
|
||||
constraints: [one_of: [:update]]
|
||||
],
|
||||
custom: [
|
||||
type: :string
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
defmodule DeepNestedUnionResource.Wrapper do
|
||||
use Ash.Resource,
|
||||
data_layer: :embedded
|
||||
|
||||
attributes do
|
||||
attribute :subject, DeepNestedUnionResource.Union,
|
||||
allow_nil?: false,
|
||||
public?: true
|
||||
end
|
||||
end
|
||||
|
||||
defmodule AshPhoenix.Test.DeepNestedUnionResource do
|
||||
use Ash.Resource,
|
||||
domain: AshPhoenix.Test.Domain,
|
||||
data_layer: Ash.DataLayer.Ets
|
||||
|
||||
ets do
|
||||
private?(true)
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key(:id, public?: true)
|
||||
attribute(:items, {:array, DeepNestedUnionResource.Wrapper}, public?: true)
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [
|
||||
:read,
|
||||
:destroy,
|
||||
create: [:items],
|
||||
update: [:items]
|
||||
]
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue