2020-05-20 14:08:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::PropagateIntegrationService do
|
|
|
|
describe '.propagate' do
|
2020-08-28 05:10:32 -04:00
|
|
|
include JiraServiceHelper
|
|
|
|
|
|
|
|
before do
|
2021-06-18 11:10:16 -04:00
|
|
|
stub_jira_integration_test
|
2020-08-28 05:10:32 -04:00
|
|
|
end
|
|
|
|
|
2020-10-06 20:08:24 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let_it_be(:instance_integration) { create(:jira_integration, :instance) }
|
|
|
|
let_it_be(:not_inherited_integration) { create(:jira_integration, project: project) }
|
2020-10-06 20:08:24 -04:00
|
|
|
let_it_be(:inherited_integration) do
|
2021-06-18 11:10:16 -04:00
|
|
|
create(:jira_integration, project: create(:project), inherit_from_id: instance_integration.id)
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
2020-11-17 10:09:28 -05:00
|
|
|
|
2020-10-06 20:08:24 -04:00
|
|
|
let_it_be(:different_type_inherited_integration) do
|
2021-06-18 11:10:16 -04:00
|
|
|
create(:redmine_integration, project: project, inherit_from_id: instance_integration.id)
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
context 'with inherited integration' do
|
|
|
|
let(:integration) { inherited_integration }
|
2020-05-20 14:08:00 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationInheritWorker).to receive(:perform_async)
|
|
|
|
.with(instance_integration.id, inherited_integration.id, inherited_integration.id)
|
2020-05-20 14:08:00 -04:00
|
|
|
|
2020-08-27 11:10:21 -04:00
|
|
|
described_class.propagate(instance_integration)
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
context 'with a project without integration' do
|
2020-10-06 20:08:24 -04:00
|
|
|
let(:another_project) { create(:project) }
|
2020-05-20 14:08:00 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
|
|
|
|
.with(instance_integration.id, another_project.id, another_project.id)
|
2020-09-15 11:10:08 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
described_class.propagate(instance_integration)
|
2020-09-15 11:10:08 -04:00
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
context 'with a group without integration' do
|
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationGroupWorker).to receive(:perform_async)
|
|
|
|
.with(instance_integration.id, group.id, group.id)
|
2020-05-20 14:08:00 -04:00
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
described_class.propagate(instance_integration)
|
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
2020-10-06 20:08:24 -04:00
|
|
|
|
|
|
|
context 'for a group-level integration' do
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:group_integration) { create(:jira_integration, group: group, project: nil) }
|
2020-10-06 20:08:24 -04:00
|
|
|
|
|
|
|
context 'with a project without integration' do
|
|
|
|
let(:another_project) { create(:project, group: group) }
|
|
|
|
|
|
|
|
it 'calls to PropagateIntegrationProjectWorker' do
|
|
|
|
expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
|
|
|
|
.with(group_integration.id, another_project.id, another_project.id)
|
|
|
|
|
|
|
|
described_class.propagate(group_integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
context 'with a subgroup without integration' do
|
2020-10-06 20:08:24 -04:00
|
|
|
let(:subgroup) { create(:group, parent: group) }
|
|
|
|
|
|
|
|
it 'calls to PropagateIntegrationGroupWorker' do
|
|
|
|
expect(PropagateIntegrationGroupWorker).to receive(:perform_async)
|
|
|
|
.with(group_integration.id, subgroup.id, subgroup.id)
|
|
|
|
|
|
|
|
described_class.propagate(group_integration)
|
|
|
|
end
|
|
|
|
end
|
2020-10-23 14:08:31 -04:00
|
|
|
|
|
|
|
context 'with a subgroup with integration' do
|
|
|
|
let(:subgroup) { create(:group, parent: group) }
|
2021-06-18 11:10:16 -04:00
|
|
|
let(:subgroup_integration) { create(:jira_integration, group: subgroup, project: nil, inherit_from_id: group_integration.id) }
|
2020-10-23 14:08:31 -04:00
|
|
|
|
|
|
|
it 'calls to PropagateIntegrationInheritDescendantWorker' do
|
|
|
|
expect(PropagateIntegrationInheritDescendantWorker).to receive(:perform_async)
|
|
|
|
.with(group_integration.id, subgroup_integration.id, subgroup_integration.id)
|
|
|
|
|
|
|
|
described_class.propagate(group_integration)
|
|
|
|
end
|
|
|
|
end
|
2020-10-06 20:08:24 -04:00
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|