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, opts} -> msg
|
||||||
msg -> msg
|
msg -> msg
|
||||||
end)
|
end)
|
||||||
{:error, hd(Map.get(changeset, :email))}
|
|
||||||
|
{:error, hd(Map.get(changeset, :email))}
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_bot_account(%{name: name, summary: summary}) do
|
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
|
def resend_confirmation_email(_parent, %{email: email, locale: locale}, _resolution) do
|
||||||
with {:ok, user} <- Actors.get_user_by_email(email, false),
|
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}
|
{:ok, email}
|
||||||
else
|
else
|
||||||
{:error, :user_not_found} ->
|
{:error, :user_not_found} ->
|
||||||
{:error, "No user to validate with this email was found"}
|
{:error, "No user to validate with this email was found"}
|
||||||
|
|
||||||
{:error, :email_too_soon} ->
|
{:error, :email_too_soon} ->
|
||||||
{:error, "You requested again a confirmation email too soon"}
|
{:error, "You requested again a confirmation email too soon"}
|
||||||
end
|
end
|
||||||
|
@ -85,11 +87,13 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
"""
|
"""
|
||||||
def send_reset_password(_parent, %{email: email, locale: locale}, _resolution) do
|
def send_reset_password(_parent, %{email: email, locale: locale}, _resolution) do
|
||||||
with {:ok, user} <- Actors.get_user_by_email(email, false),
|
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}
|
{:ok, email}
|
||||||
else
|
else
|
||||||
{:error, :user_not_found} ->
|
{:error, :user_not_found} ->
|
||||||
{:error, "No user to validate with this email was found"}
|
{:error, "No user to validate with this email was found"}
|
||||||
|
|
||||||
{:error, :email_too_soon} ->
|
{:error, :email_too_soon} ->
|
||||||
{:error, "You requested again a confirmation email too soon"}
|
{:error, "You requested again a confirmation email too soon"}
|
||||||
end
|
end
|
||||||
|
|
|
@ -337,14 +337,15 @@ defmodule Mobilizon.ActorsTest do
|
||||||
test "get_user_by_email/1 finds an activated user by it's email" do
|
test "get_user_by_email/1 finds an activated user by it's email" do
|
||||||
{:ok, %Actor{user: %User{email: email} = user} = _actor} =
|
{:ok, %Actor{user: %User{email: email} = user} = _actor} =
|
||||||
Actors.register(%{email: @email, password: @password, username: "yolo"})
|
Actors.register(%{email: @email, password: @password, username: "yolo"})
|
||||||
|
|
||||||
{:ok, %User{id: id}} = Actors.get_user_by_email(@email, false)
|
{:ok, %User{id: id}} = Actors.get_user_by_email(@email, false)
|
||||||
assert id == user.id
|
assert id == user.id
|
||||||
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, true)
|
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, true)
|
||||||
|
|
||||||
Actors.update_user(user, %{
|
Actors.update_user(user, %{
|
||||||
"confirmed_at" => DateTime.utc_now(),
|
"confirmed_at" => DateTime.utc_now(),
|
||||||
"confirmation_sent_at" => nil,
|
"confirmation_sent_at" => nil,
|
||||||
"confirmation_token" => nil
|
"confirmation_token" => nil
|
||||||
})
|
})
|
||||||
|
|
||||||
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, false)
|
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, false)
|
||||||
|
|
|
@ -130,8 +130,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
@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)
|
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||||
|
|
||||||
mutation = """
|
mutation = """
|
||||||
|
@ -154,15 +153,14 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> 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"] ==
|
assert json_response(res, 200)["data"]["validateUser"]["user"]["id"] ==
|
||||||
to_string(actor.user.id)
|
to_string(actor.user.id)
|
||||||
end
|
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)
|
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||||
|
|
||||||
mutation = """
|
mutation = """
|
||||||
|
@ -185,7 +183,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> 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
|
end
|
||||||
|
|
||||||
test "test resend_confirmation_email/3 with valid email resends an validation email", context do
|
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
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] == "You requested again a confirmation email too soon"
|
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
# Hammer time !
|
||||||
|
Mobilizon.Actors.update_user(actor.user, %{
|
||||||
|
confirmation_sent_at: Timex.shift(actor.user.confirmation_sent_at, hours: -3)
|
||||||
|
})
|
||||||
|
|
||||||
res =
|
res =
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["resendConfirmationEmail"] == actor.user.email
|
assert json_response(res, 200)["data"]["resendConfirmationEmail"] == actor.user.email
|
||||||
assert_delivered_email Mobilizon.Email.User.confirmation_email(actor.user)
|
assert_delivered_email(Mobilizon.Email.User.confirmation_email(actor.user))
|
||||||
end
|
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)
|
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||||
|
|
||||||
mutation = """
|
mutation = """
|
||||||
|
@ -234,6 +233,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> 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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue