2016-09-26 23:42:38 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-03 01:58:48 +09:00
|
|
|
RSpec.describe FetchRemoteAccountService, type: :service do
|
2018-08-23 03:55:14 +09:00
|
|
|
let(:url) { 'https://example.com/alice' }
|
2018-02-11 01:10:58 +09:00
|
|
|
let(:prefetched_body) { nil }
|
|
|
|
let(:protocol) { :ostatus }
|
2019-07-11 21:49:55 +09:00
|
|
|
let!(:representative) { Fabricate(:account) }
|
2019-07-11 01:59:28 +09:00
|
|
|
|
2018-02-11 01:10:58 +09:00
|
|
|
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' }] } }
|
2018-10-08 11:50:11 +09:00
|
|
|
let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }
|
2018-02-11 01:10:58 +09:00
|
|
|
|
|
|
|
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 '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
|
|
|
|
end
|
2016-09-26 23:42:38 +09:00
|
|
|
end
|