fetch_remote_account_service_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require 'rails_helper'
  2. RSpec.describe FetchRemoteAccountService, type: :service do
  3. let(:url) { 'https://example.com/alice' }
  4. let(:prefetched_body) { nil }
  5. let(:protocol) { :ostatus }
  6. subject { FetchRemoteAccountService.new.call(url, prefetched_body, protocol) }
  7. let(:actor) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: 'https://example.com/alice',
  11. type: 'Person',
  12. preferredUsername: 'alice',
  13. name: 'Alice',
  14. summary: 'Foo bar',
  15. inbox: 'http://example.com/alice/inbox',
  16. }
  17. end
  18. let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
  19. let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }
  20. shared_examples 'return Account' do
  21. it { is_expected.to be_an Account }
  22. end
  23. context 'protocol is :activitypub' do
  24. let(:prefetched_body) { Oj.dump(actor) }
  25. let(:protocol) { :activitypub }
  26. before do
  27. stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
  28. end
  29. include_examples 'return Account'
  30. end
  31. context 'when prefetched_body is nil' do
  32. context 'protocol is :activitypub' do
  33. before do
  34. stub_request(:get, url).to_return(status: 200, body: Oj.dump(actor), headers: { 'Content-Type' => 'application/activity+json' })
  35. stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
  36. end
  37. include_examples 'return Account'
  38. end
  39. end
  40. end