2016-02-29 18:42:08 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Api::SalmonController, type: :controller do
|
2016-09-07 22:33:07 +00:00
|
|
|
render_views
|
|
|
|
|
2016-08-18 16:39:35 +00:00
|
|
|
let(:account) { Fabricate(:user, account: Fabricate(:account, username: 'catsrgr8')).account }
|
2016-03-20 12:03:06 +00: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'))
|
|
|
|
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'))
|
|
|
|
end
|
|
|
|
|
2016-02-29 18:42:08 +00:00
|
|
|
describe 'POST #update' do
|
2017-05-30 20:28:58 +00:00
|
|
|
context 'with valid post data' do
|
|
|
|
before do
|
|
|
|
request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
|
|
|
|
post :update, params: { id: account.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains XML in the request body' do
|
|
|
|
expect(request.body.read).to be_a String
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2018-04-21 19:35:07 +00:00
|
|
|
expect(response).to have_http_status(202)
|
2017-05-30 20:28:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates remote account' do
|
|
|
|
expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates status' do
|
|
|
|
expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates mention for target account' do
|
|
|
|
expect(account.mentions.count).to eq 1
|
|
|
|
end
|
2016-03-20 12:03:06 +00:00
|
|
|
end
|
|
|
|
|
2018-02-08 04:00:45 +00:00
|
|
|
context 'with empty post data' do
|
2017-05-30 20:28:58 +00:00
|
|
|
before do
|
|
|
|
request.env['RAW_POST_DATA'] = ''
|
|
|
|
post :update, params: { id: account.id }
|
|
|
|
end
|
2016-03-20 12:03:06 +00:00
|
|
|
|
2017-10-03 21:21:19 +00:00
|
|
|
it 'returns http client error' do
|
|
|
|
expect(response).to have_http_status(400)
|
2017-05-30 20:28:58 +00:00
|
|
|
end
|
2016-03-20 12:03:06 +00:00
|
|
|
end
|
2018-02-08 04:00:45 +00:00
|
|
|
|
|
|
|
context 'with invalid post data' do
|
|
|
|
before do
|
|
|
|
service = double(call: false)
|
|
|
|
allow(VerifySalmonService).to receive(:new).and_return(service)
|
|
|
|
|
|
|
|
request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
|
|
|
|
post :update, params: { id: account.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http client error' do
|
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
end
|
|
|
|
end
|
2016-02-29 18:42:08 +00:00
|
|
|
end
|
|
|
|
end
|