From ebf192e2c7f415d2303fd9d850ac7f5a31d17c85 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 19 Apr 2021 16:50:16 +0200 Subject: [PATCH] Fix CLI to change an user's email and add a test Signed-off-by: Thomas Citharel --- lib/mix/tasks/mobilizon/users/modify.ex | 2 +- test/tasks/users_test.exs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/mix/tasks/mobilizon/users/modify.ex b/lib/mix/tasks/mobilizon/users/modify.ex index e210e5742..e49e8e1e7 100644 --- a/lib/mix/tasks/mobilizon/users/modify.ex +++ b/lib/mix/tasks/mobilizon/users/modify.ex @@ -40,7 +40,7 @@ defmodule Mix.Tasks.Mobilizon.Users.Modify do with {:ok, %User{} = user} <- Users.get_user_by_email(email), attrs <- %{}, 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 <- if(disable? && !is_nil(user.confirmed_at), diff --git a/test/tasks/users_test.exs b/test/tasks/users_test.exs index 7cd82946b..f263fa6cc 100644 --- a/test/tasks/users_test.exs +++ b/test/tasks/users_test.exs @@ -170,5 +170,22 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do assert_received {:mix_shell, :error, [message]} assert message =~ "Can't use both --enabled and --disable options at the same time." 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