502702e49bd06366420be3941ffff59ba6cb11e3
[akkoma] / test / emails / user_email_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emails.UserEmailTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Emails.UserEmail
9 alias Pleroma.Web.Endpoint
10 alias Pleroma.Web.Router
11
12 import Pleroma.Factory
13 import Swoosh.TestAssertions
14
15 test "build password reset email" do
16 config = Pleroma.Config.get(:instance)
17 user = insert(:user)
18 email = UserEmail.password_reset_email(user, "test_token")
19 assert email.from == {config[:name], config[:notify_email]}
20 assert email.to == [{user.name, user.email}]
21 assert email.subject == "Password reset"
22 assert email.html_body =~ Router.Helpers.reset_password_url(Endpoint, :reset, "test_token")
23 end
24
25 test "build user invitation email" do
26 config = Pleroma.Config.get(:instance)
27 user = insert(:user)
28 token = %Pleroma.UserInviteToken{token: "test-token"}
29 email = UserEmail.user_invitation_email(user, token, "test@test.com", "Jonh")
30 assert email.from == {config[:name], config[:notify_email]}
31 assert email.subject == "Invitation to Pleroma"
32 assert email.to == [{"Jonh", "test@test.com"}]
33
34 assert email.html_body =~
35 Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
36 end
37
38 test "build account confirmation email" do
39 config = Pleroma.Config.get(:instance)
40 user = insert(:user, confirmation_token: "conf-token")
41 email = UserEmail.account_confirmation_email(user)
42 assert email.from == {config[:name], config[:notify_email]}
43 assert email.to == [{user.name, user.email}]
44 assert email.subject == "#{config[:name]} account confirmation"
45
46 assert email.html_body =~
47 Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
48 end
49 end