You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

  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) { double acceptable?: true, resource_owner_id: user.id }
  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(:success)
  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(:success)
  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 be simon.id
  41. expect(json.first[:following]).to be true
  42. expect(json.first[:followed_by]).to be false
  43. expect(json.first[:muting]).to be false
  44. expect(json.first[:requested]).to be false
  45. expect(json.first[:domain_blocking]).to be false
  46. expect(json.second[:id]).to be lewis.id
  47. expect(json.second[:following]).to be false
  48. expect(json.second[:followed_by]).to be true
  49. expect(json.second[:muting]).to be false
  50. expect(json.second[:requested]).to be false
  51. expect(json.second[:domain_blocking]).to be false
  52. end
  53. end
  54. end
  55. end