2017-02-05 17:51:56 -08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Api::V1::MutesController, type: :controller do
|
|
|
|
render_views
|
|
|
|
|
2018-08-26 12:30:17 -07:00
|
|
|
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
|
|
|
let(:scopes) { 'read:mutes' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
2017-02-05 17:51:56 -08:00
|
|
|
|
2018-08-26 12:30:17 -07:00
|
|
|
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
2017-02-05 17:51:56 -08:00
|
|
|
|
|
|
|
describe 'GET #index' do
|
2018-08-26 12:30:17 -07:00
|
|
|
it 'limits according to limit parameter' do
|
|
|
|
2.times.map { Fabricate(:mute, account: user.account) }
|
2017-05-31 11:27:34 -07:00
|
|
|
get :index, params: { limit: 1 }
|
2018-08-26 12:30:17 -07:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries mutes in range according to max_id' do
|
|
|
|
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
|
|
|
|
|
|
|
|
get :index, params: { max_id: mutes[1] }
|
2017-05-31 11:27:34 -07:00
|
|
|
|
2018-08-26 12:30:17 -07:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq mutes[0].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries mutes in range according to since_id' do
|
|
|
|
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
|
|
|
|
|
|
|
|
get :index, params: { since_id: mutes[0] }
|
|
|
|
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq mutes[1].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets pagination header for next path' do
|
|
|
|
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
|
|
|
|
get :index, params: { limit: 1, since_id: mutes[0] }
|
|
|
|
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets pagination header for previous path' do
|
|
|
|
mute = Fabricate(:mute, account: user.account)
|
|
|
|
get :index
|
|
|
|
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_mutes_url(since_id: mute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :index
|
2018-04-21 12:35:07 -07:00
|
|
|
expect(response).to have_http_status(200)
|
2017-02-05 17:51:56 -08:00
|
|
|
end
|
2018-08-26 12:30:17 -07:00
|
|
|
|
|
|
|
context 'with wrong scopes' do
|
|
|
|
let(:scopes) { 'write:mutes' }
|
|
|
|
|
|
|
|
it 'returns http forbidden' do
|
|
|
|
get :index
|
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
2017-02-05 17:51:56 -08:00
|
|
|
end
|
2017-09-02 10:24:58 -07:00
|
|
|
|
|
|
|
describe 'GET #details' do
|
2017-09-02 11:19:19 -07:00
|
|
|
before do
|
2018-08-27 08:30:42 -07:00
|
|
|
Fabricate(:mute, account: user.account, hide_notifications: false)
|
2017-09-02 10:24:58 -07:00
|
|
|
get :details, params: { limit: 1 }
|
2017-09-02 11:19:19 -07:00
|
|
|
end
|
2017-09-02 10:24:58 -07:00
|
|
|
|
2017-09-02 11:19:19 -07:00
|
|
|
let(:mutes) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2017-09-02 10:24:58 -07:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
2017-09-02 11:19:19 -07:00
|
|
|
|
|
|
|
it 'returns one mute' do
|
|
|
|
expect(mutes.size).to be(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns whether the mute hides notifications' do
|
|
|
|
expect(mutes.first["hide_notifications"]).to be(false)
|
|
|
|
end
|
2017-09-02 10:24:58 -07:00
|
|
|
end
|
2017-02-05 17:51:56 -08:00
|
|
|
end
|