闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AuthorizeFollowsController 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. let(:account) { Fabricate(:account, user: user) }
  15. before do
  16. sign_in(user)
  17. end
  18. it 'renders error without acct param' do
  19. get :show
  20. expect(response).to render_template(:error)
  21. end
  22. it 'renders error when account cant be found' do
  23. service = double
  24. allow(ResolveRemoteAccountService).to receive(:new).and_return(service)
  25. allow(service).to receive(:call).with('missing@hostname').and_return(nil)
  26. get :show, params: { acct: 'acct:missing@hostname' }
  27. expect(response).to render_template(:error)
  28. expect(service).to have_received(:call).with('missing@hostname')
  29. end
  30. it 'sets account from url' do
  31. account = Account.new
  32. service = double
  33. allow(FetchRemoteAccountService).to receive(:new).and_return(service)
  34. allow(service).to receive(:call).with('http://example.com').and_return(account)
  35. get :show, params: { acct: 'http://example.com' }
  36. expect(response).to have_http_status(:success)
  37. expect(assigns(:account)).to eq account
  38. end
  39. it 'sets account from acct uri' do
  40. account = Account.new
  41. service = double
  42. allow(ResolveRemoteAccountService).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).to have_http_status(:success)
  46. expect(assigns(:account)).to eq account
  47. end
  48. end
  49. end
  50. describe 'POST #create' do
  51. describe 'when signed out' do
  52. it 'redirects to sign in page' do
  53. post :create
  54. expect(response).to redirect_to(new_user_session_path)
  55. end
  56. end
  57. describe 'when signed in' do
  58. let(:user) { Fabricate(:user) }
  59. let(:account) { Fabricate(:account, user: user) }
  60. before do
  61. sign_in(user)
  62. end
  63. it 'shows error when account not found' do
  64. service = double
  65. allow(FollowService).to receive(:new).and_return(service)
  66. allow(service).to receive(:call).with(account, 'user@hostname').and_return(nil)
  67. post :create, params: { acct: 'acct:user@hostname' }
  68. expect(service).to have_received(:call).with(account, 'user@hostname')
  69. expect(response).to render_template(:error)
  70. end
  71. it 'follows account when found' do
  72. target_account = Fabricate(:account)
  73. result_account = double(target_account: target_account)
  74. service = double
  75. allow(FollowService).to receive(:new).and_return(service)
  76. allow(service).to receive(:call).with(account, 'user@hostname').and_return(result_account)
  77. post :create, params: { acct: 'acct:user@hostname' }
  78. expect(service).to have_received(:call).with(account, 'user@hostname')
  79. expect(response).to render_template(:success)
  80. end
  81. end
  82. end
  83. end