debian-mirror-gitlab/spec/services/bulk_create_integration_service_spec.rb

115 lines
4.3 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkCreateIntegrationService do
include JiraServiceHelper
2021-01-29 00:20:46 +05:30
before_all do
2021-09-30 23:02:18 +05:30
stub_jira_integration_test
2021-01-03 14:25:43 +05:30
end
2021-01-29 00:20:46 +05:30
let_it_be(:excluded_group) { create(:group) }
let_it_be(:excluded_project) { create(:project, group: excluded_group) }
2021-09-30 23:02:18 +05:30
let(:instance_integration) { create(:jira_integration, :instance) }
let(:template_integration) { create(:jira_integration, :template) }
2021-01-03 14:25:43 +05:30
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))
2021-10-27 15:23:28 +05:30
.to eq(integration.reload.attributes.except(*excluded_attributes))
2021-01-03 14:25:43 +05:30
end
context 'integration with data fields' do
2021-12-11 22:18:48 +05:30
let(:excluded_attributes) { %w[id service_id integration_id created_at updated_at] }
2021-01-03 14:25:43 +05:30
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-04-29 21:17:54 +05:30
.to eq(integration.reload.data_fields.attributes.except(*excluded_attributes))
2021-01-03 14:25:43 +05:30
end
end
end
shared_examples 'updates inherit_from_id' do
it 'updates inherit_from_id attributes' do
described_class.new(integration, batch, association).execute
2021-01-29 00:20:46 +05:30
expect(created_integration.reload.inherit_from_id).to eq(inherit_from_id)
2021-01-03 14:25:43 +05:30
end
end
2021-01-29 00:20:46 +05:30
context 'passing an instance-level integration' do
2021-01-03 14:25:43 +05:30
let(:integration) { instance_integration }
2021-01-29 00:20:46 +05:30
let(:inherit_from_id) { integration.id }
2021-01-03 14:25:43 +05:30
context 'with a project association' do
let!(:project) { create(:project) }
2021-09-30 23:02:18 +05:30
let(:created_integration) { project.jira_integration }
2021-01-29 00:20:46 +05:30
let(:batch) { Project.where(id: project.id) }
2021-01-03 14:25:43 +05:30
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
let!(:group) { create(:group) }
2021-06-08 01:23:25 +05:30
let(:created_integration) { Integration.find_by(group: group) }
2021-01-29 00:20:46 +05:30
let(:batch) { Group.where(id: group.id) }
let(:association) { 'group' }
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id'
end
end
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-12-11 22:18:48 +05:30
let(:integration) { create(:jira_integration, :group, group: group) }
2021-09-30 23:02:18 +05:30
let(:created_integration) { project.jira_integration }
2021-01-29 00:20:46 +05:30
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'
2021-12-11 22:18:48 +05:30
context 'with different foreign key of data_fields' do
let(:integration) { create(:zentao_integration, :group, group: group) }
let(:created_integration) { project.zentao_integration }
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id'
end
2021-01-29 00:20:46 +05:30
end
context 'with a group association' do
let!(:subgroup) { create(:group, parent: group) }
2021-12-11 22:18:48 +05:30
let(:integration) { create(:jira_integration, :group, group: group, inherit_from_id: instance_integration.id) }
2021-06-08 01:23:25 +05:30
let(:created_integration) { Integration.find_by(group: subgroup) }
2021-01-29 00:20:46 +05:30
let(:batch) { Group.where(id: subgroup.id) }
2021-01-03 14:25:43 +05:30
let(:association) { 'group' }
2021-01-29 00:20:46 +05:30
let(:inherit_from_id) { instance_integration.id }
2021-01-03 14:25:43 +05:30
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id'
2021-12-11 22:18:48 +05:30
context 'with different foreign key of data_fields' do
let(:integration) { create(:zentao_integration, :group, group: group, inherit_from_id: instance_integration.id) }
it_behaves_like 'creates integration from batch ids'
it_behaves_like 'updates inherit_from_id'
end
2021-01-03 14:25:43 +05:30
end
end
end