Merge branch 'report-email-from-remote-user' into 'develop'
[akkoma] / test / emails / mailer_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emails.MailerTest do
6 use Pleroma.DataCase
7 alias Pleroma.Emails.Mailer
8
9 import Swoosh.TestAssertions
10
11 @email %Swoosh.Email{
12 from: {"Pleroma", "noreply@example.com"},
13 html_body: "Test email",
14 subject: "Pleroma test email",
15 to: [{"Test User", "user1@example.com"}]
16 }
17
18 setup do
19 value = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
20 on_exit(fn -> Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], value) end)
21 :ok
22 end
23
24 test "not send email when mailer is disabled" do
25 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
26 Mailer.deliver(@email)
27
28 refute_email_sent(
29 from: {"Pleroma", "noreply@example.com"},
30 to: [{"Test User", "user1@example.com"}],
31 html_body: "Test email",
32 subject: "Pleroma test email"
33 )
34 end
35
36 test "send email" do
37 Mailer.deliver(@email)
38
39 assert_email_sent(
40 from: {"Pleroma", "noreply@example.com"},
41 to: [{"Test User", "user1@example.com"}],
42 html_body: "Test email",
43 subject: "Pleroma test email"
44 )
45 end
46
47 test "perform" do
48 Mailer.perform(:deliver_async, @email, [])
49
50 assert_email_sent(
51 from: {"Pleroma", "noreply@example.com"},
52 to: [{"Test User", "user1@example.com"}],
53 html_body: "Test email",
54 subject: "Pleroma test email"
55 )
56 end
57 end