ash_graphql/test/create_test.exs
Zach Daniel fbfdb7faf8 feat: update to latest ash
feat: support query arguments
2021-01-21 23:06:06 -05:00

74 lines
1.5 KiB
Elixir

defmodule AshGraphql.CreateTest do
use ExUnit.Case, async: false
setup do
on_exit(fn ->
try do
ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Post))
rescue
_ ->
:ok
end
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 =~ "Confirmation did not match value"
end
end