Fix CLI to change an user's email and add a test
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
9a50d7e6c5
commit
ebf192e2c7
|
@ -40,7 +40,7 @@ defmodule Mix.Tasks.Mobilizon.Users.Modify do
|
||||||
with {:ok, %User{} = user} <- Users.get_user_by_email(email),
|
with {:ok, %User{} = user} <- Users.get_user_by_email(email),
|
||||||
attrs <- %{},
|
attrs <- %{},
|
||||||
role <- calculate_role(admin?, moderator?, user?),
|
role <- calculate_role(admin?, moderator?, user?),
|
||||||
attrs <- process_new_value(attrs, :mail, new_email, user.email),
|
attrs <- process_new_value(attrs, :email, new_email, user.email),
|
||||||
attrs <- process_new_value(attrs, :role, role, user.role),
|
attrs <- process_new_value(attrs, :role, role, user.role),
|
||||||
attrs <-
|
attrs <-
|
||||||
if(disable? && !is_nil(user.confirmed_at),
|
if(disable? && !is_nil(user.confirmed_at),
|
||||||
|
|
|
@ -170,5 +170,22 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
|
||||||
assert_received {:mix_shell, :error, [message]}
|
assert_received {:mix_shell, :error, [message]}
|
||||||
assert message =~ "Can't use both --enabled and --disable options at the same time."
|
assert message =~ "Can't use both --enabled and --disable options at the same time."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@modified_email "modified@email.tld"
|
||||||
|
|
||||||
|
test "change user's email" do
|
||||||
|
user = insert(:user, email: @email)
|
||||||
|
Modify.run([@email, "--email", @modified_email])
|
||||||
|
|
||||||
|
assert_received {:mix_shell, :info, [output_received]}
|
||||||
|
|
||||||
|
assert {:ok, %User{confirmed_at: confirmed_at, email: @modified_email}} =
|
||||||
|
Users.get_user_by_email(@modified_email)
|
||||||
|
|
||||||
|
assert output_received ==
|
||||||
|
"An user has been modified with the following information:\n - email: #{
|
||||||
|
@modified_email
|
||||||
|
}\n - Role: #{user.role}\n - account status: activated on #{confirmed_at} (UTC)\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue