mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 13:24:14 +12:00
70 lines
1.5 KiB
Elixir
70 lines
1.5 KiB
Elixir
defmodule AshGraphql.CreateTest do
|
|
use ExUnit.Case, async: false
|
|
|
|
setup do
|
|
on_exit(fn ->
|
|
nil
|
|
# ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Post))
|
|
end)
|
|
end
|
|
|
|
test "a create with arguments works" do
|
|
resp =
|
|
"""
|
|
mutation CreatePost($input: CreatePostInput) {
|
|
createPost(input: $input) {
|
|
result{
|
|
text
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|> Absinthe.run(AshGraphql.Test.Schema,
|
|
variables: %{
|
|
"input" => %{
|
|
"text" => "foobar",
|
|
"confirmation" => "foobar"
|
|
}
|
|
}
|
|
)
|
|
|
|
assert {:ok, result} = resp
|
|
|
|
refute Map.has_key?(result, :errors)
|
|
assert %{data: %{"createPost" => %{"result" => %{"text" => "foobar"}}}} = result
|
|
end
|
|
|
|
test "arguments are threaded properly" do
|
|
resp =
|
|
"""
|
|
mutation CreatePost($input: CreatePostInput) {
|
|
createPost(input: $input) {
|
|
result{
|
|
text
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|> Absinthe.run(AshGraphql.Test.Schema,
|
|
variables: %{
|
|
"input" => %{
|
|
"text" => "foobar",
|
|
"confirmation" => "foobar2"
|
|
}
|
|
}
|
|
)
|
|
|
|
assert {:ok, result} = resp
|
|
|
|
assert %{data: %{"createPost" => %{"result" => nil, "errors" => [%{"message" => message}]}}} =
|
|
result
|
|
|
|
assert message =~ "Value did not match confirmation"
|
|
end
|
|
end
|