Merge pull request 'User: search: exclude deactivated users from user search' (#214...
[akkoma] / test / pleroma / emails / mailer_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.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], true)
18
19 test "not send email when mailer is disabled" do
20 clear_config([Pleroma.Emails.Mailer, :enabled], false)
21 Mailer.deliver(@email)
22 :timer.sleep(100)
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 :timer.sleep(100)
35
36 assert_email_sent(
37 from: {"Pleroma", "noreply@example.com"},
38 to: [{"Test User", "user1@example.com"}],
39 html_body: "Test email",
40 subject: "Pleroma test email"
41 )
42 end
43
44 test "perform" do
45 Mailer.perform(:deliver_async, @email, [])
46 :timer.sleep(100)
47
48 assert_email_sent(
49 from: {"Pleroma", "noreply@example.com"},
50 to: [{"Test User", "user1@example.com"}],
51 html_body: "Test email",
52 subject: "Pleroma test email"
53 )
54 end
55 end