Validate emails are sent to the appropriate unconfirmed actors
authorMark Felder <feld@FreeBSD.org>
Thu, 24 Sep 2020 23:24:44 +0000 (18:24 -0500)
committerMark Felder <feld@FreeBSD.org>
Thu, 24 Sep 2020 23:24:44 +0000 (18:24 -0500)
test/tasks/email_test.exs

index c3af7ef68ab3a2c7dc9b91844257660f59795789..5393e3573d9f2bf1d3fbab1dbc414702210d57be 100644 (file)
@@ -6,6 +6,8 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
   alias Pleroma.Config
   alias Pleroma.Tests.ObanHelpers
 
+  import Pleroma.Factory
+
   setup_all do
     Mix.shell(Mix.Shell.Process)
 
@@ -17,6 +19,7 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
   end
 
   setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
+  setup do: clear_config([:instance, :account_activation_required], true)
 
   describe "pleroma.email test" do
     test "Sends test email with no given address" do
@@ -50,5 +53,71 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
         html_body: ~r/a test email was requested./i
       )
     end
+
+    test "Sends confirmation emails" do
+      local_user1 =
+        insert(:user, %{
+          confirmation_pending: true,
+          confirmation_token: "mytoken",
+          deactivated: false,
+          email: "local1@pleroma.com",
+          local: true
+        })
+
+      local_user2 =
+        insert(:user, %{
+          confirmation_pending: true,
+          confirmation_token: "mytoken",
+          deactivated: false,
+          email: "local2@pleroma.com",
+          local: true
+        })
+
+      :ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
+
+      ObanHelpers.perform_all()
+
+      assert_email_sent(to: {local_user1.name, local_user1.email})
+      assert_email_sent(to: {local_user2.name, local_user2.email})
+    end
+
+    test "Does not send confirmation email to inappropriate users" do
+      # confirmed user
+      insert(:user, %{
+        confirmation_pending: false,
+        confirmation_token: "mytoken",
+        deactivated: false,
+        email: "confirmed@pleroma.com",
+        local: true
+      })
+
+      # remote user
+      insert(:user, %{
+        deactivated: false,
+        email: "remote@not-pleroma.com",
+        local: false
+      })
+
+      # deactivated user =
+      insert(:user, %{
+        deactivated: true,
+        email: "deactivated@pleroma.com",
+        local: false
+      })
+
+      # invisible user
+      insert(:user, %{
+        deactivated: false,
+        email: "invisible@pleroma.com",
+        local: true,
+        invisible: true
+      })
+
+      :ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
+
+      ObanHelpers.perform_all()
+
+      refute_email_sent()
+    end
   end
 end