admin_mailer_spec.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AdminMailer do
  4. describe '.new_report' do
  5. let(:sender) { Fabricate(:account, username: 'John') }
  6. let(:recipient) { Fabricate(:account, username: 'Mike') }
  7. let(:report) { Fabricate(:report, account: sender, target_account: recipient) }
  8. let(:mail) { described_class.with(recipient: recipient).new_report(report) }
  9. before do
  10. recipient.user.update(locale: :en)
  11. end
  12. it 'renders the email' do
  13. expect(mail)
  14. .to be_present
  15. .and(deliver_to(recipient.user_email))
  16. .and(deliver_from('notifications@localhost'))
  17. .and(have_subject("New report for cb6e6126.ngrok.io (##{report.id})"))
  18. .and(have_body_text("Mike,\r\n\r\nJohn has reported Mike\r\n\r\nView: https://cb6e6126.ngrok.io/admin/reports/#{report.id}\r\n"))
  19. end
  20. end
  21. describe '.new_appeal' do
  22. let(:appeal) { Fabricate(:appeal) }
  23. let(:recipient) { Fabricate(:account, username: 'Kurt') }
  24. let(:mail) { described_class.with(recipient: recipient).new_appeal(appeal) }
  25. before do
  26. recipient.user.update(locale: :en)
  27. end
  28. it 'renders the email' do
  29. expect(mail)
  30. .to be_present
  31. .and(deliver_to(recipient.user_email))
  32. .and(deliver_from('notifications@localhost'))
  33. .and(have_subject("#{appeal.account.username} is appealing a moderation decision on cb6e6126.ngrok.io"))
  34. .and(have_body_text("#{appeal.account.username} is appealing a moderation decision by #{appeal.strike.account.username}"))
  35. end
  36. end
  37. describe '.new_pending_account' do
  38. let(:recipient) { Fabricate(:account, username: 'Barklums') }
  39. let(:user) { Fabricate(:user) }
  40. let(:mail) { described_class.with(recipient: recipient).new_pending_account(user) }
  41. before do
  42. recipient.user.update(locale: :en)
  43. end
  44. it 'renders the email' do
  45. expect(mail)
  46. .to be_present
  47. .and(deliver_to(recipient.user_email))
  48. .and(deliver_from('notifications@localhost'))
  49. .and(have_subject("New account up for review on cb6e6126.ngrok.io (#{user.account.username})"))
  50. .and(have_body_text('The details of the new account are below. You can approve or reject this application.'))
  51. end
  52. end
  53. describe '.new_trends' do
  54. let(:recipient) { Fabricate(:account, username: 'Snurf') }
  55. let(:link) { Fabricate(:preview_card, trendable: true, language: 'en') }
  56. let(:status) { Fabricate(:status) }
  57. let(:tag) { Fabricate(:tag) }
  58. let(:mail) { described_class.with(recipient: recipient).new_trends([link], [tag], [status]) }
  59. before do
  60. PreviewCardTrend.create!(preview_card: link)
  61. StatusTrend.create!(status: status, account: Fabricate(:account))
  62. recipient.user.update(locale: :en)
  63. end
  64. it 'renders the email' do
  65. expect(mail)
  66. .to be_present
  67. .and(deliver_to(recipient.user_email))
  68. .and(deliver_from('notifications@localhost'))
  69. .and(have_subject('New trends up for review on cb6e6126.ngrok.io'))
  70. .and(have_body_text('The following items need a review before they can be displayed publicly'))
  71. .and(have_body_text(ActivityPub::TagManager.instance.url_for(status)))
  72. .and(have_body_text(link.title))
  73. .and(have_body_text(tag.display_name))
  74. end
  75. end
  76. describe '.new_software_updates' do
  77. let(:recipient) { Fabricate(:account, username: 'Bob') }
  78. let(:mail) { described_class.with(recipient: recipient).new_software_updates }
  79. before do
  80. recipient.user.update(locale: :en)
  81. end
  82. it 'renders the email' do
  83. expect(mail)
  84. .to be_present
  85. .and(deliver_to(recipient.user_email))
  86. .and(deliver_from('notifications@localhost'))
  87. .and(have_subject('New Mastodon versions are available for cb6e6126.ngrok.io!'))
  88. .and(have_body_text('New Mastodon versions have been released, you may want to update!'))
  89. end
  90. end
  91. describe '.new_critical_software_updates' do
  92. let(:recipient) { Fabricate(:account, username: 'Bob') }
  93. let(:mail) { described_class.with(recipient: recipient).new_critical_software_updates }
  94. before do
  95. recipient.user.update(locale: :en)
  96. end
  97. it 'renders the email' do
  98. expect(mail)
  99. .to be_present
  100. .and(deliver_to(recipient.user_email))
  101. .and(deliver_from('notifications@localhost'))
  102. .and(have_subject('Critical Mastodon updates are available for cb6e6126.ngrok.io!'))
  103. .and(have_body_text('New critical versions of Mastodon have been released, you may want to update as soon as possible!'))
  104. .and(have_header('Importance', 'high'))
  105. .and(have_header('Priority', 'urgent'))
  106. .and(have_header('X-Priority', '1'))
  107. end
  108. end
  109. describe '.auto_close_registrations' do
  110. let(:recipient) { Fabricate(:account, username: 'Bob') }
  111. let(:mail) { described_class.with(recipient: recipient).auto_close_registrations }
  112. before do
  113. recipient.user.update(locale: :en)
  114. end
  115. it 'renders the email' do
  116. expect(mail)
  117. .to be_present
  118. .and(deliver_to(recipient.user_email))
  119. .and(deliver_from('notifications@localhost'))
  120. .and(have_subject('Registrations for cb6e6126.ngrok.io have been automatically switched to requiring approval'))
  121. .and(have_body_text('have been automatically switched'))
  122. end
  123. end
  124. end