push_subscription_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. require 'rails_helper'
  2. RSpec.describe Web::PushSubscription, type: :model do
  3. let(:account) { Fabricate(:account) }
  4. let(:policy) { 'all' }
  5. let(:data) do
  6. {
  7. policy: policy,
  8. alerts: {
  9. mention: true,
  10. reblog: false,
  11. follow: true,
  12. follow_request: false,
  13. favourite: true,
  14. },
  15. }
  16. end
  17. subject { described_class.new(data: data) }
  18. describe '#pushable?' do
  19. let(:notification_type) { :mention }
  20. let(:notification) { Fabricate(:notification, account: account, type: notification_type) }
  21. %i(mention reblog follow follow_request favourite).each do |type|
  22. context "when notification is a #{type}" do
  23. let(:notification_type) { type }
  24. it "returns boolean corresponding to alert setting" do
  25. expect(subject.pushable?(notification)).to eq data[:alerts][type]
  26. end
  27. end
  28. end
  29. context 'when policy is all' do
  30. let(:policy) { 'all' }
  31. it 'returns true' do
  32. expect(subject.pushable?(notification)).to eq true
  33. end
  34. end
  35. context 'when policy is none' do
  36. let(:policy) { 'none' }
  37. it 'returns false' do
  38. expect(subject.pushable?(notification)).to eq false
  39. end
  40. end
  41. context 'when policy is followed' do
  42. let(:policy) { 'followed' }
  43. context 'and notification is from someone you follow' do
  44. before do
  45. account.follow!(notification.from_account)
  46. end
  47. it 'returns true' do
  48. expect(subject.pushable?(notification)).to eq true
  49. end
  50. end
  51. context 'and notification is not from someone you follow' do
  52. it 'returns false' do
  53. expect(subject.pushable?(notification)).to eq false
  54. end
  55. end
  56. end
  57. context 'when policy is follower' do
  58. let(:policy) { 'follower' }
  59. context 'and notification is from someone who follows you' do
  60. before do
  61. notification.from_account.follow!(account)
  62. end
  63. it 'returns true' do
  64. expect(subject.pushable?(notification)).to eq true
  65. end
  66. end
  67. context 'and notification is not from someone who follows you' do
  68. it 'returns false' do
  69. expect(subject.pushable?(notification)).to eq false
  70. end
  71. end
  72. end
  73. end
  74. end