follower_accounts_controller_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. require 'rails_helper'
  2. describe FollowerAccountsController do
  3. render_views
  4. let(:alice) { Fabricate(:account) }
  5. let(:follower0) { Fabricate(:account) }
  6. let(:follower1) { Fabricate(:account) }
  7. describe 'GET #index' do
  8. let!(:follow0) { follower0.follow!(alice) }
  9. let!(:follow1) { follower1.follow!(alice) }
  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!(follower0)
  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.update(hide_collections: 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