mutes_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(2, :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: 1 } }
  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. expect(response)
  33. .to include_pagination_headers(
  34. prev: api_v1_mutes_url(limit: params[:limit], since_id: mutes.last.id),
  35. next: api_v1_mutes_url(limit: params[:limit], max_id: mutes.last.id)
  36. )
  37. end
  38. end
  39. context 'with max_id param' do
  40. let(:params) { { max_id: mutes[1].id } }
  41. it 'queries mutes in range according to max_id', :aggregate_failures do
  42. subject
  43. body = body_as_json
  44. expect(body.size).to eq 1
  45. expect(body[0][:id]).to eq mutes[0].target_account_id.to_s
  46. end
  47. end
  48. context 'with since_id param' do
  49. let(:params) { { since_id: mutes[0].id } }
  50. it 'queries mutes in range according to since_id', :aggregate_failures do
  51. subject
  52. body = body_as_json
  53. expect(body.size).to eq 1
  54. expect(body[0][:id]).to eq mutes[1].target_account_id.to_s
  55. end
  56. end
  57. context 'without an authentication header' do
  58. let(:headers) { {} }
  59. it 'returns http unauthorized' do
  60. subject
  61. expect(response).to have_http_status(401)
  62. end
  63. end
  64. end
  65. end