mutes_spec.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 with muted accounts' do
  16. subject
  17. expect(response).to have_http_status(200)
  18. expect(response.content_type)
  19. .to start_with('application/json')
  20. muted_accounts = mutes.map(&:target_account)
  21. expect(response.parsed_body.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s })
  22. end
  23. context 'with limit param' do
  24. let(:params) { { limit: 1 } }
  25. it 'returns only the requested number of muted accounts with pagination headers' do
  26. subject
  27. expect(response.parsed_body.size).to eq(params[:limit])
  28. expect(response.content_type)
  29. .to start_with('application/json')
  30. expect(response)
  31. .to include_pagination_headers(
  32. prev: api_v1_mutes_url(limit: params[:limit], since_id: mutes.last.id),
  33. next: api_v1_mutes_url(limit: params[:limit], max_id: mutes.last.id)
  34. )
  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. expect(response.parsed_body)
  42. .to contain_exactly(include(id: mutes.first.target_account_id.to_s))
  43. end
  44. end
  45. context 'with since_id param' do
  46. let(:params) { { since_id: mutes[0].id } }
  47. it 'queries mutes in range according to since_id', :aggregate_failures do
  48. subject
  49. expect(response.parsed_body)
  50. .to contain_exactly(include(id: mutes[1].target_account_id.to_s))
  51. end
  52. end
  53. context 'without an authentication header' do
  54. let(:headers) { {} }
  55. it 'returns http unauthorized' do
  56. subject
  57. expect(response).to have_http_status(401)
  58. expect(response.content_type)
  59. .to start_with('application/json')
  60. end
  61. end
  62. end
  63. end