闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

  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