2020-09-29 11:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkCreateIntegrationService do
|
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
before_all do
|
2021-06-18 11:10:16 -04:00
|
|
|
stub_jira_integration_test
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
let_it_be(:excluded_group) { create(:group) }
|
|
|
|
let_it_be(:excluded_project) { create(:project, group: excluded_group) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:instance_integration) { create(:jira_integration, :instance) }
|
|
|
|
let(:template_integration) { create(:jira_integration, :template) }
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:excluded_attributes) { %w[id project_id group_id inherit_from_id instance template created_at updated_at] }
|
|
|
|
|
|
|
|
shared_examples 'creates integration from batch ids' do
|
|
|
|
it 'updates the inherited integrations' do
|
|
|
|
described_class.new(integration, batch, association).execute
|
|
|
|
|
|
|
|
expect(created_integration.attributes.except(*excluded_attributes))
|
|
|
|
.to eq(integration.attributes.except(*excluded_attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'integration with data fields' do
|
|
|
|
let(:excluded_attributes) { %w[id service_id created_at updated_at] }
|
|
|
|
|
|
|
|
it 'updates the data fields from inherited integrations' do
|
|
|
|
described_class.new(integration, batch, association).execute
|
|
|
|
|
|
|
|
expect(created_integration.reload.data_fields.attributes.except(*excluded_attributes))
|
2021-03-28 02:09:12 -04:00
|
|
|
.to eq(integration.reload.data_fields.attributes.except(*excluded_attributes))
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'updates inherit_from_id' do
|
|
|
|
it 'updates inherit_from_id attributes' do
|
|
|
|
described_class.new(integration, batch, association).execute
|
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
expect(created_integration.reload.inherit_from_id).to eq(inherit_from_id)
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
context 'passing an instance-level integration' do
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:integration) { instance_integration }
|
2020-10-23 14:08:31 -04:00
|
|
|
let(:inherit_from_id) { integration.id }
|
2020-09-29 11:10:08 -04:00
|
|
|
|
|
|
|
context 'with a project association' do
|
|
|
|
let!(:project) { create(:project) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:created_integration) { project.jira_integration }
|
2020-10-30 14:08:56 -04:00
|
|
|
let(:batch) { Project.where(id: project.id) }
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:association) { 'project' }
|
|
|
|
|
|
|
|
it_behaves_like 'creates integration from batch ids'
|
|
|
|
it_behaves_like 'updates inherit_from_id'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a group association' do
|
2020-10-30 14:08:56 -04:00
|
|
|
let!(:group) { create(:group) }
|
2021-05-12 08:10:24 -04:00
|
|
|
let(:created_integration) { Integration.find_by(group: group) }
|
2020-10-30 14:08:56 -04:00
|
|
|
let(:batch) { Group.where(id: group.id) }
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:association) { 'group' }
|
|
|
|
|
|
|
|
it_behaves_like 'creates integration from batch ids'
|
|
|
|
it_behaves_like 'updates inherit_from_id'
|
2020-10-30 14:08:56 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-23 14:08:31 -04:00
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
context 'passing a group integration' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
|
|
|
|
context 'with a project association' do
|
|
|
|
let!(:project) { create(:project, group: group) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:integration) { create(:jira_integration, group: group, project: nil) }
|
|
|
|
let(:created_integration) { project.jira_integration }
|
2020-10-30 14:08:56 -04:00
|
|
|
let(:batch) { Project.where(id: Project.minimum(:id)..Project.maximum(:id)).without_integration(integration).in_namespace(integration.group.self_and_descendants) }
|
|
|
|
let(:association) { 'project' }
|
|
|
|
let(:inherit_from_id) { integration.id }
|
|
|
|
|
|
|
|
it_behaves_like 'creates integration from batch ids'
|
|
|
|
it_behaves_like 'updates inherit_from_id'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a group association' do
|
|
|
|
let!(:subgroup) { create(:group, parent: group) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:integration) { create(:jira_integration, group: group, project: nil, inherit_from_id: instance_integration.id) }
|
2021-05-12 08:10:24 -04:00
|
|
|
let(:created_integration) { Integration.find_by(group: subgroup) }
|
2020-10-30 14:08:56 -04:00
|
|
|
let(:batch) { Group.where(id: subgroup.id) }
|
|
|
|
let(:association) { 'group' }
|
|
|
|
let(:inherit_from_id) { instance_integration.id }
|
|
|
|
|
|
|
|
it_behaves_like 'creates integration from batch ids'
|
|
|
|
it_behaves_like 'updates inherit_from_id'
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
context 'passing a template integration' do
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:integration) { template_integration }
|
|
|
|
|
|
|
|
context 'with a project association' do
|
|
|
|
let!(:project) { create(:project) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:created_integration) { project.jira_integration }
|
2020-10-30 14:08:56 -04:00
|
|
|
let(:batch) { Project.where(id: project.id) }
|
2020-09-29 11:10:08 -04:00
|
|
|
let(:association) { 'project' }
|
2020-10-23 14:08:31 -04:00
|
|
|
let(:inherit_from_id) { integration.id }
|
2020-09-29 11:10:08 -04:00
|
|
|
|
|
|
|
it_behaves_like 'creates integration from batch ids'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|