follow_requests_controller_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::FollowRequestsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account_attributes: { locked: true }) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:follower) { Fabricate(:account) }
  7. before do
  8. FollowService.new.call(follower, user.account)
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'GET #index' do
  12. let(:scopes) { 'read:follows' }
  13. before do
  14. get :index, params: { limit: 1 }
  15. end
  16. it 'returns http success' do
  17. expect(response).to have_http_status(200)
  18. end
  19. end
  20. describe 'POST #authorize' do
  21. let(:scopes) { 'write:follows' }
  22. before do
  23. post :authorize, params: { id: follower.id }
  24. end
  25. it 'returns http success' do
  26. expect(response).to have_http_status(200)
  27. end
  28. it 'allows follower to follow' do
  29. expect(follower.following?(user.account)).to be true
  30. end
  31. it 'returns JSON with followed_by=true' do
  32. json = body_as_json
  33. expect(json[:followed_by]).to be true
  34. end
  35. end
  36. describe 'POST #reject' do
  37. let(:scopes) { 'write:follows' }
  38. before do
  39. post :reject, params: { id: follower.id }
  40. end
  41. it 'returns http success' do
  42. expect(response).to have_http_status(200)
  43. end
  44. it 'removes follow request' do
  45. expect(FollowRequest.where(target_account: user.account, account: follower).count).to eq 0
  46. end
  47. it 'returns JSON with followed_by=false' do
  48. json = body_as_json
  49. expect(json[:followed_by]).to be false
  50. end
  51. end
  52. end