闭社主体 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.

46 lines
2.0 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(:perform_async)
  15. subject.perform(status.stream_entry.id)
  16. expect(Pubsubhubbub::DeliveryWorker).to have_received(:perform_async).with(subscription_with_follower.id, /.*/)
  17. expect(Pubsubhubbub::DeliveryWorker).to have_received(:perform_async).with(anonymous_subscription.id, /.*/)
  18. end
  19. end
  20. describe 'with private status' do
  21. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :private) }
  22. it 'delivers payload only to subscriptions with followers' do
  23. allow(Pubsubhubbub::DeliveryWorker).to receive(:perform_async)
  24. subject.perform(status.stream_entry.id)
  25. expect(Pubsubhubbub::DeliveryWorker).to have_received(:perform_async).with(subscription_with_follower.id, /.*/)
  26. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:perform_async).with(anonymous_subscription.id, /.*/)
  27. end
  28. end
  29. describe 'with direct status' do
  30. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :direct) }
  31. it 'does not deliver payload' do
  32. allow(Pubsubhubbub::DeliveryWorker).to receive(:perform_async)
  33. subject.perform(status.stream_entry.id)
  34. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:perform_async)
  35. end
  36. end
  37. end