Merge remote-tracking branch 'remotes/upstream/develop' into 1260-rate-limited-auth...
[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 clear_config([Pleroma.Emails.Mailer, :enabled])
19
20 test "not send email when mailer is disabled" do
21 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
22 Mailer.deliver(@email)
23
24 refute_email_sent(
25 from: {"Pleroma", "noreply@example.com"},
26 to: [{"Test User", "user1@example.com"}],
27 html_body: "Test email",
28 subject: "Pleroma test email"
29 )
30 end
31
32 test "send email" do
33 Mailer.deliver(@email)
34
35 assert_email_sent(
36 from: {"Pleroma", "noreply@example.com"},
37 to: [{"Test User", "user1@example.com"}],
38 html_body: "Test email",
39 subject: "Pleroma test email"
40 )
41 end
42
43 test "perform" do
44 Mailer.perform(:deliver_async, @email, [])
45
46 assert_email_sent(
47 from: {"Pleroma", "noreply@example.com"},
48 to: [{"Test User", "user1@example.com"}],
49 html_body: "Test email",
50 subject: "Pleroma test email"
51 )
52 end
53 end