闭社主体 forked from https://github.com/tootsuite/mastodon
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.

37 lines
1.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe FollowRemoteAccountService do
  3. subject { FollowRemoteAccountService.new }
  4. before do
  5. stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
  6. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  7. stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
  8. stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:catsrgr8@quitter.no").to_return(status: 404)
  9. stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  10. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  11. end
  12. it 'raises error if no such user can be resolved via webfinger' do
  13. expect { subject.call('catsrgr8@quitter.no') }.to raise_error Goldfinger::Error
  14. end
  15. it 'raises error if the domain does not have webfinger' do
  16. expect { subject.call('catsrgr8@example.com') }.to raise_error Goldfinger::Error
  17. end
  18. it 'returns an already existing remote account' do
  19. old_account = Fabricate(:account, username: 'gargron', domain: 'quitter.no')
  20. returned_account = subject.call('gargron@quitter.no')
  21. expect(old_account.id).to eq returned_account.id
  22. end
  23. it 'returns a new remote account' do
  24. account = subject.call('gargron@quitter.no')
  25. expect(account.username).to eq 'gargron'
  26. expect(account.domain).to eq 'quitter.no'
  27. expect(account.remote_url).to eq 'https://quitter.no/api/statuses/user_timeline/7477.atom'
  28. end
  29. end