2017-04-26 18:19:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe AuthorizeInteractionsController do
|
2017-04-28 09:12:37 -04:00
|
|
|
render_views
|
|
|
|
|
2017-04-26 18:19:53 -04: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
|
|
|
|
|
2023-07-27 10:11:17 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2017-04-26 18:19:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders error when account cant be found' do
|
2023-06-22 08:55:22 -04:00
|
|
|
service = instance_double(ResolveAccountService)
|
2018-01-22 08:25:09 -05:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
2017-04-26 18:19:53 -04:00
|
|
|
allow(service).to receive(:call).with('missing@hostname').and_return(nil)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'acct:missing@hostname' }
|
|
|
|
|
2023-07-27 10:11:17 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2017-04-26 18:19:53 -04:00
|
|
|
expect(service).to have_received(:call).with('missing@hostname')
|
|
|
|
end
|
|
|
|
|
2018-08-17 21:03:12 -04:00
|
|
|
it 'sets resource from url' do
|
2022-10-20 08:35:29 -04:00
|
|
|
account = Fabricate(:account)
|
2023-06-22 08:55:22 -04:00
|
|
|
service = instance_double(ResolveURLService)
|
2018-08-17 21:03:12 -04:00
|
|
|
allow(ResolveURLService).to receive(:new).and_return(service)
|
2017-04-26 18:19:53 -04:00
|
|
|
allow(service).to receive(:call).with('http://example.com').and_return(account)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'http://example.com' }
|
|
|
|
|
2024-09-03 11:23:16 -04:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(302)
|
|
|
|
.and redirect_to(web_url("@#{account.pretty_acct}"))
|
2017-04-26 18:19:53 -04:00
|
|
|
end
|
|
|
|
|
2018-08-17 21:03:12 -04:00
|
|
|
it 'sets resource from acct uri' do
|
2022-10-20 08:35:29 -04:00
|
|
|
account = Fabricate(:account)
|
2023-06-22 08:55:22 -04:00
|
|
|
service = instance_double(ResolveAccountService)
|
2018-01-22 08:25:09 -05:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service)
|
2017-04-26 18:19:53 -04:00
|
|
|
allow(service).to receive(:call).with('found@hostname').and_return(account)
|
|
|
|
|
|
|
|
get :show, params: { acct: 'acct:found@hostname' }
|
|
|
|
|
2024-09-03 11:23:16 -04:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(302)
|
|
|
|
.and redirect_to(web_url("@#{account.pretty_acct}"))
|
2017-04-26 18:19:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|