statuses_controller_spec.rb 2.8 KB

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