2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-04 06:13:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-09-08 11:08:41 -04:00
|
|
|
RSpec.describe Admin::PropagateServiceTemplate do
|
2017-05-05 12:01:33 -04:00
|
|
|
describe '.propagate' do
|
2020-09-29 11:10:08 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
2020-02-11 13:08:58 -05:00
|
|
|
let!(:service_template) do
|
2020-09-08 11:08:41 -04:00
|
|
|
PushoverService.create!(
|
2020-02-11 13:08:58 -05:00
|
|
|
template: true,
|
2017-05-04 06:13:33 -04:00
|
|
|
active: true,
|
2020-04-22 11:09:27 -04:00
|
|
|
push_events: false,
|
2017-05-04 06:13:33 -04:00
|
|
|
properties: {
|
|
|
|
device: 'MyDevice',
|
|
|
|
sound: 'mic',
|
|
|
|
priority: 4,
|
|
|
|
user_key: 'asdf',
|
|
|
|
api_key: '123456789'
|
2020-04-22 11:09:27 -04:00
|
|
|
}
|
|
|
|
)
|
2017-05-04 06:13:33 -04:00
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
|
|
|
|
.with(service_template.id, project.id, project.id)
|
2017-05-05 12:57:52 -04:00
|
|
|
|
2020-02-11 13:08:58 -05:00
|
|
|
described_class.propagate(service_template)
|
2017-05-04 10:41:07 -04:00
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
context 'with a project that has another service' do
|
|
|
|
before do
|
|
|
|
BambooService.create!(
|
2020-04-22 11:09:27 -04:00
|
|
|
active: true,
|
2020-09-29 11:10:08 -04:00
|
|
|
project: project,
|
|
|
|
properties: {
|
|
|
|
bamboo_url: 'http://gitlab.com',
|
|
|
|
username: 'mic',
|
|
|
|
password: 'password',
|
|
|
|
build_key: 'build'
|
|
|
|
}
|
2020-04-22 11:09:27 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
|
|
|
|
.with(service_template.id, project.id, project.id)
|
2017-05-05 04:43:56 -04:00
|
|
|
|
2020-02-11 13:08:58 -05:00
|
|
|
described_class.propagate(service_template)
|
2017-05-23 02:52:23 -04:00
|
|
|
end
|
2017-05-05 04:43:56 -04:00
|
|
|
end
|
2017-05-05 10:16:02 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
it 'does not create the service if it exists already' do
|
|
|
|
Service.build_from_integration(service_template, project_id: project.id).save!
|
2017-05-05 10:16:02 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.not_to change { Service.count }
|
2017-05-05 10:16:02 -04:00
|
|
|
end
|
2017-05-04 06:13:33 -04:00
|
|
|
end
|
|
|
|
end
|