From b3be9088fe9ccf9abe2cac438e96027f9986032d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 1 Oct 2019 09:26:07 +0200 Subject: [PATCH] Add test to make sure user emails are really unique Signed-off-by: Thomas Citharel --- .../resolvers/user_resolver_test.exs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/mobilizon_web/resolvers/user_resolver_test.exs b/test/mobilizon_web/resolvers/user_resolver_test.exs index 338de03c4..e6324d651 100644 --- a/test/mobilizon_web/resolvers/user_resolver_test.exs +++ b/test/mobilizon_web/resolvers/user_resolver_test.exs @@ -275,6 +275,44 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do @user_creation.username end + test "create_user/3 doesn't allow two users with the same email", %{conn: conn} do + mutation = """ + mutation { + createUser( + email: "#{@user_creation.email}", + password: "#{@user_creation.password}", + ) { + id, + email + } + } + """ + + res = + conn + |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) + + assert json_response(res, 200)["data"]["createUser"]["email"] == @user_creation.email + + mutation = """ + mutation { + createUser( + email: "#{@user_creation.email}", + password: "#{@user_creation.password}", + ) { + id, + email + } + } + """ + + res = + conn + |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) + + assert hd(json_response(res, 200)["errors"])["message"] == "This email is already used." + end + test "register_person/3 doesn't register a profile from an unknown email", context do mutation = """ mutation { @@ -429,7 +467,6 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do end describe "Resolver: Validate an user" do - @valid_actor_params %{email: "test@test.tld", password: "testest"} test "test validate_user/3 validates an user", context do {:ok, %User{} = user} = Users.register(@valid_actor_params)