2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe Ci::PipelineScheduleService, feature_category: :continuous_integration do
|
2022-10-11 01:57:18 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:service) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
subject { service.execute(schedule) }
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
let_it_be(:schedule) { create(:ci_pipeline_schedule, project: project, owner: user) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
it 'schedules next run' do
|
|
|
|
expect(schedule).to receive(:schedule_next_run!)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'runs RunPipelineScheduleWorker' do
|
|
|
|
expect(RunPipelineScheduleWorker)
|
|
|
|
.to receive(:perform_async).with(schedule.id, schedule.owner.id)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is nil' do
|
|
|
|
let(:schedule) { create(:ci_pipeline_schedule, project: project, owner: nil) }
|
|
|
|
|
|
|
|
it 'does not raise an error' do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
context 'when the project is missing' do
|
2022-10-11 01:57:18 +05:30
|
|
|
let(:project) { create(:project).tap(&:delete) }
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
it 'does not raise an exception' do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not run RunPipelineScheduleWorker' do
|
|
|
|
expect(RunPipelineScheduleWorker)
|
|
|
|
.not_to receive(:perform_async).with(schedule.id, schedule.owner.id)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|