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.

144 lines
3.7 KiB

  1. require 'rails_helper'
  2. describe FollowingAccountsController do
  3. render_views
  4. let(:alice) { Fabricate(:user).account }
  5. let(:followee0) { Fabricate(:account) }
  6. let(:followee1) { Fabricate(:account) }
  7. describe 'GET #index' do
  8. let!(:follow0) { alice.follow!(followee0) }
  9. let!(:follow1) { alice.follow!(followee1) }
  10. context 'when format is html' do
  11. subject(:response) { get :index, params: { account_username: alice.username, format: :html } }
  12. context 'when account is permanently suspended' do
  13. before do
  14. alice.suspend!
  15. alice.deletion_request.destroy
  16. end
  17. it 'returns http gone' do
  18. expect(response).to have_http_status(410)
  19. end
  20. end
  21. context 'when account is temporarily suspended' do
  22. before do
  23. alice.suspend!
  24. end
  25. it 'returns http forbidden' do
  26. expect(response).to have_http_status(403)
  27. end
  28. end
  29. it 'assigns follows' do
  30. expect(response).to have_http_status(200)
  31. assigned = assigns(:follows).to_a
  32. expect(assigned.size).to eq 2
  33. expect(assigned[0]).to eq follow1
  34. expect(assigned[1]).to eq follow0
  35. end
  36. it 'does not assign blocked users' do
  37. user = Fabricate(:user)
  38. user.account.block!(followee0)
  39. sign_in(user)
  40. expect(response).to have_http_status(200)
  41. assigned = assigns(:follows).to_a
  42. expect(assigned.size).to eq 1
  43. expect(assigned[0]).to eq follow1
  44. end
  45. end
  46. context 'when format is json' do
  47. subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
  48. subject(:body) { JSON.parse(response.body) }
  49. context 'with page' do
  50. let(:page) { 1 }
  51. it 'returns followers' do
  52. expect(response).to have_http_status(200)
  53. expect(body['totalItems']).to eq 2
  54. expect(body['partOf']).to be_present
  55. end
  56. context 'when account is permanently suspended' do
  57. before do
  58. alice.suspend!
  59. alice.deletion_request.destroy
  60. end
  61. it 'returns http gone' do
  62. expect(response).to have_http_status(410)
  63. end
  64. end
  65. context 'when account is temporarily suspended' do
  66. before do
  67. alice.suspend!
  68. end
  69. it 'returns http forbidden' do
  70. expect(response).to have_http_status(403)
  71. end
  72. end
  73. end
  74. context 'without page' do
  75. let(:page) { nil }
  76. it 'returns followers' do
  77. expect(response).to have_http_status(200)
  78. expect(body['totalItems']).to eq 2
  79. expect(body['partOf']).to be_blank
  80. end
  81. context 'when account hides their network' do
  82. before do
  83. alice.user.settings.hide_network = true
  84. end
  85. it 'returns followers count' do
  86. expect(body['totalItems']).to eq 2
  87. end
  88. it 'does not return items' do
  89. expect(body['items']).to be_blank
  90. expect(body['orderedItems']).to be_blank
  91. expect(body['first']).to be_blank
  92. expect(body['last']).to be_blank
  93. end
  94. end
  95. context 'when account is permanently suspended' do
  96. before do
  97. alice.suspend!
  98. alice.deletion_request.destroy
  99. end
  100. it 'returns http gone' do
  101. expect(response).to have_http_status(410)
  102. end
  103. end
  104. context 'when account is temporarily suspended' do
  105. before do
  106. alice.suspend!
  107. end
  108. it 'returns http forbidden' do
  109. expect(response).to have_http_status(403)
  110. end
  111. end
  112. end
  113. end
  114. end
  115. end