2020-09-29 11:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkUpdateIntegrationService do
|
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
before_all do
|
2020-09-29 11:10:08 -04:00
|
|
|
stub_jira_service_test
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:excluded_attributes) { %w[id project_id group_id inherit_from_id instance template created_at updated_at] }
|
2020-10-28 17:08:42 -04:00
|
|
|
let(:batch) do
|
|
|
|
Service.inherited_descendants_from_self_or_ancestors_from(subgroup_integration).where(id: group_integration.id..integration.id)
|
|
|
|
end
|
2020-10-23 14:08:31 -04:00
|
|
|
|
|
|
|
let_it_be(:group) { create(:group) }
|
2020-10-28 17:08:42 -04:00
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
2020-10-23 14:08:31 -04:00
|
|
|
let_it_be(:group_integration) do
|
|
|
|
JiraService.create!(
|
|
|
|
group: group,
|
2020-10-28 17:08:42 -04:00
|
|
|
url: 'http://group.jira.com'
|
2020-10-23 14:08:31 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:subgroup_integration) do
|
2020-09-29 11:10:08 -04:00
|
|
|
JiraService.create!(
|
2020-10-23 14:08:31 -04:00
|
|
|
inherit_from_id: group_integration.id,
|
2020-10-28 17:08:42 -04:00
|
|
|
group: subgroup,
|
|
|
|
url: 'http://subgroup.jira.com',
|
|
|
|
push_events: true
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:excluded_integration) do
|
|
|
|
JiraService.create!(
|
|
|
|
group: create(:group),
|
|
|
|
url: 'http://another.jira.com',
|
|
|
|
push_events: false
|
2020-09-29 11:10:08 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
let_it_be(:integration) do
|
2020-09-29 11:10:08 -04:00
|
|
|
JiraService.create!(
|
2020-10-28 17:08:42 -04:00
|
|
|
project: create(:project, group: subgroup),
|
|
|
|
inherit_from_id: subgroup_integration.id,
|
|
|
|
url: 'http://project.jira.com',
|
|
|
|
push_events: false
|
2020-09-29 11:10:08 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with inherited integration' do
|
2020-10-28 17:08:42 -04:00
|
|
|
it 'updates the integration', :aggregate_failures do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
expect(integration.reload.inherit_from_id).to eq(group_integration.id)
|
2020-10-28 17:08:42 -04:00
|
|
|
expect(integration.reload.attributes.except(*excluded_attributes))
|
2020-10-23 14:08:31 -04:00
|
|
|
.to eq(subgroup_integration.attributes.except(*excluded_attributes))
|
2020-10-28 17:08:42 -04:00
|
|
|
|
|
|
|
expect(excluded_integration.reload.inherit_from_id).not_to eq(group_integration.id)
|
|
|
|
expect(excluded_integration.reload.attributes.except(*excluded_attributes))
|
|
|
|
.not_to eq(subgroup_integration.attributes.except(*excluded_attributes))
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with integration with data fields' do
|
|
|
|
let(:excluded_attributes) { %w[id service_id created_at updated_at] }
|
|
|
|
|
2020-10-28 17:08:42 -04:00
|
|
|
it 'updates the data fields from the integration', :aggregate_failures do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2020-10-28 17:08:42 -04:00
|
|
|
expect(integration.data_fields.attributes.except(*excluded_attributes))
|
2020-10-23 14:08:31 -04:00
|
|
|
.to eq(subgroup_integration.data_fields.attributes.except(*excluded_attributes))
|
2020-10-28 17:08:42 -04:00
|
|
|
|
|
|
|
expect(integration.data_fields.attributes.except(*excluded_attributes))
|
|
|
|
.not_to eq(excluded_integration.data_fields.attributes.except(*excluded_attributes))
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|