2016-03-07 13:42:33 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2016-09-27 17:58:23 +03:00
|
|
|
RSpec.describe Api::V1::FollowsController, type: :controller do
|
2016-09-08 01:33:07 +03:00
|
|
|
render_views
|
|
|
|
|
2016-03-20 14:03:06 +02:00
|
|
|
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
2017-07-27 16:16:07 +03:00
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
2016-03-20 14:03:06 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:doorkeeper_token) { token }
|
|
|
|
end
|
|
|
|
|
2016-03-19 13:13:47 +02:00
|
|
|
describe 'POST #create' do
|
2016-03-20 14:03:06 +02:00
|
|
|
before do
|
|
|
|
stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
|
|
|
|
stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
|
2017-02-11 15:12:29 +02:00
|
|
|
stub_request(:head, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(:status => 405, :body => "", :headers => {})
|
2016-03-20 14:03:06 +02:00
|
|
|
stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
|
|
|
|
stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
|
|
|
|
stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
|
|
|
|
stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {})
|
|
|
|
|
2016-08-17 18:56:23 +03:00
|
|
|
post :create, params: { uri: 'gargron@quitter.no' }
|
2016-03-20 14:03:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2018-04-21 22:35:07 +03:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-20 14:03:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates account for remote user' do
|
|
|
|
expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a follow relation between user and remote user' do
|
|
|
|
expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends a salmon slap to the remote user' do
|
|
|
|
expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'subscribes to remote hub' do
|
|
|
|
expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
|
|
|
|
end
|
2017-09-10 16:09:06 +03:00
|
|
|
|
|
|
|
it 'returns http success if already following, too' do
|
|
|
|
post :create, params: { uri: 'gargron@quitter.no' }
|
2018-04-21 22:35:07 +03:00
|
|
|
expect(response).to have_http_status(200)
|
2017-09-10 16:09:06 +03:00
|
|
|
end
|
2016-03-19 13:13:47 +02:00
|
|
|
end
|
2016-03-07 13:42:33 +02:00
|
|
|
end
|