闭社主体 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.

108 lines
3.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AuthorizeFollowsController do
  4. describe 'GET #show' do
  5. describe 'when signed out' do
  6. it 'redirects to sign in page' do
  7. get :show
  8. expect(response).to redirect_to(new_user_session_path)
  9. end
  10. end
  11. describe 'when signed in' do
  12. let(:user) { Fabricate(:user) }
  13. let(:account) { Fabricate(:account, user: 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(FollowRemoteAccountService).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 account from url' do
  30. account = double
  31. service = double
  32. allow(FetchRemoteAccountService).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(:success)
  36. expect(service).to have_received(:call).with('http://example.com')
  37. end
  38. it 'sets account from acct uri' do
  39. account = double
  40. service = double
  41. allow(FollowRemoteAccountService).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(:success)
  45. expect(service).to have_received(:call).with('found@hostname')
  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) { Fabricate(:account, user: user) }
  59. before do
  60. sign_in(user)
  61. end
  62. it 'shows error when account not found' do
  63. service = double
  64. allow(FollowService).to receive(:new).and_return(service)
  65. allow(service).to receive(:call).with(account, 'user@hostname').and_return(nil)
  66. post :create, params: { acct: 'acct:user@hostname' }
  67. expect(service).to have_received(:call).with(account, 'user@hostname')
  68. expect(response).to render_template(:error)
  69. end
  70. it 'follows account when found' do
  71. target_account = double(id: '123')
  72. result_account = double(target_account: target_account)
  73. service = double
  74. allow(FollowService).to receive(:new).and_return(service)
  75. allow(service).to receive(:call).with(account, 'user@hostname').and_return(result_account)
  76. post :create, params: { acct: 'acct:user@hostname' }
  77. expect(service).to have_received(:call).with(account, 'user@hostname')
  78. expect(response).to redirect_to(web_url('accounts/123'))
  79. end
  80. end
  81. end
  82. end