mutes_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Mutes' do
  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. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/mutes' do
  9. subject do
  10. get '/api/v1/mutes', headers: headers, params: params
  11. end
  12. let!(:mutes) { Fabricate.times(3, :mute, account: user.account) }
  13. let(:params) { {} }
  14. it_behaves_like 'forbidden for wrong scope', 'write write:mutes'
  15. it 'returns http success' do
  16. subject
  17. expect(response).to have_http_status(200)
  18. end
  19. it 'returns the muted accounts' do
  20. subject
  21. muted_accounts = mutes.map(&:target_account)
  22. expect(body_as_json.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s })
  23. end
  24. context 'with limit param' do
  25. let(:params) { { limit: 2 } }
  26. it 'returns only the requested number of muted accounts' do
  27. subject
  28. expect(body_as_json.size).to eq(params[:limit])
  29. end
  30. it 'sets the correct pagination headers', :aggregate_failures do
  31. subject
  32. headers = response.headers['Link']
  33. expect(headers.find_link(%w(rel prev)).href).to eq(api_v1_mutes_url(limit: params[:limit], since_id: mutes[2].id.to_s))
  34. expect(headers.find_link(%w(rel next)).href).to eq(api_v1_mutes_url(limit: params[:limit], max_id: mutes[1].id.to_s))
  35. end
  36. end
  37. context 'with max_id param' do
  38. let(:params) { { max_id: mutes[1].id } }
  39. it 'queries mutes in range according to max_id', :aggregate_failures do
  40. subject
  41. body = body_as_json
  42. expect(body.size).to eq 1
  43. expect(body[0][:id]).to eq mutes[0].target_account_id.to_s
  44. end
  45. end
  46. context 'with since_id param' do
  47. let(:params) { { since_id: mutes[0].id } }
  48. it 'queries mutes in range according to since_id', :aggregate_failures do
  49. subject
  50. body = body_as_json
  51. expect(body.size).to eq 2
  52. expect(body[0][:id]).to eq mutes[2].target_account_id.to_s
  53. end
  54. end
  55. context 'without an authentication header' do
  56. let(:headers) { {} }
  57. it 'returns http unauthorized' do
  58. subject
  59. expect(response).to have_http_status(401)
  60. end
  61. end
  62. end
  63. end