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.

40 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe ActivityPub::FetchRepliesWorker do
  4. subject { described_class.new }
  5. let(:account) { Fabricate(:account, uri: 'https://example.com/user/1') }
  6. let(:status) { Fabricate(:status, account: account) }
  7. let(:payload) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: 'https://example.com/statuses_replies/1',
  11. type: 'Collection',
  12. items: [],
  13. }
  14. end
  15. let(:json) { Oj.dump(payload) }
  16. describe 'perform' do
  17. it 'performs a request if the collection URI is from the same host' do
  18. stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json)
  19. subject.perform(status.id, 'https://example.com/statuses_replies/1')
  20. expect(a_request(:get, 'https://example.com/statuses_replies/1')).to have_been_made.once
  21. end
  22. it 'does not perform a request if the collection URI is from a different host' do
  23. stub_request(:get, 'https://other.com/statuses_replies/1').to_return(status: 200)
  24. subject.perform(status.id, 'https://other.com/statuses_replies/1')
  25. expect(a_request(:get, 'https://other.com/statuses_replies/1')).to_not have_been_made
  26. end
  27. it 'raises when request fails' do
  28. stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 500)
  29. expect { subject.perform(status.id, 'https://example.com/statuses_replies/1') }.to raise_error Mastodon::UnexpectedResponseError
  30. end
  31. end
  32. end