The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

79 lines
2.2 KiB

  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) }
  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 silenced and not followed' do
  16. sender.update(silenced: true)
  17. is_expected.to_not change(Notification, :count)
  18. end
  19. it 'does not notify when recipient is suspended' do
  20. recipient.update(suspended: true)
  21. is_expected.to_not change(Notification, :count)
  22. end
  23. context do
  24. let(:asshole) { Fabricate(:account, username: 'asshole') }
  25. let(:reply_to) { Fabricate(:status, account: asshole) }
  26. let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, thread: reply_to)) }
  27. it 'does not notify when conversation is muted' do
  28. recipient.mute_conversation!(activity.status.conversation)
  29. is_expected.to_not change(Notification, :count)
  30. end
  31. it 'does not notify when it is a reply to a blocked user' do
  32. recipient.block!(asshole)
  33. is_expected.to_not change(Notification, :count)
  34. end
  35. end
  36. context do
  37. let(:sender) { recipient }
  38. it 'does not notify when recipient is the sender' do
  39. is_expected.to_not change(Notification, :count)
  40. end
  41. end
  42. describe 'email' do
  43. before do
  44. ActionMailer::Base.deliveries.clear
  45. notification_emails = user.settings.notification_emails
  46. user.settings.notification_emails = notification_emails.merge('follow' => enabled)
  47. end
  48. context 'when email notification is enabled' do
  49. let(:enabled) { true }
  50. it 'sends email' do
  51. is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
  52. end
  53. end
  54. context 'when email notification is disabled' do
  55. let(:enabled) { false }
  56. it "doesn't send email" do
  57. is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
  58. end
  59. end
  60. end
  61. end