2017-04-26 15:19:53 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-08-17 18:03:12 -07:00
|
|
|
describe AuthorizeInteractionsController do
|
2017-04-28 06:12:37 -07:00
|
|
|
render_views
|
|
|
|
|
2017-04-26 15:19:53 -07:00
|
|
|
describe 'GET #show' do
|
|
|
|
describe 'when signed out' do
|
|
|
|
it 'redirects to sign in page' do
|
|
|
|
get :show
|
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when signed in' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders error without acct param' do
|
|
|
|
get :show
|
|
|
|
|
|
|
|
expect(response).to render_template(:error)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders error when account cant be found' do
|
|
|
|
service = double
|
2018-01-22 05:25:09 -08:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
2017-04-26 15:19:53 -07:00
|
|
|
allow(service).to receive(:call).with('missing@hostname').and_return(nil)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'acct:missing@hostname' }
|
|
|
|
|
|
|
|
expect(response).to render_template(:error)
|
|
|
|
expect(service).to have_received(:call).with('missing@hostname')
|
|
|
|
end
|
|
|
|
|
2018-08-17 18:03:12 -07:00
|
|
|
it 'sets resource from url' do
|
2022-10-20 05:35:29 -07:00
|
|
|
account = Fabricate(:account)
|
2017-04-26 15:19:53 -07:00
|
|
|
service = double
|
2018-08-17 18:03:12 -07:00
|
|
|
allow(ResolveURLService).to receive(:new).and_return(service)
|
2017-04-26 15:19:53 -07:00
|
|
|
allow(service).to receive(:call).with('http://example.com').and_return(account)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'http://example.com' }
|
|
|
|
|
2018-04-21 12:35:07 -07:00
|
|
|
expect(response).to have_http_status(200)
|
2018-08-17 18:03:12 -07:00
|
|
|
expect(assigns(:resource)).to eq account
|
2017-04-26 15:19:53 -07:00
|
|
|
end
|
|
|
|
|
2018-08-17 18:03:12 -07:00
|
|
|
it 'sets resource from acct uri' do
|
2022-10-20 05:35:29 -07:00
|
|
|
account = Fabricate(:account)
|
2017-04-26 15:19:53 -07:00
|
|
|
service = double
|
2018-01-22 05:25:09 -08:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
2017-04-26 15:19:53 -07:00
|
|
|
allow(service).to receive(:call).with('found@hostname').and_return(account)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'acct:found@hostname' }
|
|
|
|
|
2018-04-21 12:35:07 -07:00
|
|
|
expect(response).to have_http_status(200)
|
2018-08-17 18:03:12 -07:00
|
|
|
expect(assigns(:resource)).to eq account
|
2017-04-26 15:19:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
describe 'when signed out' do
|
|
|
|
it 'redirects to sign in page' do
|
|
|
|
post :create
|
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when signed in' do
|
2018-08-17 18:03:12 -07:00
|
|
|
let!(:user) { Fabricate(:user) }
|
2022-01-27 15:46:42 -08:00
|
|
|
let(:account) { user.account }
|
2017-04-26 15:19:53 -07:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows error when account not found' do
|
|
|
|
service = double
|
2018-08-17 18:03:12 -07:00
|
|
|
|
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
|
|
|
allow(service).to receive(:call).with('user@hostname').and_return(nil)
|
2017-04-26 15:19:53 -07:00
|
|
|
|
|
|
|
post :create, params: { acct: 'acct:user@hostname' }
|
|
|
|
|
|
|
|
expect(response).to render_template(:error)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'follows account when found' do
|
2017-07-10 09:05:06 -07:00
|
|
|
target_account = Fabricate(:account)
|
2017-04-26 15:19:53 -07:00
|
|
|
service = double
|
2018-08-17 18:03:12 -07:00
|
|
|
|
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
|
|
|
allow(service).to receive(:call).with('user@hostname').and_return(target_account)
|
2018-11-08 12:05:42 -08:00
|
|
|
|
2017-04-26 15:19:53 -07:00
|
|
|
|
|
|
|
post :create, params: { acct: 'acct:user@hostname' }
|
|
|
|
|
2018-08-17 18:03:12 -07:00
|
|
|
expect(account.following?(target_account)).to be true
|
2017-07-10 09:05:06 -07:00
|
|
|
expect(response).to render_template(:success)
|
2017-04-26 15:19:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|