diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-08-27 17:30:42 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-08-27 18:09:28 +0200 |
commit | 53b7bb9d047cfc8b21ee0540bd3e5285267160fd (patch) | |
tree | 30dcf8694eadb68ca8a9579e312f9c38ad8c09d1 /spec/controllers/api/v1 | |
parent | af934b90710a2ce1099d3ceda5de7bcf0e94595c (diff) | |
parent | 81697997a3fdbb481202a179908958198baaf0dd (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: app/controllers/api/v1/mutes_controller.rb config/locales/simple_form.pl.yml
Diffstat (limited to 'spec/controllers/api/v1')
-rw-r--r-- | spec/controllers/api/v1/mutes_controller_spec.rb | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/spec/controllers/api/v1/mutes_controller_spec.rb b/spec/controllers/api/v1/mutes_controller_spec.rb index 33df32195..95ec17d6f 100644 --- a/spec/controllers/api/v1/mutes_controller_spec.rb +++ b/spec/controllers/api/v1/mutes_controller_spec.rb @@ -3,24 +3,67 @@ require 'rails_helper' RSpec.describe Api::V1::MutesController, type: :controller do render_views - let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:mutes') } + 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) } - before do - Fabricate(:mute, account: user.account, hide_notifications: false) - allow(controller).to receive(:doorkeeper_token) { token } - end + before { allow(controller).to receive(:doorkeeper_token) { token } } describe 'GET #index' do - it 'returns http success' do + it 'limits according to limit parameter' do + 2.times.map { Fabricate(:mute, account: user.account) } get :index, params: { limit: 1 } + 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] } + 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 expect(response).to have_http_status(200) end + + 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 end describe 'GET #details' do before do + Fabricate(:mute, account: user.account, hide_notifications: false) get :details, params: { limit: 1 } end |