logo

mastofe

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

subscribe_service_spec.rb (1599B)


  1. require 'rails_helper'
  2. RSpec.describe SubscribeService do
  3. let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com', hub_url: 'http://hub.example.com') }
  4. subject { SubscribeService.new }
  5. it 'sends subscription request to PuSH hub' do
  6. stub_request(:post, 'http://hub.example.com/').to_return(status: 202)
  7. subject.call(account)
  8. expect(a_request(:post, 'http://hub.example.com/')).to have_been_made.once
  9. end
  10. it 'generates and keeps PuSH secret on successful call' do
  11. stub_request(:post, 'http://hub.example.com/').to_return(status: 202)
  12. subject.call(account)
  13. expect(account.secret).to_not be_blank
  14. end
  15. it 'fails silently if PuSH hub forbids subscription' do
  16. stub_request(:post, 'http://hub.example.com/').to_return(status: 403)
  17. subject.call(account)
  18. end
  19. it 'fails silently if PuSH hub is not found' do
  20. stub_request(:post, 'http://hub.example.com/').to_return(status: 404)
  21. subject.call(account)
  22. end
  23. it 'fails loudly if there is a network error' do
  24. stub_request(:post, 'http://hub.example.com/').to_raise(HTTP::Error)
  25. expect { subject.call(account) }.to raise_error HTTP::Error
  26. end
  27. it 'fails loudly if PuSH hub is unavailable' do
  28. stub_request(:post, 'http://hub.example.com/').to_return(status: 503)
  29. expect { subject.call(account) }.to raise_error Mastodon::UnexpectedResponseError
  30. end
  31. it 'fails loudly if rate limited' do
  32. stub_request(:post, 'http://hub.example.com/').to_return(status: 429)
  33. expect { subject.call(account) }.to raise_error Mastodon::UnexpectedResponseError
  34. end
  35. end