Format
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
b54dae7e15
commit
10dddc03a9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -131,7 +131,6 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||
|
||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
||||
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
|
||||
|
||||
{: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
|
||||
|
Loading…
Reference in New Issue
Block a user