logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

admin_email_test.exs (2780B)


  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. defmodule Pleroma.Emails.AdminEmailTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Emails.AdminEmail
  8. alias Pleroma.Web.Router.Helpers
  9. test "build report email" do
  10. config = Pleroma.Config.get(:instance)
  11. to_user = insert(:user)
  12. reporter = insert(:user)
  13. account = insert(:user)
  14. res =
  15. AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
  16. status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
  17. reporter_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
  18. account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
  19. assert res.to == [{to_user.name, to_user.email}]
  20. assert res.from == {config[:name], config[:notify_email]}
  21. assert res.subject == "#{config[:name]} Report"
  22. assert res.html_body ==
  23. "<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{
  24. account_url
  25. }\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{
  26. status_url
  27. }\">#{status_url}</li>\n </ul>\n</p>\n\n<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
  28. end
  29. test "it works when the reporter is a remote user without email" do
  30. config = Pleroma.Config.get(:instance)
  31. to_user = insert(:user)
  32. reporter = insert(:user, email: nil, local: false)
  33. account = insert(:user)
  34. res =
  35. AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
  36. assert res.to == [{to_user.name, to_user.email}]
  37. assert res.from == {config[:name], config[:notify_email]}
  38. end
  39. test "new unapproved registration email" do
  40. config = Pleroma.Config.get(:instance)
  41. to_user = insert(:user)
  42. account = insert(:user, registration_reason: "Plz let me in")
  43. res = AdminEmail.new_unapproved_registration(to_user, account)
  44. account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
  45. assert res.to == [{to_user.name, to_user.email}]
  46. assert res.from == {config[:name], config[:notify_email]}
  47. assert res.subject == "New account up for review on #{config[:name]} (@#{account.nickname})"
  48. assert res.html_body == """
  49. <p>New account for review: <a href="#{account_url}">@#{account.nickname}</a></p>
  50. <blockquote>Plz let me in</blockquote>
  51. <a href="http://localhost:4001/pleroma/admin">Visit AdminFE</a>
  52. """
  53. end
  54. end