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.

45 lines
1.9 KiB

  1. require 'rails_helper'
  2. describe Pubsubhubbub::DistributionWorker do
  3. subject { Pubsubhubbub::DistributionWorker.new }
  4. let!(:alice) { Fabricate(:account, username: 'alice') }
  5. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example2.com') }
  6. let!(:anonymous_subscription) { Fabricate(:subscription, account: alice, callback_url: 'http://example1.com', confirmed: true, lease_seconds: 3600) }
  7. let!(:subscription_with_follower) { Fabricate(:subscription, account: alice, callback_url: 'http://example2.com', confirmed: true, lease_seconds: 3600) }
  8. before do
  9. bob.follow!(alice)
  10. end
  11. describe 'with public status' do
  12. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :public) }
  13. it 'delivers payload to all subscriptions' do
  14. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  15. subject.perform(status.stream_entry.id)
  16. expect(Pubsubhubbub::DeliveryWorker).to have_received(:push_bulk).with([anonymous_subscription, subscription_with_follower])
  17. end
  18. end
  19. describe 'with private status' do
  20. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :private) }
  21. it 'delivers payload only to subscriptions with followers' do
  22. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  23. subject.perform(status.stream_entry.id)
  24. expect(Pubsubhubbub::DeliveryWorker).to have_received(:push_bulk).with([subscription_with_follower])
  25. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk).with([anonymous_subscription])
  26. end
  27. end
  28. describe 'with direct status' do
  29. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :direct) }
  30. it 'does not deliver payload' do
  31. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  32. subject.perform(status.stream_entry.id)
  33. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk)
  34. end
  35. end
  36. end