follower_accounts_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Accounts FollowerAccounts' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'read:accounts' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let(:account) { Fabricate(:account) }
  9. let(:alice) { Fabricate(:account) }
  10. let(:bob) { Fabricate(:account) }
  11. before do
  12. alice.follow!(account)
  13. bob.follow!(account)
  14. end
  15. describe 'GET /api/v1/accounts/:acount_id/followers' do
  16. it 'returns accounts following the given account', :aggregate_failures do
  17. get "/api/v1/accounts/#{account.id}/followers", params: { limit: 2 }, headers: headers
  18. expect(response).to have_http_status(200)
  19. expect(response.content_type)
  20. .to start_with('application/json')
  21. expect(response.parsed_body)
  22. .to contain_exactly(
  23. hash_including(id: alice.id.to_s),
  24. hash_including(id: bob.id.to_s)
  25. )
  26. end
  27. it 'does not return blocked users', :aggregate_failures do
  28. user.account.block!(bob)
  29. get "/api/v1/accounts/#{account.id}/followers", params: { limit: 2 }, headers: headers
  30. expect(response).to have_http_status(200)
  31. expect(response.content_type)
  32. .to start_with('application/json')
  33. expect(response.parsed_body)
  34. .to contain_exactly(
  35. hash_including(id: alice.id.to_s)
  36. )
  37. end
  38. context 'when requesting user is blocked' do
  39. before do
  40. account.block!(user.account)
  41. end
  42. it 'hides results' do
  43. get "/api/v1/accounts/#{account.id}/followers", params: { limit: 2 }, headers: headers
  44. expect(response.parsed_body.size).to eq 0
  45. end
  46. end
  47. context 'when requesting user is the account owner' do
  48. let(:user) { account.user }
  49. it 'returns all accounts, including muted accounts' do
  50. account.mute!(bob)
  51. get "/api/v1/accounts/#{account.id}/followers", params: { limit: 2 }, headers: headers
  52. expect(response.parsed_body)
  53. .to contain_exactly(
  54. hash_including(id: alice.id.to_s),
  55. hash_including(id: bob.id.to_s)
  56. )
  57. end
  58. end
  59. end
  60. end