reblogged_by_accounts_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Statuses Reblogged by Accounts' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:accounts' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let(:alice) { Fabricate(:account) }
  9. let(:bob) { Fabricate(:account) }
  10. context 'with an oauth token' do
  11. subject do
  12. get "/api/v1/statuses/#{status.id}/reblogged_by", headers: headers, params: { limit: 2 }
  13. end
  14. describe 'GET /api/v1/statuses/:status_id/reblogged_by' do
  15. let(:status) { Fabricate(:status, account: user.account) }
  16. before do
  17. Fabricate(:status, account: alice, reblog_of_id: status.id)
  18. Fabricate(:status, account: bob, reblog_of_id: status.id)
  19. end
  20. it 'returns accounts who reblogged the status', :aggregate_failures do
  21. subject
  22. expect(response)
  23. .to have_http_status(200)
  24. .and include_pagination_headers(
  25. prev: api_v1_status_reblogged_by_index_url(limit: 2, since_id: bob.statuses.first.id),
  26. next: api_v1_status_reblogged_by_index_url(limit: 2, max_id: alice.statuses.first.id)
  27. )
  28. expect(response.content_type)
  29. .to start_with('application/json')
  30. expect(response.parsed_body)
  31. .to contain_exactly(
  32. include(id: alice.id.to_s),
  33. include(id: bob.id.to_s)
  34. )
  35. end
  36. it 'does not return blocked users' do
  37. user.account.block!(bob)
  38. subject
  39. expect(response.parsed_body)
  40. .to contain_exactly(
  41. hash_including(id: alice.id.to_s)
  42. )
  43. end
  44. end
  45. end
  46. context 'without an oauth token' do
  47. subject do
  48. get "/api/v1/statuses/#{status.id}/reblogged_by", params: { limit: 2 }
  49. end
  50. context 'with a private status' do
  51. let(:status) { Fabricate(:status, account: user.account, visibility: :private) }
  52. describe 'GET #index' do
  53. before do
  54. Fabricate(:status, reblog_of_id: status.id)
  55. end
  56. it 'returns http unauthorized' do
  57. subject
  58. expect(response).to have_http_status(404)
  59. expect(response.content_type)
  60. .to start_with('application/json')
  61. end
  62. end
  63. end
  64. context 'with a public status' do
  65. let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
  66. describe 'GET #index' do
  67. before do
  68. Fabricate(:status, reblog_of_id: status.id)
  69. end
  70. it 'returns http success' do
  71. subject
  72. expect(response).to have_http_status(200)
  73. expect(response.content_type)
  74. .to start_with('application/json')
  75. end
  76. end
  77. end
  78. end
  79. end