fetch_remote_resource_service_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe FetchRemoteResourceService do
  4. subject { described_class.new }
  5. describe '#call' do
  6. it 'returns nil when there is no atom url' do
  7. url = 'http://example.com/missing-atom'
  8. service = double
  9. allow(FetchAtomService).to receive(:new).and_return service
  10. allow(service).to receive(:call).with(url).and_return(nil)
  11. result = subject.call(url)
  12. expect(result).to be_nil
  13. end
  14. it 'fetches remote accounts for feed types' do
  15. url = 'http://example.com/atom-feed'
  16. service = double
  17. allow(FetchAtomService).to receive(:new).and_return service
  18. feed_url = 'http://feed-url'
  19. feed_content = '<feed>contents</feed>'
  20. allow(service).to receive(:call).with(url).and_return([feed_url, feed_content])
  21. account_service = double
  22. allow(FetchRemoteAccountService).to receive(:new).and_return(account_service)
  23. allow(account_service).to receive(:call)
  24. _result = subject.call(url)
  25. expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
  26. end
  27. it 'fetches remote statuses for entry types' do
  28. url = 'http://example.com/atom-entry'
  29. service = double
  30. allow(FetchAtomService).to receive(:new).and_return service
  31. feed_url = 'http://feed-url'
  32. feed_content = '<entry>contents</entry>'
  33. allow(service).to receive(:call).with(url).and_return([feed_url, feed_content])
  34. account_service = double
  35. allow(FetchRemoteStatusService).to receive(:new).and_return(account_service)
  36. allow(account_service).to receive(:call)
  37. _result = subject.call(url)
  38. expect(account_service).to have_received(:call).with(feed_url, feed_content, nil)
  39. end
  40. end
  41. end