闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.4 KiB

  1. require "rails_helper"
  2. RSpec.describe NotificationMailer, type: :mailer do
  3. let(:receiver) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  4. let(:sender) { Fabricate(:account, username: 'bob') }
  5. let(:foreign_status) { Fabricate(:status, account: sender) }
  6. let(:own_status) { Fabricate(:status, account: receiver.account) }
  7. describe "mention" do
  8. let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) }
  9. let(:mail) { NotificationMailer.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) }
  10. it "renders the headers" do
  11. expect(mail.subject).to eq("You were mentioned by bob")
  12. expect(mail.to).to eq([receiver.email])
  13. end
  14. it "renders the body" do
  15. expect(mail.body.encoded).to match("You were mentioned by bob")
  16. end
  17. end
  18. describe "follow" do
  19. let(:follow) { sender.follow!(receiver.account) }
  20. let(:mail) { NotificationMailer.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) }
  21. it "renders the headers" do
  22. expect(mail.subject).to eq("bob is now following you")
  23. expect(mail.to).to eq([receiver.email])
  24. end
  25. it "renders the body" do
  26. expect(mail.body.encoded).to match("bob is now following you")
  27. end
  28. end
  29. describe "favourite" do
  30. let(:favourite) { Favourite.create!(account: sender, status: own_status) }
  31. let(:mail) { NotificationMailer.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) }
  32. it "renders the headers" do
  33. expect(mail.subject).to eq("bob favourited your status")
  34. expect(mail.to).to eq([receiver.email])
  35. end
  36. it "renders the body" do
  37. expect(mail.body.encoded).to match("Your status was favourited by bob")
  38. end
  39. end
  40. describe "reblog" do
  41. let(:reblog) { Status.create!(account: sender, reblog: own_status) }
  42. let(:mail) { NotificationMailer.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) }
  43. it "renders the headers" do
  44. expect(mail.subject).to eq("bob boosted your status")
  45. expect(mail.to).to eq([receiver.email])
  46. end
  47. it "renders the body" do
  48. expect(mail.body.encoded).to match("Your status was boosted by bob")
  49. end
  50. end
  51. describe 'follow_request' do
  52. let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) }
  53. let(:mail) { NotificationMailer.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) }
  54. it 'renders the headers' do
  55. expect(mail.subject).to eq('Pending follower: bob')
  56. expect(mail.to).to eq([receiver.email])
  57. end
  58. it 'renders the body' do
  59. expect(mail.body.encoded).to match("bob has requested to follow you")
  60. end
  61. end
  62. describe 'digest' do
  63. before do
  64. mention = Fabricate(:mention, account: receiver.account)
  65. Fabricate(:notification, account: receiver.account, activity: mention)
  66. end
  67. let(:mail) { NotificationMailer.digest(receiver.account, since: 5.days.ago) }
  68. it 'renders the headers' do
  69. expect(mail.subject).to match('notification since your last')
  70. expect(mail.to).to eq([receiver.email])
  71. end
  72. it 'renders the body' do
  73. expect(mail.body.encoded).to match('brief summary')
  74. end
  75. end
  76. end