favourited_by_accounts_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Statuses Favourited by Accounts' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:accounts' }
  6. # let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  9. let(:alice) { Fabricate(:account) }
  10. let(:bob) { Fabricate(:account) }
  11. context 'with an oauth token' do
  12. subject do
  13. get "/api/v1/statuses/#{status.id}/favourited_by", headers: headers, params: { limit: 2 }
  14. end
  15. describe 'GET /api/v1/statuses/:status_id/favourited_by' do
  16. let(:status) { Fabricate(:status, account: user.account) }
  17. before do
  18. Favourite.create!(account: alice, status: status)
  19. Favourite.create!(account: bob, status: status)
  20. end
  21. it 'returns http success and accounts who favourited the status' do
  22. subject
  23. expect(response)
  24. .to have_http_status(200)
  25. expect(response.headers['Link'].links.size)
  26. .to eq(2)
  27. expect(body_as_json.size)
  28. .to eq(2)
  29. expect(body_as_json)
  30. .to contain_exactly(
  31. include(id: alice.id.to_s),
  32. include(id: bob.id.to_s)
  33. )
  34. end
  35. it 'does not return blocked users' do
  36. user.account.block!(bob)
  37. subject
  38. expect(body_as_json.size)
  39. .to eq 1
  40. expect(body_as_json.first[:id]).to eq(alice.id.to_s)
  41. end
  42. end
  43. end
  44. context 'without an oauth token' do
  45. subject do
  46. get "/api/v1/statuses/#{status.id}/favourited_by", params: { limit: 2 }
  47. end
  48. context 'with a private status' do
  49. let(:status) { Fabricate(:status, account: user.account, visibility: :private) }
  50. describe 'GET #index' do
  51. before do
  52. Fabricate(:favourite, status: status)
  53. end
  54. it 'returns http unauthorized' do
  55. subject
  56. expect(response).to have_http_status(404)
  57. end
  58. end
  59. end
  60. context 'with a public status' do
  61. let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
  62. describe 'GET #index' do
  63. before do
  64. Fabricate(:favourite, status: status)
  65. end
  66. it 'returns http success' do
  67. subject
  68. expect(response).to have_http_status(200)
  69. end
  70. end
  71. end
  72. end
  73. end