follow_requests_controller_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::FollowRequestsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice', locked: true)) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:follower) { Fabricate(:account, username: 'bob') }
  7. before do
  8. FollowService.new.call(follower, user.account.acct)
  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. end
  32. describe 'POST #reject' do
  33. let(:scopes) { 'write:follows' }
  34. before do
  35. post :reject, params: { id: follower.id }
  36. end
  37. it 'returns http success' do
  38. expect(response).to have_http_status(200)
  39. end
  40. it 'removes follow request' do
  41. expect(FollowRequest.where(target_account: user.account, account: follower).count).to eq 0
  42. end
  43. end
  44. end