Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / emails / mailer_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 setup do: clear_config([Pleroma.Emails.Mailer, :enabled])
18
19 test "not send email when mailer is disabled" do
20 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
21 Mailer.deliver(@email)
22
23 refute_email_sent(
24 from: {"Pleroma", "noreply@example.com"},
25 to: [{"Test User", "user1@example.com"}],
26 html_body: "Test email",
27 subject: "Pleroma test email"
28 )
29 end
30
31 test "send email" do
32 Mailer.deliver(@email)
33
34 assert_email_sent(
35 from: {"Pleroma", "noreply@example.com"},
36 to: [{"Test User", "user1@example.com"}],
37 html_body: "Test email",
38 subject: "Pleroma test email"
39 )
40 end
41
42 test "perform" do
43 Mailer.perform(:deliver_async, @email, [])
44
45 assert_email_sent(
46 from: {"Pleroma", "noreply@example.com"},
47 to: [{"Test User", "user1@example.com"}],
48 html_body: "Test email",
49 subject: "Pleroma test email"
50 )
51 end
52 end