following_accounts_controller_spec.rb 3.5 KB

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