2023-07-18 20:05:19 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Mutes' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:scopes) { 'read:mutes' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
|
|
|
|
describe 'GET /api/v1/mutes' do
|
|
|
|
subject do
|
|
|
|
get '/api/v1/mutes', headers: headers, params: params
|
|
|
|
end
|
|
|
|
|
2023-11-21 22:05:59 +09:00
|
|
|
let!(:mutes) { Fabricate.times(2, :mute, account: user.account) }
|
2023-07-18 20:05:19 +09:00
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write write:mutes'
|
|
|
|
|
2024-09-19 19:15:21 +09:00
|
|
|
it 'returns http success with muted accounts' do
|
2023-07-18 20:05:19 +09:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 22:13:04 +09:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-07-18 20:05:19 +09:00
|
|
|
|
|
|
|
muted_accounts = mutes.map(&:target_account)
|
2024-09-06 18:58:46 +09:00
|
|
|
expect(response.parsed_body.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s })
|
2023-07-18 20:05:19 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with limit param' do
|
2023-11-21 22:05:59 +09:00
|
|
|
let(:params) { { limit: 1 } }
|
2023-07-18 20:05:19 +09:00
|
|
|
|
2024-09-19 19:15:21 +09:00
|
|
|
it 'returns only the requested number of muted accounts with pagination headers' do
|
2023-07-18 20:05:19 +09:00
|
|
|
subject
|
|
|
|
|
2024-09-06 18:58:46 +09:00
|
|
|
expect(response.parsed_body.size).to eq(params[:limit])
|
2024-09-20 22:13:04 +09:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-03-15 19:17:45 +09:00
|
|
|
expect(response)
|
|
|
|
.to include_pagination_headers(
|
|
|
|
prev: api_v1_mutes_url(limit: params[:limit], since_id: mutes.last.id),
|
|
|
|
next: api_v1_mutes_url(limit: params[:limit], max_id: mutes.last.id)
|
|
|
|
)
|
2023-07-18 20:05:19 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with max_id param' do
|
|
|
|
let(:params) { { max_id: mutes[1].id } }
|
|
|
|
|
|
|
|
it 'queries mutes in range according to max_id', :aggregate_failures do
|
|
|
|
subject
|
|
|
|
|
2024-09-06 18:58:46 +09:00
|
|
|
expect(response.parsed_body)
|
2024-09-03 17:03:08 +09:00
|
|
|
.to contain_exactly(include(id: mutes.first.target_account_id.to_s))
|
2023-07-18 20:05:19 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with since_id param' do
|
|
|
|
let(:params) { { since_id: mutes[0].id } }
|
|
|
|
|
|
|
|
it 'queries mutes in range according to since_id', :aggregate_failures do
|
|
|
|
subject
|
|
|
|
|
2024-09-06 18:58:46 +09:00
|
|
|
expect(response.parsed_body)
|
2024-09-03 17:03:08 +09:00
|
|
|
.to contain_exactly(include(id: mutes[1].target_account_id.to_s))
|
2023-07-18 20:05:19 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without an authentication header' do
|
|
|
|
let(:headers) { {} }
|
|
|
|
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(401)
|
2024-09-20 22:13:04 +09:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-07-18 20:05:19 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|