authorize_interactions_controller_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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)
  36. .to have_http_status(302)
  37. .and redirect_to(web_url("@#{account.pretty_acct}"))
  38. end
  39. it 'sets resource from acct uri' do
  40. account = Fabricate(:account)
  41. service = instance_double(ResolveAccountService)
  42. allow(ResolveAccountService).to receive(:new).and_return(service)
  43. allow(service).to receive(:call).with('found@hostname').and_return(account)
  44. get :show, params: { acct: 'acct:found@hostname' }
  45. expect(response)
  46. .to have_http_status(302)
  47. .and redirect_to(web_url("@#{account.pretty_acct}"))
  48. end
  49. end
  50. end
  51. end