statuses_spec.rb 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Accounts Statuses' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:statuses' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/accounts/:account_id/statuses' do
  9. it 'returns expected headers', :aggregate_failures do
  10. status = Fabricate(:status, account: user.account)
  11. get "/api/v1/accounts/#{user.account.id}/statuses", params: { limit: 1 }, headers: headers
  12. expect(response)
  13. .to have_http_status(200)
  14. .and include_pagination_headers(
  15. prev: api_v1_account_statuses_url(limit: 1, min_id: status.id),
  16. next: api_v1_account_statuses_url(limit: 1, max_id: status.id)
  17. )
  18. expect(response.content_type)
  19. .to start_with('application/json')
  20. end
  21. context 'with only media' do
  22. it 'returns http success' do
  23. get "/api/v1/accounts/#{user.account.id}/statuses", params: { only_media: true }, headers: headers
  24. expect(response).to have_http_status(200)
  25. expect(response.content_type)
  26. .to start_with('application/json')
  27. end
  28. end
  29. context 'with exclude replies' do
  30. let!(:status) { Fabricate(:status, account: user.account) }
  31. let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }
  32. before do
  33. Fabricate(:status, account: user.account, thread: Fabricate(:status)) # Reply to another user
  34. get "/api/v1/accounts/#{user.account.id}/statuses", params: { exclude_replies: true }, headers: headers
  35. end
  36. it 'returns posts along with self replies', :aggregate_failures do
  37. expect(response)
  38. .to have_http_status(200)
  39. expect(response.content_type)
  40. .to start_with('application/json')
  41. expect(response.parsed_body)
  42. .to have_attributes(size: 2)
  43. .and contain_exactly(
  44. include(id: status.id.to_s),
  45. include(id: status_self_reply.id.to_s)
  46. )
  47. end
  48. end
  49. context 'with only own pinned' do
  50. before do
  51. Fabricate(:status_pin, account: user.account, status: Fabricate(:status, account: user.account))
  52. end
  53. it 'returns http success and includes a header link' do
  54. get "/api/v1/accounts/#{user.account.id}/statuses", params: { pinned: true }, headers: headers
  55. expect(response)
  56. .to have_http_status(200)
  57. .and include_pagination_headers(prev: api_v1_account_statuses_url(pinned: true, min_id: Status.first.id))
  58. expect(response.content_type)
  59. .to start_with('application/json')
  60. end
  61. end
  62. context 'with enough pinned statuses to paginate' do
  63. before do
  64. stub_const 'Api::BaseController::DEFAULT_STATUSES_LIMIT', 1
  65. 2.times { Fabricate(:status_pin, account: user.account) }
  66. end
  67. it 'returns http success and header pagination links to prev and next' do
  68. get "/api/v1/accounts/#{user.account.id}/statuses", params: { pinned: true }, headers: headers
  69. expect(response)
  70. .to have_http_status(200)
  71. .and include_pagination_headers(
  72. prev: api_v1_account_statuses_url(pinned: true, min_id: Status.first.id),
  73. next: api_v1_account_statuses_url(pinned: true, max_id: Status.first.id)
  74. )
  75. expect(response.content_type)
  76. .to start_with('application/json')
  77. end
  78. end
  79. context "with someone else's pinned statuses" do
  80. let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  81. let(:status) { Fabricate(:status, account: account) }
  82. let(:private_status) { Fabricate(:status, account: account, visibility: :private) }
  83. before do
  84. Fabricate(:status_pin, account: account, status: status)
  85. Fabricate(:status_pin, account: account, status: private_status)
  86. end
  87. it 'returns http success' do
  88. get "/api/v1/accounts/#{account.id}/statuses", params: { pinned: true }, headers: headers
  89. expect(response).to have_http_status(200)
  90. expect(response.content_type)
  91. .to start_with('application/json')
  92. end
  93. context 'when user does not follow account' do
  94. it 'lists the public status only' do
  95. get "/api/v1/accounts/#{account.id}/statuses", params: { pinned: true }, headers: headers
  96. expect(response.parsed_body)
  97. .to contain_exactly(
  98. a_hash_including(id: status.id.to_s)
  99. )
  100. end
  101. end
  102. context 'when user follows account' do
  103. before do
  104. user.account.follow!(account)
  105. end
  106. it 'lists both the public and the private statuses' do
  107. get "/api/v1/accounts/#{account.id}/statuses", params: { pinned: true }, headers: headers
  108. expect(response.parsed_body)
  109. .to contain_exactly(
  110. a_hash_including(id: status.id.to_s),
  111. a_hash_including(id: private_status.id.to_s)
  112. )
  113. expect(response.content_type)
  114. .to start_with('application/json')
  115. end
  116. end
  117. end
  118. end
  119. end