logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

notify_service_spec.rb (5192B)


  1. require 'rails_helper'
  2. RSpec.describe NotifyService do
  3. subject do
  4. -> { described_class.new.call(recipient, activity) }
  5. end
  6. let(:user) { Fabricate(:user) }
  7. let(:recipient) { user.account }
  8. let(:sender) { Fabricate(:account, domain: 'example.com') }
  9. let(:activity) { Fabricate(:follow, account: sender, target_account: recipient) }
  10. it { is_expected.to change(Notification, :count).by(1) }
  11. it 'does not notify when sender is blocked' do
  12. recipient.block!(sender)
  13. is_expected.to_not change(Notification, :count)
  14. end
  15. it 'does not notify when sender is muted with hide_notifications' do
  16. recipient.mute!(sender, notifications: true)
  17. is_expected.to_not change(Notification, :count)
  18. end
  19. it 'does notify when sender is muted without hide_notifications' do
  20. recipient.mute!(sender, notifications: false)
  21. is_expected.to change(Notification, :count)
  22. end
  23. it 'does not notify when sender\'s domain is blocked' do
  24. recipient.block_domain!(sender.domain)
  25. is_expected.to_not change(Notification, :count)
  26. end
  27. it 'does still notify when sender\'s domain is blocked but sender is followed' do
  28. recipient.block_domain!(sender.domain)
  29. recipient.follow!(sender)
  30. is_expected.to change(Notification, :count)
  31. end
  32. it 'does not notify when sender is silenced and not followed' do
  33. sender.update(silenced: true)
  34. is_expected.to_not change(Notification, :count)
  35. end
  36. it 'does not notify when recipient is suspended' do
  37. recipient.update(suspended: true)
  38. is_expected.to_not change(Notification, :count)
  39. end
  40. context 'for direct messages' do
  41. let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) }
  42. before do
  43. user.settings.interactions = user.settings.interactions.merge('must_be_following_dm' => enabled)
  44. end
  45. context 'if recipient is supposed to be following sender' do
  46. let(:enabled) { true }
  47. it 'does not notify' do
  48. is_expected.to_not change(Notification, :count)
  49. end
  50. context 'if the message chain initiated by recipient, but is not direct message' do
  51. let(:reply_to) { Fabricate(:status, account: recipient) }
  52. let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
  53. it 'does not notify' do
  54. is_expected.to_not change(Notification, :count)
  55. end
  56. end
  57. context 'if the message chain initiated by recipient and is direct message' do
  58. let(:reply_to) { Fabricate(:status, account: recipient, visibility: :direct) }
  59. let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
  60. it 'does notify' do
  61. is_expected.to change(Notification, :count)
  62. end
  63. end
  64. end
  65. context 'if recipient is NOT supposed to be following sender' do
  66. let(:enabled) { false }
  67. it 'does notify' do
  68. is_expected.to change(Notification, :count)
  69. end
  70. end
  71. end
  72. describe 'reblogs' do
  73. let(:status) { Fabricate(:status, account: Fabricate(:account)) }
  74. let(:activity) { Fabricate(:status, account: sender, reblog: status) }
  75. it 'shows reblogs by default' do
  76. recipient.follow!(sender)
  77. is_expected.to change(Notification, :count)
  78. end
  79. it 'shows reblogs when explicitly enabled' do
  80. recipient.follow!(sender, reblogs: true)
  81. is_expected.to change(Notification, :count)
  82. end
  83. it 'hides reblogs when disabled' do
  84. recipient.follow!(sender, reblogs: false)
  85. is_expected.to_not change(Notification, :count)
  86. end
  87. end
  88. context do
  89. let(:asshole) { Fabricate(:account, username: 'asshole') }
  90. let(:reply_to) { Fabricate(:status, account: asshole) }
  91. let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, thread: reply_to)) }
  92. it 'does not notify when conversation is muted' do
  93. recipient.mute_conversation!(activity.status.conversation)
  94. is_expected.to_not change(Notification, :count)
  95. end
  96. it 'does not notify when it is a reply to a blocked user' do
  97. recipient.block!(asshole)
  98. is_expected.to_not change(Notification, :count)
  99. end
  100. end
  101. context do
  102. let(:sender) { recipient }
  103. it 'does not notify when recipient is the sender' do
  104. is_expected.to_not change(Notification, :count)
  105. end
  106. end
  107. describe 'email' do
  108. before do
  109. ActionMailer::Base.deliveries.clear
  110. notification_emails = user.settings.notification_emails
  111. user.settings.notification_emails = notification_emails.merge('follow' => enabled)
  112. end
  113. context 'when email notification is enabled' do
  114. let(:enabled) { true }
  115. it 'sends email' do
  116. is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
  117. end
  118. end
  119. context 'when email notification is disabled' do
  120. let(:enabled) { false }
  121. it "doesn't send email" do
  122. is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
  123. end
  124. end
  125. end
  126. end