scinote-web/spec/controllers/client_api/permissions_controller_spec.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

2017-12-04 20:25:48 +08:00
require 'rails_helper'
2018-01-31 19:05:45 +08:00
describe ClientApi::PermissionsController, type: :controller, broken: true do
2017-12-04 20:25:48 +08:00
login_user
2017-12-13 15:57:50 +08:00
describe '#status' do
2018-01-08 23:28:20 +08:00
let!(:user) { User.first || create(:user) }
let!(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, user: user, team: team, role: 2 }
2017-12-04 20:25:48 +08:00
let(:params) do
2018-01-08 23:28:20 +08:00
{ requiredPermissions: ['can_read_team'],
resource: { type: 'Team', id: team.id } }
2017-12-04 20:25:48 +08:00
end
2018-01-08 23:28:20 +08:00
2017-12-13 15:57:50 +08:00
let(:subject) { post :status, format: :json, params: params }
2017-12-04 20:25:48 +08:00
it { is_expected.to be_success }
2018-01-08 23:28:20 +08:00
it 'returns an object with the permission' do
body = JSON.parse(subject.body)
expect(body).to eq('can_read_team' => true)
end
it 'raises an error if no required permissions passed' do
expect do
post :status,
format: :json,
params: { resource: { type: 'Team', id: team.id } }
end
.to raise_error(NoMethodError)
end
it 'raises an error if no required resource type invalid' do
expect do
post :status,
format: :json,
params: { requiredPermissions: ['can_read_team'],
resource: { type: 'Banana', id: team.id } }
end
.to raise_error(ArgumentError)
end
it 'raises an error if no required resource id is not present' do
expect do
post :status,
format: :json,
params: { requiredPermissions: ['can_read_team'],
resource: { type: 'Team' } }
end
.to raise_error(ArgumentError)
end
context 'raises an error if can\'t find permission invalid when resource' do
it 'is absent' do
expect do
post :status,
format: :json,
params: { requiredPermissions: ['can_throw_bananas'] }
end
.to raise_error(ArgumentError)
end
it 'is present' do
expect do
post :status,
format: :json,
params: { requiredPermissions: ['can_throw_bananas'],
resource: { type: 'Team', id: team.id } }
end
.to raise_error(ArgumentError)
end
end
2017-12-04 20:25:48 +08:00
end
end