logo

mastofe

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

unsubscribe_service_spec.rb (1166B)


  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(/unsubscribe for bob@example.com failed/)
  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