following_accounts_controller_spec.rb 1.9 KB

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