logo

mastofe

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

push_subscription_spec.rb (1391B)


  1. require 'rails_helper'
  2. RSpec.describe Web::PushSubscription, type: :model do
  3. let(:alerts) { { mention: true, reblog: false, follow: true, follow_request: false, favourite: true } }
  4. let(:payload_no_alerts) { Web::PushSubscription.new(id: 1, endpoint: 'a', key_p256dh: 'c', key_auth: 'd').as_payload }
  5. let(:payload_alerts) { Web::PushSubscription.new(id: 1, endpoint: 'a', key_p256dh: 'c', key_auth: 'd', data: { alerts: alerts }).as_payload }
  6. let(:push_subscription) { Web::PushSubscription.new(data: { alerts: alerts }) }
  7. describe '#as_payload' do
  8. it 'only returns id and endpoint' do
  9. expect(payload_no_alerts.keys).to eq [:id, :endpoint]
  10. end
  11. it 'returns alerts if set' do
  12. expect(payload_alerts.keys).to eq [:id, :endpoint, :alerts]
  13. end
  14. end
  15. describe '#pushable?' do
  16. it 'obeys alert settings' do
  17. expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Mention'))).to eq true
  18. expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Status'))).to eq false
  19. expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Follow'))).to eq true
  20. expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'FollowRequest'))).to eq false
  21. expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Favourite'))).to eq true
  22. end
  23. end
  24. end