Purge Rejected Follow requests in daily task (#334)
[akkoma] / test / pleroma / emails / user_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.Emails.UserEmailTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Emails.UserEmail
9 alias Pleroma.Web.Endpoint
10 alias Pleroma.Web.Router
11
12 import Pleroma.Factory
13
14 test "build password reset email" do
15 config = Pleroma.Config.get(:instance)
16 user = insert(:user)
17 email = UserEmail.password_reset_email(user, "test_token")
18 assert email.from == {config[:name], config[:notify_email]}
19 assert email.to == [{user.name, user.email}]
20 assert email.subject == "Password reset"
21 assert email.html_body =~ Router.Helpers.reset_password_url(Endpoint, :reset, "test_token")
22 end
23
24 test "build user invitation email" do
25 config = Pleroma.Config.get(:instance)
26 user = insert(:user)
27 token = %Pleroma.UserInviteToken{token: "test-token"}
28 email = UserEmail.user_invitation_email(user, token, "test@test.com", "Jonh")
29 assert email.from == {config[:name], config[:notify_email]}
30 assert email.subject == "Invitation to Akkoma"
31 assert email.to == [{"Jonh", "test@test.com"}]
32
33 assert email.html_body =~
34 Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
35 end
36
37 test "build account confirmation email" do
38 config = Pleroma.Config.get(:instance)
39 user = insert(:user, confirmation_token: "conf-token")
40 email = UserEmail.account_confirmation_email(user)
41 assert email.from == {config[:name], config[:notify_email]}
42 assert email.to == [{user.name, user.email}]
43 assert email.subject == "#{config[:name]} account confirmation"
44
45 assert email.html_body =~
46 Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
47 end
48
49 test "build approval pending email" do
50 config = Pleroma.Config.get(:instance)
51 user = insert(:user)
52 email = UserEmail.approval_pending_email(user)
53
54 assert email.from == {config[:name], config[:notify_email]}
55 assert email.to == [{user.name, user.email}]
56 assert email.subject == "Your account is awaiting approval"
57 assert email.html_body =~ "Awaiting Approval"
58 end
59
60 test "email i18n" do
61 user = insert(:user, language: "en_test")
62 email = UserEmail.approval_pending_email(user)
63 assert email.subject == "xxYour account is awaiting approvalxx"
64 end
65
66 test "email i18n should fallback to default locale if user language is unsupported" do
67 user = insert(:user, language: "unsupported")
68 email = UserEmail.approval_pending_email(user)
69 assert email.subject == "Your account is awaiting approval"
70 end
71 end