relationships_controller_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. require 'rails_helper'
  2. describe Api::V1::Accounts::RelationshipsController do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:follows') }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'GET #index' do
  10. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  11. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  12. before do
  13. user.account.follow!(simon)
  14. lewis.follow!(user.account)
  15. end
  16. context 'provided only one ID' do
  17. before do
  18. get :index, params: { id: simon.id }
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(200)
  22. end
  23. it 'returns JSON with correct data' do
  24. json = body_as_json
  25. expect(json).to be_a Enumerable
  26. expect(json.first[:following]).to be true
  27. expect(json.first[:followed_by]).to be false
  28. end
  29. end
  30. context 'provided multiple IDs' do
  31. before do
  32. get :index, params: { id: [simon.id, lewis.id] }
  33. end
  34. it 'returns http success' do
  35. expect(response).to have_http_status(200)
  36. end
  37. it 'returns JSON with correct data' do
  38. json = body_as_json
  39. expect(json).to be_a Enumerable
  40. expect(json.first[:id]).to eq simon.id.to_s
  41. expect(json.first[:following]).to be true
  42. expect(json.first[:showing_reblogs]).to be true
  43. expect(json.first[:followed_by]).to be false
  44. expect(json.first[:muting]).to be false
  45. expect(json.first[:requested]).to be false
  46. expect(json.first[:domain_blocking]).to be false
  47. expect(json.second[:id]).to eq lewis.id.to_s
  48. expect(json.second[:following]).to be false
  49. expect(json.second[:showing_reblogs]).to be false
  50. expect(json.second[:followed_by]).to be true
  51. expect(json.second[:muting]).to be false
  52. expect(json.second[:requested]).to be false
  53. expect(json.second[:domain_blocking]).to be false
  54. end
  55. it 'returns JSON with correct data on cached requests too' do
  56. get :index, params: { id: [simon.id] }
  57. json = body_as_json
  58. expect(json).to be_a Enumerable
  59. expect(json.first[:following]).to be true
  60. expect(json.first[:showing_reblogs]).to be true
  61. end
  62. it 'returns JSON with correct data after change too' do
  63. user.account.unfollow!(simon)
  64. get :index, params: { id: [simon.id] }
  65. json = body_as_json
  66. expect(json).to be_a Enumerable
  67. expect(json.first[:following]).to be false
  68. expect(json.first[:showing_reblogs]).to be false
  69. end
  70. end
  71. end
  72. end