2019-09-30 23:59:55 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Ci::CancelUserPipelinesService do
|
2019-09-30 23:59:55 +05:30
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new.execute(user) }
|
|
|
|
|
|
|
|
context 'when user has running CI pipelines' do
|
|
|
|
let(:pipeline) { create(:ci_pipeline, :running, user: user) }
|
|
|
|
let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'cancels all running pipelines and related jobs', :sidekiq_might_not_need_inline do
|
2019-09-30 23:59:55 +05:30
|
|
|
subject
|
|
|
|
|
|
|
|
expect(pipeline.reload).to be_canceled
|
|
|
|
expect(build.reload).to be_canceled
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
context 'when an error ocurrs' do
|
|
|
|
it 'raises a service level error' do
|
|
|
|
service = double(execute: ServiceResponse.error(message: 'Error canceling pipeline'))
|
|
|
|
allow(::Ci::CancelUserPipelinesService).to receive(:new).and_return(service)
|
|
|
|
|
|
|
|
result = subject
|
|
|
|
|
|
|
|
expect(result).to be_a(ServiceResponse)
|
|
|
|
expect(result).to be_error
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 23:59:55 +05:30
|
|
|
end
|
|
|
|
end
|