From 10dddc03a9aae23e6e78a8f0719d8619c458ffcf Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 6 Nov 2018 10:32:53 +0100 Subject: [PATCH] Format Signed-off-by: Thomas Citharel --- lib/mobilizon/actors/actors.ex | 3 +- lib/mobilizon_web/resolvers/user.ex | 8 +++-- test/mobilizon/actors/actors_test.exs | 7 ++-- .../resolvers/user_resolver_test.exs | 34 +++++++++---------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 6dfb773fa..e1c665643 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -453,7 +453,8 @@ defmodule Mobilizon.Actors do {msg, opts} -> msg msg -> msg end) - {:error, hd(Map.get(changeset, :email))} + + {:error, hd(Map.get(changeset, :email))} end def register_bot_account(%{name: name, summary: summary}) do diff --git a/lib/mobilizon_web/resolvers/user.ex b/lib/mobilizon_web/resolvers/user.ex index 213d2aaf2..d56a88e5b 100644 --- a/lib/mobilizon_web/resolvers/user.ex +++ b/lib/mobilizon_web/resolvers/user.ex @@ -70,11 +70,13 @@ defmodule MobilizonWeb.Resolvers.User do """ def resend_confirmation_email(_parent, %{email: email, locale: locale}, _resolution) do with {:ok, user} <- Actors.get_user_by_email(email, false), - {:ok, email} <- Mobilizon.Actors.Service.Activation.resend_confirmation_email(user, locale) do + {:ok, email} <- + Mobilizon.Actors.Service.Activation.resend_confirmation_email(user, locale) do {:ok, email} else {:error, :user_not_found} -> {:error, "No user to validate with this email was found"} + {:error, :email_too_soon} -> {:error, "You requested again a confirmation email too soon"} end @@ -85,11 +87,13 @@ defmodule MobilizonWeb.Resolvers.User do """ def send_reset_password(_parent, %{email: email, locale: locale}, _resolution) do with {:ok, user} <- Actors.get_user_by_email(email, false), - {:ok, email} <- Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user, locale) do + {:ok, email} <- + Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user, locale) do {:ok, email} else {:error, :user_not_found} -> {:error, "No user to validate with this email was found"} + {:error, :email_too_soon} -> {:error, "You requested again a confirmation email too soon"} end diff --git a/test/mobilizon/actors/actors_test.exs b/test/mobilizon/actors/actors_test.exs index e7e0e53ef..b4a523694 100644 --- a/test/mobilizon/actors/actors_test.exs +++ b/test/mobilizon/actors/actors_test.exs @@ -337,14 +337,15 @@ defmodule Mobilizon.ActorsTest do test "get_user_by_email/1 finds an activated user by it's email" do {:ok, %Actor{user: %User{email: email} = user} = _actor} = Actors.register(%{email: @email, password: @password, username: "yolo"}) + {:ok, %User{id: id}} = Actors.get_user_by_email(@email, false) assert id == user.id assert {:error, :user_not_found} = Actors.get_user_by_email(@email, true) Actors.update_user(user, %{ - "confirmed_at" => DateTime.utc_now(), - "confirmation_sent_at" => nil, - "confirmation_token" => nil + "confirmed_at" => DateTime.utc_now(), + "confirmation_sent_at" => nil, + "confirmation_token" => nil }) assert {:error, :user_not_found} = Actors.get_user_by_email(@email, false) diff --git a/test/mobilizon_web/resolvers/user_resolver_test.exs b/test/mobilizon_web/resolvers/user_resolver_test.exs index 595583476..784250aa5 100644 --- a/test/mobilizon_web/resolvers/user_resolver_test.exs +++ b/test/mobilizon_web/resolvers/user_resolver_test.exs @@ -130,8 +130,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do end @valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"} - test "test validate_user/3 validates an user", context do - + test "test validate_user/3 validates an user", context do {:ok, actor} = Actors.register(@valid_actor_params) mutation = """ @@ -154,15 +153,14 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do context.conn |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) - assert json_response(res, 200)["data"]["validateUser"]["actor"]["preferredUsername"] == @valid_actor_params.username - + assert json_response(res, 200)["data"]["validateUser"]["actor"]["preferredUsername"] == + @valid_actor_params.username assert json_response(res, 200)["data"]["validateUser"]["user"]["id"] == to_string(actor.user.id) end - test "test validate_user/3 with invalid token doesn't validate an user", context do - + test "test validate_user/3 with invalid token doesn't validate an user", context do {:ok, actor} = Actors.register(@valid_actor_params) mutation = """ @@ -185,7 +183,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do context.conn |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) - assert hd(json_response(res, 200)["errors"])["message"] == "Invalid token" + assert hd(json_response(res, 200)["errors"])["message"] == "Invalid token" end test "test resend_confirmation_email/3 with valid email resends an validation email", context do @@ -203,23 +201,24 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do context.conn |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) - assert hd(json_response(res, 200)["errors"])["message"] == "You requested again a confirmation email too soon" - - # Hammer time ! - Mobilizon.Actors.update_user(actor.user, %{ - confirmation_sent_at: Timex.shift(actor.user.confirmation_sent_at, hours: -3) - }) + assert hd(json_response(res, 200)["errors"])["message"] == + "You requested again a confirmation email too soon" + # Hammer time ! + Mobilizon.Actors.update_user(actor.user, %{ + confirmation_sent_at: Timex.shift(actor.user.confirmation_sent_at, hours: -3) + }) res = context.conn |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) - assert json_response(res, 200)["data"]["resendConfirmationEmail"] == actor.user.email - assert_delivered_email Mobilizon.Email.User.confirmation_email(actor.user) + assert json_response(res, 200)["data"]["resendConfirmationEmail"] == actor.user.email + assert_delivered_email(Mobilizon.Email.User.confirmation_email(actor.user)) end - test "test resend_confirmation_email/3 with invalid email resends an validation email", context do + test "test resend_confirmation_email/3 with invalid email resends an validation email", + context do {:ok, actor} = Actors.register(@valid_actor_params) mutation = """ @@ -234,6 +233,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do context.conn |> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) - assert hd(json_response(res, 200)["errors"])["message"] == "No user to validate with this email was found" + assert hd(json_response(res, 200)["errors"])["message"] == + "No user to validate with this email was found" end end