1
0

follower_accounts_controller_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FollowerAccountsController do
  4. render_views
  5. let(:alice) { Fabricate(:account, username: 'alice') }
  6. let(:follower_bob) { Fabricate(:account, username: 'bob') }
  7. let(:follower_chris) { Fabricate(:account, username: 'curt') }
  8. describe 'GET #index' do
  9. let!(:follow_from_bob) { follower_bob.follow!(alice) }
  10. let!(:follow_from_chris) { follower_chris.follow!(alice) }
  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. let(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
  33. context 'with page' do
  34. let(:page) { 1 }
  35. it 'returns followers' do
  36. expect(response).to have_http_status(200)
  37. expect(response.parsed_body)
  38. .to include(
  39. orderedItems: contain_exactly(
  40. include(follow_from_bob.account.username),
  41. include(follow_from_chris.account.username)
  42. ),
  43. totalItems: eq(2),
  44. partOf: be_present
  45. )
  46. end
  47. context 'when account is permanently suspended' do
  48. before do
  49. alice.suspend!
  50. alice.deletion_request.destroy
  51. end
  52. it 'returns http gone' do
  53. expect(response).to have_http_status(410)
  54. end
  55. end
  56. context 'when account is temporarily suspended' do
  57. before do
  58. alice.suspend!
  59. end
  60. it 'returns http forbidden' do
  61. expect(response).to have_http_status(403)
  62. end
  63. end
  64. end
  65. context 'without page' do
  66. let(:page) { nil }
  67. it 'returns followers' do
  68. expect(response).to have_http_status(200)
  69. expect(response.parsed_body)
  70. .to include(
  71. totalItems: eq(2)
  72. )
  73. .and not_include(:partOf)
  74. end
  75. context 'when account hides their network' do
  76. before do
  77. alice.update(hide_collections: true)
  78. end
  79. it 'returns followers count but not any items' do
  80. expect(response.parsed_body)
  81. .to include(
  82. totalItems: eq(2)
  83. )
  84. .and not_include(
  85. :items,
  86. :orderedItems,
  87. :first,
  88. :last
  89. )
  90. end
  91. end
  92. context 'when account is permanently suspended' do
  93. before do
  94. alice.suspend!
  95. alice.deletion_request.destroy
  96. end
  97. it 'returns http gone' do
  98. expect(response).to have_http_status(410)
  99. end
  100. end
  101. context 'when account is temporarily suspended' do
  102. before do
  103. alice.suspend!
  104. end
  105. it 'returns http forbidden' do
  106. expect(response).to have_http_status(403)
  107. end
  108. end
  109. end
  110. end
  111. end
  112. end