From 521e965884d916c21d76ff12544e678b7fcdb1d4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 11 Oct 2020 21:38:01 -0500 Subject: [PATCH] Registration tests --- lib/pleroma/user.ex | 8 +++++--- .../web/twitter_api/twitter_api_controller.ex | 4 ++-- test/user_test.exs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index cde9ff0eb..ae2fe93fc 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1582,9 +1582,11 @@ defmodule Pleroma.User do end def approve(%User{} = user) do - change(user, approval_pending: false) - |> update_and_set_cache() - |> post_register_action() + with chg <- change(user, approval_pending: false), + {:ok, user} <- update_and_set_cache(chg) do + post_register_action(user) + {:ok, user} + end end def update_notification_settings(%User{} = user, settings) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 25dad547c..6961118ca 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -34,8 +34,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do {:ok, _} <- user |> User.confirmation_changeset(need_confirmation: false) - |> User.update_and_set_cache() - |> User.post_register_action() do + |> User.update_and_set_cache() do + User.post_register_action(user) redirect(conn, to: "/") end end diff --git a/test/user_test.exs b/test/user_test.exs index d506f7047..2d3a6564b 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -517,6 +517,22 @@ defmodule Pleroma.UserTest do |> assert_email_sent() end + test "sends a pending approval email" do + clear_config([:instance, :account_approval_required], true) + + {:ok, user} = + User.register_changeset(%User{}, @full_user_data) + |> User.register() + + ObanHelpers.perform_all() + + assert_email_sent( + from: Pleroma.Config.Helpers.sender(), + to: {user.name, user.email}, + subject: "Your account is awaiting approval" + ) + end + test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do Pleroma.Config.put([:instance, :account_activation_required], true) -- 2.45.2