authorize_interactions_controller_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AuthorizeInteractionsController do
  4. render_views
  5. describe 'GET #show' do
  6. describe 'when signed out' do
  7. it 'redirects to sign in page' do
  8. get :show
  9. expect(response).to redirect_to(new_user_session_path)
  10. end
  11. end
  12. describe 'when signed in' do
  13. let(:user) { Fabricate(:user) }
  14. before do
  15. sign_in(user)
  16. end
  17. it 'renders error without acct param' do
  18. get :show
  19. expect(response).to have_http_status(404)
  20. end
  21. it 'renders error when account cant be found' do
  22. service = instance_double(ResolveAccountService)
  23. allow(ResolveAccountService).to receive(:new).and_return(service)
  24. allow(service).to receive(:call).with('missing@hostname').and_return(nil)
  25. get :show, params: { acct: 'acct:missing@hostname' }
  26. expect(response).to have_http_status(404)
  27. expect(service).to have_received(:call).with('missing@hostname')
  28. end
  29. it 'sets resource from url' do
  30. account = Fabricate(:account)
  31. service = instance_double(ResolveURLService)
  32. allow(ResolveURLService).to receive(:new).and_return(service)
  33. allow(service).to receive(:call).with('http://example.com').and_return(account)
  34. get :show, params: { acct: 'http://example.com' }
  35. expect(response).to have_http_status(302)
  36. expect(assigns(:resource)).to eq account
  37. end
  38. it 'sets resource from acct uri' do
  39. account = Fabricate(:account)
  40. service = instance_double(ResolveAccountService)
  41. allow(ResolveAccountService).to receive(:new).and_return(service)
  42. allow(service).to receive(:call).with('found@hostname').and_return(account)
  43. get :show, params: { acct: 'acct:found@hostname' }
  44. expect(response).to have_http_status(302)
  45. expect(assigns(:resource)).to eq account
  46. end
  47. end
  48. end
  49. end