logo

mastofe

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

unsubscribe_service_spec.rb (1484B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Pubsubhubbub::UnsubscribeService do
  4. describe '#call' do
  5. subject { described_class.new }
  6. context 'with a nil account' do
  7. it 'returns an invalid topic status' do
  8. result = subject.call(nil, 'callback.host')
  9. expect(result).to eq invalid_topic_status
  10. end
  11. end
  12. context 'with a valid account' do
  13. let(:account) { Fabricate(:account) }
  14. it 'returns a valid topic status and does not run confirm when no subscription' do
  15. allow(Pubsubhubbub::ConfirmationWorker).to receive(:perform_async).and_return(nil)
  16. result = subject.call(account, 'callback.host')
  17. expect(result).to eq valid_topic_status
  18. expect(Pubsubhubbub::ConfirmationWorker).not_to have_received(:perform_async)
  19. end
  20. it 'returns a valid topic status and does run confirm when there is a subscription' do
  21. subscription = Fabricate(:subscription, account: account, callback_url: 'callback.host')
  22. allow(Pubsubhubbub::ConfirmationWorker).to receive(:perform_async).and_return(nil)
  23. result = subject.call(account, 'callback.host')
  24. expect(result).to eq valid_topic_status
  25. expect(Pubsubhubbub::ConfirmationWorker).to have_received(:perform_async).with(subscription.id, 'unsubscribe')
  26. end
  27. end
  28. def invalid_topic_status
  29. ['Invalid topic URL', 422]
  30. end
  31. def valid_topic_status
  32. ['', 202]
  33. end
  34. end
  35. end