unsubscribe_service_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. require 'rails_helper'
  2. RSpec.describe UnsubscribeService do
  3. let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com', hub_url: 'http://hub.example.com') }
  4. subject { UnsubscribeService.new }
  5. it 'removes the secret and resets expiration on account' do
  6. stub_request(:post, 'http://hub.example.com/').to_return(status: 204)
  7. subject.call(account)
  8. account.reload
  9. expect(account.secret).to be_blank
  10. expect(account.subscription_expires_at).to be_blank
  11. end
  12. it 'logs error on subscription failure' do
  13. logger = stub_logger
  14. stub_request(:post, 'http://hub.example.com/').to_return(status: 404)
  15. subject.call(account)
  16. expect(logger).to have_received(:debug).with(/unsubscribe for bob@example.com failed/)
  17. end
  18. it 'logs error on connection failure' do
  19. logger = stub_logger
  20. stub_request(:post, 'http://hub.example.com/').to_raise(HTTP::Error)
  21. subject.call(account)
  22. expect(logger).to have_received(:debug).with(/PuSH subscription request for bob@example.com could not be made due to HTTP or SSL error/)
  23. end
  24. def stub_logger
  25. double(debug: nil).tap do |logger|
  26. allow(Rails).to receive(:logger).and_return(logger)
  27. end
  28. end
  29. end