Created
June 3, 2016 23:51
-
-
Save cesarandreu/0ac99604de4b29a3070d7d0dc1ae9f40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App.SignUpMutationTest do | |
use App.MutationCase, async: true | |
defp mutation({query, input}) do | |
body = Poison.encode!(%{ | |
query: query, | |
variables: %{input: input} | |
}) | |
build_conn() | |
|> put_req_header("accept", "application/json") | |
|> put_req_header("content-type", "application/json") | |
|> post("/api/graphql", body) | |
|> json_response(200) | |
end | |
@sign_up_mutation """ | |
mutation SignUpMutation($input:SignUpInput!) { | |
sign_up(input: $input) { | |
client_mutation_id | |
errors { | |
field, | |
messages | |
} | |
user { | |
display_name | |
} | |
} | |
} | |
""" | |
@sign_up_valid %{ | |
client_mutation_id: "1", | |
display_name: "Bob", | |
email: "bob@example.com", | |
password: "123456", | |
password_confirmation: "123456" | |
} | |
@sign_up_invalid %{ | |
client_mutation_id: "1", | |
display_name: "Bob", | |
email: "bob@example.com", | |
password: "12345", | |
password_confirmation: "12345" | |
} | |
test "sign_up mutation succeeds and includes user" do | |
assert mutation({@sign_up_mutation, @sign_up_valid}) == %{ | |
"data" => %{ | |
"sign_up" => %{ | |
"client_mutation_id" => "1", | |
"errors" => nil, | |
"user" => %{ | |
"display_name" => "Bob" | |
} | |
} | |
} | |
} | |
end | |
test "sign_up mutation fails and shows validation errors" do | |
assert mutation({@sign_up_mutation, @sign_up_invalid}) == %{ | |
"data" => %{ | |
"sign_up" => %{ | |
"client_mutation_id" => "1", | |
"errors" => [%{ | |
"field" => "password", | |
"messages" => ["should be at least 6 character(s)"] | |
}], | |
"user" => nil | |
} | |
} | |
} | |
end | |
test "sign_up mutation sends jwt token" do | |
query = """ | |
mutation SignUpMutation($input:SignUpInput!) { | |
sign_up(input: $input) { | |
jwt | |
} | |
} | |
""" | |
assert mutation({query, @sign_up_valid}) | |
|> get_in(["data", "sign_up", "jwt"]) | |
|> is_binary | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment