2020-07-06 05:09:20 -04:00
# frozen_string_literal: true
require 'spec_helper'
RSpec . describe Groups :: UpdateSharedRunnersService do
let ( :user ) { create ( :user ) }
let ( :group ) { create ( :group ) }
let ( :params ) { { } }
describe '#execute' do
subject { described_class . new ( group , user , params ) . execute }
context 'when current_user is not the group owner' do
let_it_be ( :group ) { create ( :group ) }
2020-09-30 11:09:46 -04:00
let ( :params ) { { shared_runners_setting : 'enabled' } }
2020-07-06 05:09:20 -04:00
before do
group . add_maintainer ( user )
end
it 'results error and does not call any method' do
2020-09-30 11:09:46 -04:00
expect ( group ) . not_to receive ( :update_shared_runners_setting! )
2020-07-06 05:09:20 -04:00
expect ( subject [ :status ] ) . to eq ( :error )
expect ( subject [ :message ] ) . to eq ( 'Operation not allowed' )
expect ( subject [ :http_status ] ) . to eq ( 403 )
end
end
context 'when current_user is the group owner' do
before do
group . add_owner ( user )
end
context 'enable shared Runners' do
2020-09-30 11:09:46 -04:00
let ( :params ) { { shared_runners_setting : 'enabled' } }
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
context 'group that its ancestors have shared runners disabled' do
let_it_be ( :parent ) { create ( :group , :shared_runners_disabled ) }
let_it_be ( :group ) { create ( :group , :shared_runners_disabled , parent : parent ) }
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
it 'results error' do
expect ( subject [ :status ] ) . to eq ( :error )
expect ( subject [ :message ] ) . to eq ( 'Validation failed: Shared runners enabled cannot be enabled because parent group has shared Runners disabled' )
2020-07-06 05:09:20 -04:00
end
end
2020-09-30 11:09:46 -04:00
context 'root group with shared runners disabled' do
let_it_be ( :group ) { create ( :group , :shared_runners_disabled ) }
2020-07-06 05:09:20 -04:00
it 'receives correct method and succeeds' do
2020-09-30 11:09:46 -04:00
expect ( group ) . to receive ( :update_shared_runners_setting! ) . with ( 'enabled' )
2020-07-06 05:09:20 -04:00
expect ( subject [ :status ] ) . to eq ( :success )
end
end
end
2020-09-30 11:09:46 -04:00
context 'disable shared Runners' do
let_it_be ( :group ) { create ( :group ) }
let ( :params ) { { shared_runners_setting : 'disabled_and_unoverridable' } }
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
it 'receives correct method and succeeds' do
expect ( group ) . to receive ( :update_shared_runners_setting! ) . with ( 'disabled_and_unoverridable' )
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
expect ( subject [ :status ] ) . to eq ( :success )
2020-07-06 05:09:20 -04:00
end
end
2020-09-30 11:09:46 -04:00
context 'allow descendants to override' do
let ( :params ) { { shared_runners_setting : 'disabled_with_override' } }
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
context 'top level group' do
2020-07-06 05:09:20 -04:00
let_it_be ( :group ) { create ( :group , :shared_runners_disabled ) }
2020-09-30 11:09:46 -04:00
it 'receives correct method and succeeds' do
expect ( group ) . to receive ( :update_shared_runners_setting! ) . with ( 'disabled_with_override' )
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
expect ( subject [ :status ] ) . to eq ( :success )
2020-07-06 05:09:20 -04:00
end
end
2020-09-30 11:09:46 -04:00
context 'when parent does not allow' do
let_it_be ( :parent ) { create ( :group , :shared_runners_disabled , allow_descendants_override_disabled_shared_runners : false ) }
let_it_be ( :group ) { create ( :group , :shared_runners_disabled , allow_descendants_override_disabled_shared_runners : false , parent : parent ) }
2020-07-06 05:09:20 -04:00
2020-09-30 11:09:46 -04:00
it 'results error' do
expect ( subject [ :status ] ) . to eq ( :error )
expect ( subject [ :message ] ) . to eq ( 'Validation failed: Allow descendants override disabled shared runners cannot be enabled because parent group does not allow it' )
2020-07-06 05:09:20 -04:00
end
end
end
end
end
end