1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emails.UserEmailTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.Emails.UserEmail
9 alias Pleroma.Web.Endpoint
10 alias Pleroma.Web.Router
12 import Pleroma.Factory
14 test "build password reset email" do
15 config = Pleroma.Config.get(:instance)
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")
24 test "build user invitation email" do
25 config = Pleroma.Config.get(:instance)
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 Pleroma"
31 assert email.to == [{"Jonh", "test@test.com"}]
33 assert email.html_body =~
34 Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
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"
45 assert email.html_body =~
46 Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
49 test "build approval pending email" do
50 config = Pleroma.Config.get(:instance)
52 email = UserEmail.approval_pending_email(user)
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"
61 user = insert(:user, language: "en_test")
62 email = UserEmail.approval_pending_email(user)
63 assert email.subject == "xxYour account is awaiting approvalxx"
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"