2019-07-09 23:34:21 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-07-09 23:34:21 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Emails.UserEmailTest do
|
2020-12-21 04:21:40 -07:00
|
|
|
use Pleroma.DataCase, async: true
|
2019-07-09 23:34:21 -06:00
|
|
|
|
|
|
|
alias Pleroma.Emails.UserEmail
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "build password reset email" do
|
|
|
|
config = Pleroma.Config.get(:instance)
|
|
|
|
user = insert(:user)
|
|
|
|
email = UserEmail.password_reset_email(user, "test_token")
|
|
|
|
assert email.from == {config[:name], config[:notify_email]}
|
|
|
|
assert email.to == [{user.name, user.email}]
|
|
|
|
assert email.subject == "Password reset"
|
2023-08-15 04:22:18 -06:00
|
|
|
assert email.html_body =~ ~p"/api/v1/pleroma/password_reset/test_token"
|
2019-07-09 23:34:21 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "build user invitation email" do
|
|
|
|
config = Pleroma.Config.get(:instance)
|
|
|
|
user = insert(:user)
|
|
|
|
token = %Pleroma.UserInviteToken{token: "test-token"}
|
|
|
|
email = UserEmail.user_invitation_email(user, token, "test@test.com", "Jonh")
|
|
|
|
assert email.from == {config[:name], config[:notify_email]}
|
2022-11-04 12:42:12 -06:00
|
|
|
assert email.subject == "Invitation to Akkoma"
|
2019-07-09 23:34:21 -06:00
|
|
|
assert email.to == [{"Jonh", "test@test.com"}]
|
|
|
|
|
2023-08-15 04:22:18 -06:00
|
|
|
assert email.html_body =~ ~p[/registration/#{token.token}]
|
2019-07-09 23:34:21 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "build account confirmation email" do
|
|
|
|
config = Pleroma.Config.get(:instance)
|
2019-10-16 12:59:21 -06:00
|
|
|
user = insert(:user, confirmation_token: "conf-token")
|
2019-07-09 23:34:21 -06:00
|
|
|
email = UserEmail.account_confirmation_email(user)
|
|
|
|
assert email.from == {config[:name], config[:notify_email]}
|
|
|
|
assert email.to == [{user.name, user.email}]
|
|
|
|
assert email.subject == "#{config[:name]} account confirmation"
|
|
|
|
|
2023-08-15 04:22:18 -06:00
|
|
|
assert email.html_body =~ ~p[/account/confirm_email/#{user.id}/conf-token]
|
2019-07-09 23:34:21 -06:00
|
|
|
end
|
2020-10-11 19:50:09 -06:00
|
|
|
|
|
|
|
test "build approval pending email" do
|
|
|
|
config = Pleroma.Config.get(:instance)
|
|
|
|
user = insert(:user)
|
|
|
|
email = UserEmail.approval_pending_email(user)
|
|
|
|
|
|
|
|
assert email.from == {config[:name], config[:notify_email]}
|
|
|
|
assert email.to == [{user.name, user.email}]
|
|
|
|
assert email.subject == "Your account is awaiting approval"
|
|
|
|
assert email.html_body =~ "Awaiting Approval"
|
|
|
|
end
|
2022-03-01 19:24:17 -07:00
|
|
|
|
|
|
|
test "email i18n" do
|
|
|
|
user = insert(:user, language: "en_test")
|
|
|
|
email = UserEmail.approval_pending_email(user)
|
|
|
|
assert email.subject == "xxYour account is awaiting approvalxx"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "email i18n should fallback to default locale if user language is unsupported" do
|
|
|
|
user = insert(:user, language: "unsupported")
|
|
|
|
email = UserEmail.approval_pending_email(user)
|
|
|
|
assert email.subject == "Your account is awaiting approval"
|
|
|
|
end
|
2019-07-09 23:34:21 -06:00
|
|
|
end
|