2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
RSpec.describe Admin::PropagateServiceTemplate do
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.propagate' do
|
|
|
|
let!(:service_template) do
|
2020-11-24 15:15:51 +05:30
|
|
|
PushoverService.create!(
|
2017-08-17 22:00:37 +05:30
|
|
|
template: true,
|
|
|
|
active: true,
|
2020-05-24 23:13:21 +05:30
|
|
|
push_events: false,
|
2017-08-17 22:00:37 +05:30
|
|
|
properties: {
|
|
|
|
device: 'MyDevice',
|
|
|
|
sound: 'mic',
|
|
|
|
priority: 4,
|
|
|
|
user_key: 'asdf',
|
|
|
|
api_key: '123456789'
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project) { create(:project) }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:excluded_attributes) { %w[id project_id template created_at updated_at default] }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'creates services for projects' do
|
|
|
|
expect(project.pushover_service).to be_nil
|
|
|
|
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
|
|
|
|
expect(project.reload.pushover_service).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates services for a project that has another service' do
|
2020-11-24 15:15:51 +05:30
|
|
|
BambooService.create!(
|
2017-08-17 22:00:37 +05:30
|
|
|
active: true,
|
|
|
|
project: project,
|
|
|
|
properties: {
|
|
|
|
bamboo_url: 'http://gitlab.com',
|
|
|
|
username: 'mic',
|
2020-05-24 23:13:21 +05:30
|
|
|
password: 'password',
|
2017-08-17 22:00:37 +05:30
|
|
|
build_key: 'build'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(project.pushover_service).to be_nil
|
|
|
|
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
|
|
|
|
expect(project.reload.pushover_service).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create the service if it exists already' do
|
2020-11-24 15:15:51 +05:30
|
|
|
other_service = BambooService.create!(
|
2017-08-17 22:00:37 +05:30
|
|
|
template: true,
|
|
|
|
active: true,
|
|
|
|
properties: {
|
|
|
|
bamboo_url: 'http://gitlab.com',
|
|
|
|
username: 'mic',
|
2020-05-24 23:13:21 +05:30
|
|
|
password: 'password',
|
2017-08-17 22:00:37 +05:30
|
|
|
build_key: 'build'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Service.build_from_integration(project.id, service_template).save!
|
|
|
|
Service.build_from_integration(project.id, other_service).save!
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.not_to change { Service.count }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the service containing the template attributes' do
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
|
|
|
|
expect(project.pushover_service.properties).to eq(service_template.properties)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(project.pushover_service.attributes.except(*excluded_attributes))
|
|
|
|
.to eq(service_template.attributes.except(*excluded_attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'service with data fields' do
|
2020-11-24 15:15:51 +05:30
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:service_template) do
|
2020-11-24 15:15:51 +05:30
|
|
|
stub_jira_service_test
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
JiraService.create!(
|
|
|
|
template: true,
|
|
|
|
active: true,
|
|
|
|
push_events: false,
|
|
|
|
url: 'http://jira.instance.com',
|
|
|
|
username: 'user',
|
|
|
|
password: 'secret'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the service containing the template attributes' do
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
|
|
|
|
expect(project.jira_service.attributes.except(*excluded_attributes))
|
|
|
|
.to eq(service_template.attributes.except(*excluded_attributes))
|
|
|
|
|
|
|
|
excluded_attributes = %w[id service_id created_at updated_at]
|
|
|
|
expect(project.jira_service.data_fields.attributes.except(*excluded_attributes))
|
|
|
|
.to eq(service_template.data_fields.attributes.except(*excluded_attributes))
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe 'bulk update', :use_sql_query_cache do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project_total) { 5 }
|
|
|
|
|
|
|
|
before do
|
2020-11-24 15:15:51 +05:30
|
|
|
stub_const('Admin::PropagateServiceTemplate::BATCH_SIZE', 3)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
project_total.times { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates services for all projects' do
|
|
|
|
expect(Service.all.reload.count).to eq(project_total + 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'external tracker' do
|
|
|
|
it 'updates the project external tracker' do
|
2020-10-24 23:57:45 +05:30
|
|
|
service_template.update!(category: 'issue_tracker')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.to change { project.reload.has_external_issue_tracker }.to(true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'external wiki' do
|
|
|
|
it 'updates the project external tracker' do
|
|
|
|
service_template.update!(type: 'ExternalWikiService')
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.to change { project.reload.has_external_wiki }.to(true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|