diff options
author | Kazushige Tominaga <kazu9su@gmail.com> | 2018-02-11 01:10:58 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-02-10 17:10:57 +0100 |
commit | 718802a05dfb3211d758513daf6070ffa22751dd (patch) | |
tree | 78c1bbeb19b009a8ba8b8f0b7766f27df128bf63 /spec/services | |
parent | 411c9ecb4b7396afe95bbf6f191616dcd3fc970c (diff) |
Added FetchRemoteAccountService spec (#6456)
* Added #link_header spec * Added #call spec * Delete spec of private methods * Added #call spec
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/fetch_remote_account_service_spec.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/services/fetch_remote_account_service_spec.rb b/spec/services/fetch_remote_account_service_spec.rb index bb1877c7a..4388d4cf4 100644 --- a/spec/services/fetch_remote_account_service_spec.rb +++ b/spec/services/fetch_remote_account_service_spec.rb @@ -1,4 +1,71 @@ require 'rails_helper' RSpec.describe FetchRemoteAccountService do + let(:url) { 'https://example.com' } + let(:prefetched_body) { nil } + let(:protocol) { :ostatus } + subject { FetchRemoteAccountService.new.call(url, prefetched_body, protocol) } + + let(:actor) do + { + '@context': 'https://www.w3.org/ns/activitystreams', + id: 'https://example.com/alice', + type: 'Person', + preferredUsername: 'alice', + name: 'Alice', + summary: 'Foo bar', + inbox: 'http://example.com/alice/inbox', + } + end + + let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } + let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) } + + shared_examples 'return Account' do + it { is_expected.to be_an Account } + end + + context 'protocol is :activitypub' do + let(:prefetched_body) { Oj.dump(actor) } + let(:protocol) { :activitypub } + + before do + 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' }) + end + + include_examples 'return Account' + end + + context 'protocol is :ostatus' do + let(:prefetched_body) { xml } + let(:protocol) { :ostatus } + + before do + stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt')) + stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) + end + + include_examples 'return Account' + end + + context 'when prefetched_body is nil' do + context 'protocol is :activitypub' do + before do + stub_request(:get, url).to_return(status: 200, body: Oj.dump(actor), headers: { 'Content-Type' => 'application/activity+json' }) + 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' }) + end + + include_examples 'return Account' + end + + context 'protocol is :ostatus' do + before do + stub_request(:get, url).to_return(status: 200, body: xml, headers: { 'Content-Type' => 'application/atom+xml' }) + stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt')) + stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) + end + + include_examples 'return Account' + end + end end |