Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / pleroma / user / welcome_email_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.WelcomeEmailTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Config
9 alias Pleroma.Tests.ObanHelpers
10 alias Pleroma.User.WelcomeEmail
11
12 import Pleroma.Factory
13 import Swoosh.TestAssertions
14
15 setup do: clear_config([:welcome])
16
17 describe "send_email/1" do
18 test "send a welcome email" do
19 user = insert(:user, name: "Jimm")
20
21 Config.put([:welcome, :email, :enabled], true)
22 Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
23
24 Config.put(
25 [:welcome, :email, :subject],
26 "Hello, welcome to pleroma: <%= instance_name %>"
27 )
28
29 Config.put(
30 [:welcome, :email, :html],
31 "<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
32 )
33
34 instance_name = Config.get([:instance, :name])
35
36 {:ok, _job} = WelcomeEmail.send_email(user)
37
38 ObanHelpers.perform_all()
39
40 assert_email_sent(
41 from: {instance_name, "welcome@pleroma.app"},
42 to: {user.name, user.email},
43 subject: "Hello, welcome to pleroma: #{instance_name}",
44 html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
45 )
46
47 Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
48
49 {:ok, _job} = WelcomeEmail.send_email(user)
50
51 ObanHelpers.perform_all()
52
53 assert_email_sent(
54 from: {"Pleroma App", "welcome@pleroma.app"},
55 to: {user.name, user.email},
56 subject: "Hello, welcome to pleroma: #{instance_name}",
57 html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
58 )
59 end
60 end
61 end