mutes_controller_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::MutesController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:mutes' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. before { allow(controller).to receive(:doorkeeper_token) { token } }
  8. describe 'GET #index' do
  9. it 'limits according to limit parameter' do
  10. 2.times.map { Fabricate(:mute, account: user.account) }
  11. get :index, params: { limit: 1 }
  12. expect(body_as_json.size).to eq 1
  13. end
  14. it 'queries mutes in range according to max_id' do
  15. mutes = 2.times.map { Fabricate(:mute, account: user.account) }
  16. get :index, params: { max_id: mutes[1] }
  17. expect(body_as_json.size).to eq 1
  18. expect(body_as_json[0][:id]).to eq mutes[0].target_account_id.to_s
  19. end
  20. it 'queries mutes in range according to since_id' do
  21. mutes = 2.times.map { Fabricate(:mute, account: user.account) }
  22. get :index, params: { since_id: mutes[0] }
  23. expect(body_as_json.size).to eq 1
  24. expect(body_as_json[0][:id]).to eq mutes[1].target_account_id.to_s
  25. end
  26. it 'sets pagination header for next path' do
  27. mutes = 2.times.map { Fabricate(:mute, account: user.account) }
  28. get :index, params: { limit: 1, since_id: mutes[0] }
  29. expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
  30. end
  31. it 'sets pagination header for previous path' do
  32. mute = Fabricate(:mute, account: user.account)
  33. get :index
  34. expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_mutes_url(since_id: mute)
  35. end
  36. it 'returns http success' do
  37. get :index
  38. expect(response).to have_http_status(200)
  39. end
  40. context 'with wrong scopes' do
  41. let(:scopes) { 'write:mutes' }
  42. it 'returns http forbidden' do
  43. get :index
  44. expect(response).to have_http_status(403)
  45. end
  46. end
  47. end
  48. end