Registration tests
authorAlex Gleason <alex@alexgleason.me>
Mon, 12 Oct 2020 02:38:01 +0000 (21:38 -0500)
committerAlex Gleason <alex@alexgleason.me>
Mon, 12 Oct 2020 02:38:01 +0000 (21:38 -0500)
lib/pleroma/user.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/user_test.exs

index cde9ff0eb72faf25ae825cb7331220597f9bc5f9..ae2fe93fcfcf73dd2307b1b949d9099298d8ed8a 100644 (file)
@@ -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
index 25dad547caf6d27e98388ebb2a6b890caec91d6f..6961118cac97894f28134aa36f5fae1e790fab74 100644 (file)
@@ -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
index d506f704708a6c7f501bf51db735b8f5cd301b21..2d3a6564b4ae4f1f05f5c81abd5477da662afc8f 100644 (file)
@@ -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)