added tests
authorMaksim Pechnikov <parallel588@gmail.com>
Wed, 22 Jul 2020 05:58:06 +0000 (08:58 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Wed, 22 Jul 2020 05:58:06 +0000 (08:58 +0300)
test/emails/user_email_test.exs
test/user/welcome_email_test.exs [new file with mode: 0644]
test/user/welcome_message_test.exs [new file with mode: 0644]

index 502702e49bd06366420be3941ffff59ba6cb11e3..a75623bb41aa3c72cd3a532e6db38c3ce2545d68 100644 (file)
@@ -10,7 +10,6 @@ defmodule Pleroma.Emails.UserEmailTest do
   alias Pleroma.Web.Router
 
   import Pleroma.Factory
-  import Swoosh.TestAssertions
 
   test "build password reset email" do
     config = Pleroma.Config.get(:instance)
diff --git a/test/user/welcome_email_test.exs b/test/user/welcome_email_test.exs
new file mode 100644 (file)
index 0000000..1a80109
--- /dev/null
@@ -0,0 +1,49 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.User.WelcomeEmailTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Config
+  alias Pleroma.Tests.ObanHelpers
+  alias Pleroma.User.WelcomeEmail
+
+  import Pleroma.Factory
+  import Swoosh.TestAssertions
+
+  setup do: clear_config([:welcome])
+
+  describe "send_email/1" do
+    test "send a welcome email" do
+      welcome_user = insert(:user)
+      user = insert(:user, name: "Jimm")
+
+      Config.put([:welcome, :email, :enabled], true)
+      Config.put([:welcome, :email, :sender_nickname], welcome_user.nickname)
+
+      Config.put(
+        [:welcome, :email, :subject],
+        "Hello, welcome to pleroma: <%= instance_name %>"
+      )
+
+      Config.put(
+        [:welcome, :email, :html],
+        "<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
+      )
+
+      instance_name = Config.get([:instance, :name])
+
+      {:ok, _job} = WelcomeEmail.send_email(user)
+
+      ObanHelpers.perform_all()
+
+      assert_email_sent(
+        from: {instance_name, welcome_user.email},
+        to: {user.name, user.email},
+        subject: "Hello, welcome to pleroma: #{instance_name}",
+        html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
+      )
+    end
+  end
+end
diff --git a/test/user/welcome_message_test.exs b/test/user/welcome_message_test.exs
new file mode 100644 (file)
index 0000000..3cd6f5c
--- /dev/null
@@ -0,0 +1,34 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.User.WelcomeMessageTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Config
+  alias Pleroma.User.WelcomeMessage
+
+  import Pleroma.Factory
+
+  setup do: clear_config([:welcome])
+
+  describe "post_message/1" do
+    test "send a direct welcome message" do
+      welcome_user = insert(:user)
+      user = insert(:user, name: "Jimm")
+
+      Config.put([:welcome, :direct_message, :enabled], true)
+      Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
+
+      Config.put(
+        [:welcome, :direct_message, :message],
+        "Hello. Welcome to Pleroma"
+      )
+
+      {:ok, %Pleroma.Activity{} = activity} = WelcomeMessage.post_message(user)
+      assert user.ap_id in activity.recipients
+      assert activity.data["directMessage"] == true
+      assert Pleroma.Object.normalize(activity).data["content"] =~ "Hello. Welcome to Pleroma"
+    end
+  end
+end