authorize_interactions_controller_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 render_template(:error)
  20. end
  21. it 'renders error when account cant be found' do
  22. service = double
  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 render_template(:error)
  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 = double
  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(200)
  36. expect(assigns(:resource)).to eq account
  37. end
  38. it 'sets resource from acct uri' do
  39. account = Fabricate(:account)
  40. service = double
  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(200)
  45. expect(assigns(:resource)).to eq account
  46. end
  47. end
  48. end
  49. describe 'POST #create' do
  50. describe 'when signed out' do
  51. it 'redirects to sign in page' do
  52. post :create
  53. expect(response).to redirect_to(new_user_session_path)
  54. end
  55. end
  56. describe 'when signed in' do
  57. let!(:user) { Fabricate(:user) }
  58. let(:account) { user.account }
  59. before do
  60. sign_in(user)
  61. end
  62. it 'shows error when account not found' do
  63. service = double
  64. allow(ResolveAccountService).to receive(:new).and_return(service)
  65. allow(service).to receive(:call).with('user@hostname').and_return(nil)
  66. post :create, params: { acct: 'acct:user@hostname' }
  67. expect(response).to render_template(:error)
  68. end
  69. it 'follows account when found' do
  70. target_account = Fabricate(:account)
  71. service = double
  72. allow(ResolveAccountService).to receive(:new).and_return(service)
  73. allow(service).to receive(:call).with('user@hostname').and_return(target_account)
  74. post :create, params: { acct: 'acct:user@hostname' }
  75. expect(account.following?(target_account)).to be true
  76. expect(response).to render_template(:success)
  77. end
  78. end
  79. end
  80. end