admin_mailer_spec.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 headers' do
  13. expect(mail.subject).to eq("New report for cb6e6126.ngrok.io (##{report.id})")
  14. expect(mail.to).to eq [recipient.user_email]
  15. expect(mail.from).to eq ['notifications@localhost']
  16. end
  17. it 'renders the body' do
  18. expect(mail.body.encoded).to eq("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 headers' do
  29. expect(mail.subject).to eq("#{appeal.account.username} is appealing a moderation decision on cb6e6126.ngrok.io")
  30. expect(mail.to).to eq [recipient.user_email]
  31. expect(mail.from).to eq ['notifications@localhost']
  32. end
  33. it 'renders the body' do
  34. expect(mail.body.encoded).to match "#{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 headers' do
  45. expect(mail.subject).to eq("New account up for review on cb6e6126.ngrok.io (#{user.account.username})")
  46. expect(mail.to).to eq [recipient.user_email]
  47. expect(mail.from).to eq ['notifications@localhost']
  48. end
  49. it 'renders the body' do
  50. expect(mail.body.encoded).to match '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(:links) { [] }
  56. let(:statuses) { [] }
  57. let(:tags) { [] }
  58. let(:mail) { described_class.with(recipient: recipient).new_trends(links, tags, statuses) }
  59. before do
  60. recipient.user.update(locale: :en)
  61. end
  62. it 'renders the headers' do
  63. expect(mail.subject).to eq('New trends up for review on cb6e6126.ngrok.io')
  64. expect(mail.to).to eq [recipient.user_email]
  65. expect(mail.from).to eq ['notifications@localhost']
  66. end
  67. it 'renders the body' do
  68. expect(mail.body.encoded).to match 'The following items need a review before they can be displayed publicly'
  69. end
  70. end
  71. describe '.new_software_updates' do
  72. let(:recipient) { Fabricate(:account, username: 'Bob') }
  73. let(:mail) { described_class.with(recipient: recipient).new_software_updates }
  74. before do
  75. recipient.user.update(locale: :en)
  76. end
  77. it 'renders the headers' do
  78. expect(mail.subject).to eq('New Mastodon versions are available for cb6e6126.ngrok.io!')
  79. expect(mail.to).to eq [recipient.user_email]
  80. expect(mail.from).to eq ['notifications@localhost']
  81. end
  82. it 'renders the body' do
  83. expect(mail.body.encoded).to match 'New Mastodon versions have been released, you may want to update!'
  84. end
  85. end
  86. describe '.new_critical_software_updates' do
  87. let(:recipient) { Fabricate(:account, username: 'Bob') }
  88. let(:mail) { described_class.with(recipient: recipient).new_critical_software_updates }
  89. before do
  90. recipient.user.update(locale: :en)
  91. end
  92. it 'renders the headers', :aggregate_failures do
  93. expect(mail.subject).to eq('Critical Mastodon updates are available for cb6e6126.ngrok.io!')
  94. expect(mail.to).to eq [recipient.user_email]
  95. expect(mail.from).to eq ['notifications@localhost']
  96. expect(mail['Importance'].value).to eq 'high'
  97. expect(mail['Priority'].value).to eq 'urgent'
  98. expect(mail['X-Priority'].value).to eq '1'
  99. end
  100. it 'renders the body' do
  101. expect(mail.body.encoded).to match 'New critical versions of Mastodon have been released, you may want to update as soon as possible!'
  102. end
  103. end
  104. end