ash_graphql/test/create_test.exs

71 lines
1.5 KiB
Elixir
Raw Normal View History

2020-12-02 18:07:15 +13:00
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
2020-12-02 18:07:15 +13:00
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
2020-12-30 09:11:16 +13:00
assert message =~ "Value did not match confirmation"
2020-12-02 18:07:15 +13:00
end
end