mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-19 06:42:47 +12:00
test: unions test case for primitive subtype (#203)
This commit is contained in:
parent
1eba24b5d5
commit
2a74d91618
3 changed files with 58 additions and 1 deletions
|
@ -2,7 +2,7 @@ defmodule AshPhoenix.AutoFormTest do
|
|||
use ExUnit.Case
|
||||
|
||||
alias AshPhoenix.Form.Auto
|
||||
alias AshPhoenix.Test.{Domain, Post}
|
||||
alias AshPhoenix.Test.{Domain, Post, SimplePost}
|
||||
import AshPhoenix.Form, only: [update_opts: 2]
|
||||
|
||||
defp form_for(a, _b), do: Phoenix.HTML.FormData.to_form(a, [])
|
||||
|
@ -98,6 +98,21 @@ defmodule AshPhoenix.AutoFormTest do
|
|||
|> AshPhoenix.Form.submit!()
|
||||
end
|
||||
|
||||
test "simple unions" do
|
||||
SimplePost
|
||||
|> AshPhoenix.Form.for_create(:create,
|
||||
domain: Domain,
|
||||
forms: [
|
||||
auto?: true
|
||||
],
|
||||
params: %{
|
||||
"text" => "foobar"
|
||||
}
|
||||
)
|
||||
|> AshPhoenix.Form.add_form(:union, params: %{"type" => "custom"})
|
||||
|> AshPhoenix.Form.submit!()
|
||||
end
|
||||
|
||||
test "deeply nested unions" do
|
||||
# AshPhoenix.Test.DeepNestedUnionResource
|
||||
# |> AshPhoenix.Form.for_create(:create,
|
||||
|
|
|
@ -11,5 +11,6 @@ defmodule AshPhoenix.Test.Domain do
|
|||
resource(AshPhoenix.Test.PostWithDefault)
|
||||
resource(AshPhoenix.Test.User)
|
||||
resource(AshPhoenix.Test.DeepNestedUnionResource)
|
||||
resource(AshPhoenix.Test.SimplePost)
|
||||
end
|
||||
end
|
||||
|
|
41
test/support/resources/simple_post.ex
Normal file
41
test/support/resources/simple_post.ex
Normal file
|
@ -0,0 +1,41 @@
|
|||
defmodule AshPhoenix.Test.SimplePost.SimpleUnion do
|
||||
use Ash.Type.NewType,
|
||||
subtype_of: :union,
|
||||
constraints: [
|
||||
types: [
|
||||
predefined: [
|
||||
type: :atom,
|
||||
constraints: [one_of: [:update]],
|
||||
tag: :type,
|
||||
tag_value: :predefined,
|
||||
cast_tag?: true
|
||||
],
|
||||
custom: [
|
||||
type: :string,
|
||||
tag: :type,
|
||||
tag_value: :custom,
|
||||
cast_tag?: true
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
defmodule AshPhoenix.Test.SimplePost 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(:union, AshPhoenix.Test.SimplePost.SimpleUnion, public?: true)
|
||||
end
|
||||
|
||||
actions do
|
||||
default_accept(:*)
|
||||
defaults([:create])
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue