2022-05-07 20:08:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute', feature_category: :runner_fleet do
|
2022-08-27 11:52:29 +05:30
|
|
|
subject(:execute) { described_class.new(runner, project, user).execute }
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
context 'without user' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it 'does not call assign_to on runner and returns error response', :aggregate_failures do
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(runner).not_to receive(:assign_to)
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
is_expected.to be_error
|
|
|
|
expect(execute.message).to eq('user not allowed to assign runner')
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
let(:user) { build(:user) }
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it 'does not call assign_to on runner and returns error message' do
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(runner).not_to receive(:assign_to)
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
is_expected.to be_error
|
|
|
|
expect(execute.message).to eq('user not allowed to assign runner')
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with admin user', :enable_admin_mode do
|
|
|
|
let(:user) { create_default(:user, :admin) }
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it 'calls assign_to on runner and returns success response' do
|
|
|
|
expect(runner).to receive(:assign_to).with(project, user).once.and_call_original
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
is_expected.to be_success
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|