statuses_controller_spec.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Accounts::StatusesController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses') }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #index' do
  11. it 'returns expected headers', :aggregate_failures do
  12. Fabricate(:status, account: user.account)
  13. get :index, params: { account_id: user.account.id, limit: 1 }
  14. expect(response).to have_http_status(200)
  15. expect(response.headers['Link'].links.size).to eq(2)
  16. end
  17. context 'with only media' do
  18. it 'returns http success' do
  19. get :index, params: { account_id: user.account.id, only_media: true }
  20. expect(response).to have_http_status(200)
  21. end
  22. end
  23. context 'with exclude replies' do
  24. let!(:status) { Fabricate(:status, account: user.account) }
  25. let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }
  26. before do
  27. Fabricate(:status, account: user.account, thread: Fabricate(:status)) # Reply to another user
  28. get :index, params: { account_id: user.account.id, exclude_replies: true }
  29. end
  30. it 'returns posts along with self replies', :aggregate_failures do
  31. expect(response)
  32. .to have_http_status(200)
  33. expect(body_as_json)
  34. .to have_attributes(size: 2)
  35. .and contain_exactly(
  36. include(id: status.id.to_s),
  37. include(id: status_self_reply.id.to_s)
  38. )
  39. end
  40. end
  41. context 'with only own pinned' do
  42. before do
  43. Fabricate(:status_pin, account: user.account, status: Fabricate(:status, account: user.account))
  44. end
  45. it 'returns http success' do
  46. get :index, params: { account_id: user.account.id, pinned: true }
  47. expect(response).to have_http_status(200)
  48. end
  49. end
  50. context "with someone else's pinned statuses" do
  51. let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  52. let(:status) { Fabricate(:status, account: account) }
  53. let(:private_status) { Fabricate(:status, account: account, visibility: :private) }
  54. before do
  55. Fabricate(:status_pin, account: account, status: status)
  56. Fabricate(:status_pin, account: account, status: private_status)
  57. end
  58. it 'returns http success' do
  59. get :index, params: { account_id: account.id, pinned: true }
  60. expect(response).to have_http_status(200)
  61. end
  62. context 'when user does not follow account' do
  63. it 'lists the public status only' do
  64. get :index, params: { account_id: account.id, pinned: true }
  65. json = body_as_json
  66. expect(json.map { |item| item[:id].to_i }).to eq [status.id]
  67. end
  68. end
  69. context 'when user follows account' do
  70. before do
  71. user.account.follow!(account)
  72. end
  73. it 'lists both the public and the private statuses' do
  74. get :index, params: { account_id: account.id, pinned: true }
  75. json = body_as_json
  76. expect(json.map { |item| item[:id].to_i }).to contain_exactly(status.id, private_status.id)
  77. end
  78. end
  79. end
  80. end
  81. end