statuses_controller_spec.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Fabricate(:status, account: user.account)
  10. end
  11. describe 'GET #index' do
  12. it 'returns expected headers', :aggregate_failures do
  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!(:older_statuses) { user.account.statuses.destroy_all }
  25. let!(:status) { Fabricate(:status, account: user.account) }
  26. let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }
  27. before do
  28. Fabricate(:status, account: user.account, thread: Fabricate(:status)) # Reply to another user
  29. get :index, params: { account_id: user.account.id, exclude_replies: true }
  30. end
  31. it 'returns posts along with self replies', :aggregate_failures do
  32. json = body_as_json
  33. post_ids = json.map { |item| item[:id].to_i }.sort
  34. expect(response).to have_http_status(200)
  35. expect(post_ids).to eq [status.id, status_self_reply.id]
  36. end
  37. end
  38. context 'with only own pinned' do
  39. before do
  40. Fabricate(:status_pin, account: user.account, status: Fabricate(:status, account: user.account))
  41. end
  42. it 'returns http success' do
  43. get :index, params: { account_id: user.account.id, pinned: true }
  44. expect(response).to have_http_status(200)
  45. end
  46. end
  47. context "with someone else's pinned statuses" do
  48. let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  49. let(:status) { Fabricate(:status, account: account) }
  50. let(:private_status) { Fabricate(:status, account: account, visibility: :private) }
  51. before do
  52. Fabricate(:status_pin, account: account, status: status)
  53. Fabricate(:status_pin, account: account, status: private_status)
  54. end
  55. it 'returns http success' do
  56. get :index, params: { account_id: account.id, pinned: true }
  57. expect(response).to have_http_status(200)
  58. end
  59. context 'when user does not follow account' do
  60. it 'lists the public status only' do
  61. get :index, params: { account_id: account.id, pinned: true }
  62. json = body_as_json
  63. expect(json.map { |item| item[:id].to_i }).to eq [status.id]
  64. end
  65. end
  66. context 'when user follows account' do
  67. before do
  68. user.account.follow!(account)
  69. end
  70. it 'lists both the public and the private statuses' do
  71. get :index, params: { account_id: account.id, pinned: true }
  72. json = body_as_json
  73. expect(json.map { |item| item[:id].to_i }).to contain_exactly(status.id, private_status.id)
  74. end
  75. end
  76. end
  77. end
  78. end