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.

83 lines
3.2 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. context 'when OStatus privacy is used' do
  20. around do |example|
  21. before_val = Rails.configuration.x.use_ostatus_privacy
  22. Rails.configuration.x.use_ostatus_privacy = true
  23. example.run
  24. Rails.configuration.x.use_ostatus_privacy = before_val
  25. end
  26. describe 'with private status' do
  27. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :private) }
  28. it 'delivers payload only to subscriptions with followers' do
  29. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  30. subject.perform(status.stream_entry.id)
  31. expect(Pubsubhubbub::DeliveryWorker).to have_received(:push_bulk).with([subscription_with_follower])
  32. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk).with([anonymous_subscription])
  33. end
  34. end
  35. describe 'with direct status' do
  36. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :direct) }
  37. it 'does not deliver payload' do
  38. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  39. subject.perform(status.stream_entry.id)
  40. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk)
  41. end
  42. end
  43. end
  44. context 'when OStatus privacy is not used' do
  45. around do |example|
  46. before_val = Rails.configuration.x.use_ostatus_privacy
  47. Rails.configuration.x.use_ostatus_privacy = false
  48. example.run
  49. Rails.configuration.x.use_ostatus_privacy = before_val
  50. end
  51. describe 'with private status' do
  52. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :private) }
  53. it 'does not deliver anything' do
  54. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  55. subject.perform(status.stream_entry.id)
  56. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk)
  57. end
  58. end
  59. describe 'with direct status' do
  60. let(:status) { Fabricate(:status, account: alice, text: 'Hello', visibility: :direct) }
  61. it 'does not deliver payload' do
  62. allow(Pubsubhubbub::DeliveryWorker).to receive(:push_bulk)
  63. subject.perform(status.stream_entry.id)
  64. expect(Pubsubhubbub::DeliveryWorker).to_not have_received(:push_bulk)
  65. end
  66. end
  67. end
  68. end