follower_accounts_controller_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require 'rails_helper'
  2. describe Api::V1::Accounts::FollowerAccountsController do
  3. render_views
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
  6. let(:account) { Fabricate(:account) }
  7. let(:alice) { Fabricate(:account) }
  8. let(:bob) { Fabricate(:account) }
  9. before do
  10. alice.follow!(account)
  11. bob.follow!(account)
  12. allow(controller).to receive(:doorkeeper_token) { token }
  13. end
  14. describe 'GET #index' do
  15. it 'returns http success' do
  16. get :index, params: { account_id: account.id, limit: 2 }
  17. expect(response).to have_http_status(200)
  18. end
  19. it 'returns accounts following the given account' do
  20. get :index, params: { account_id: account.id, limit: 2 }
  21. expect(body_as_json.size).to eq 2
  22. expect([body_as_json[0][:id], body_as_json[1][:id]]).to match_array([alice.id.to_s, bob.id.to_s])
  23. end
  24. it 'does not return blocked users' do
  25. user.account.block!(bob)
  26. get :index, params: { account_id: account.id, limit: 2 }
  27. expect(body_as_json.size).to eq 1
  28. expect(body_as_json[0][:id]).to eq alice.id.to_s
  29. end
  30. context 'when requesting user is blocked' do
  31. before do
  32. account.block!(user.account)
  33. end
  34. it 'hides results' do
  35. get :index, params: { account_id: account.id, limit: 2 }
  36. expect(body_as_json.size).to eq 0
  37. end
  38. end
  39. context 'when requesting user is the account owner' do
  40. let(:user) { account.user }
  41. it 'returns all accounts, including muted accounts' do
  42. account.mute!(bob)
  43. get :index, params: { account_id: account.id, limit: 2 }
  44. expect(body_as_json.size).to eq 2
  45. expect([body_as_json[0][:id], body_as_json[1][:id]]).to match_array([alice.id.to_s, bob.id.to_s])
  46. end
  47. end
  48. end
  49. end