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.

122 lines
5.0 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::FetchRepliesService, type: :service do
  3. let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
  4. let(:status) { Fabricate(:status, account: actor) }
  5. let(:collection_uri) { 'http://example.com/replies/1' }
  6. let(:items) do
  7. [
  8. 'http://example.com/self-reply-1',
  9. 'http://example.com/self-reply-2',
  10. 'http://example.com/self-reply-3',
  11. 'http://other.com/other-reply-1',
  12. 'http://other.com/other-reply-2',
  13. 'http://other.com/other-reply-3',
  14. 'http://example.com/self-reply-4',
  15. 'http://example.com/self-reply-5',
  16. 'http://example.com/self-reply-6',
  17. ]
  18. end
  19. let(:payload) do
  20. {
  21. '@context': 'https://www.w3.org/ns/activitystreams',
  22. type: 'Collection',
  23. id: collection_uri,
  24. items: items,
  25. }.with_indifferent_access
  26. end
  27. subject { described_class.new }
  28. describe '#call' do
  29. context 'when the payload is a Collection with inlined replies' do
  30. context 'when passing the collection itself' do
  31. it 'spawns workers for up to 5 replies on the same server' do
  32. allow(FetchReplyWorker).to receive(:push_bulk)
  33. subject.call(status, payload)
  34. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  35. end
  36. end
  37. context 'when passing the URL to the collection' do
  38. before do
  39. stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload))
  40. end
  41. it 'spawns workers for up to 5 replies on the same server' do
  42. allow(FetchReplyWorker).to receive(:push_bulk)
  43. subject.call(status, collection_uri)
  44. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  45. end
  46. end
  47. end
  48. context 'when the payload is an OrderedCollection with inlined replies' do
  49. let(:payload) do
  50. {
  51. '@context': 'https://www.w3.org/ns/activitystreams',
  52. type: 'OrderedCollection',
  53. id: collection_uri,
  54. orderedItems: items,
  55. }.with_indifferent_access
  56. end
  57. context 'when passing the collection itself' do
  58. it 'spawns workers for up to 5 replies on the same server' do
  59. allow(FetchReplyWorker).to receive(:push_bulk)
  60. subject.call(status, payload)
  61. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  62. end
  63. end
  64. context 'when passing the URL to the collection' do
  65. before do
  66. stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload))
  67. end
  68. it 'spawns workers for up to 5 replies on the same server' do
  69. allow(FetchReplyWorker).to receive(:push_bulk)
  70. subject.call(status, collection_uri)
  71. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  72. end
  73. end
  74. end
  75. context 'when the payload is a paginated Collection with inlined replies' do
  76. let(:payload) do
  77. {
  78. '@context': 'https://www.w3.org/ns/activitystreams',
  79. type: 'Collection',
  80. id: collection_uri,
  81. first: {
  82. type: 'CollectionPage',
  83. partOf: collection_uri,
  84. items: items,
  85. }
  86. }.with_indifferent_access
  87. end
  88. context 'when passing the collection itself' do
  89. it 'spawns workers for up to 5 replies on the same server' do
  90. allow(FetchReplyWorker).to receive(:push_bulk)
  91. subject.call(status, payload)
  92. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  93. end
  94. end
  95. context 'when passing the URL to the collection' do
  96. before do
  97. stub_request(:get, collection_uri).to_return(status: 200, body: Oj.dump(payload))
  98. end
  99. it 'spawns workers for up to 5 replies on the same server' do
  100. allow(FetchReplyWorker).to receive(:push_bulk)
  101. subject.call(status, collection_uri)
  102. expect(FetchReplyWorker).to have_received(:push_bulk).with(['http://example.com/self-reply-1', 'http://example.com/self-reply-2', 'http://example.com/self-reply-3', 'http://example.com/self-reply-4', 'http://example.com/self-reply-5'])
  103. end
  104. end
  105. end
  106. end
  107. end