follow_requests_controller_spec.rb 1.7 KB

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