2020-05-20 18:08:00 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-11-18 09:10:16 +00:00
|
|
|
RSpec.describe Integrations::PropagateService do
|
2020-05-20 18:08:00 +00:00
|
|
|
describe '.propagate' do
|
2022-06-02 21:09:25 +00:00
|
|
|
include JiraIntegrationHelpers
|
2020-08-28 09:10:32 +00:00
|
|
|
|
|
|
|
before do
|
2021-06-18 15:10:16 +00:00
|
|
|
stub_jira_integration_test
|
2020-08-28 09:10:32 +00:00
|
|
|
end
|
|
|
|
|
2020-10-07 00:08:24 +00:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2020-09-29 15:10:08 +00:00
|
|
|
let_it_be(:project) { create(:project) }
|
2021-06-18 15:10:16 +00:00
|
|
|
let_it_be(:instance_integration) { create(:jira_integration, :instance) }
|
|
|
|
let_it_be(:not_inherited_integration) { create(:jira_integration, project: project) }
|
2020-10-07 00:08:24 +00:00
|
|
|
let_it_be(:inherited_integration) do
|
2021-06-18 15:10:16 +00:00
|
|
|
create(:jira_integration, project: create(:project), inherit_from_id: instance_integration.id)
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
2020-11-17 15:09:28 +00:00
|
|
|
|
2020-10-07 00:08:24 +00:00
|
|
|
let_it_be(:different_type_inherited_integration) do
|
2021-06-18 15:10:16 +00:00
|
|
|
create(:redmine_integration, project: project, inherit_from_id: instance_integration.id)
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
|
|
|
|
2020-09-29 15:10:08 +00:00
|
|
|
context 'with inherited integration' do
|
|
|
|
let(:integration) { inherited_integration }
|
2020-05-20 18:08:00 +00:00
|
|
|
|
2020-09-29 15:10:08 +00: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 18:08:00 +00:00
|
|
|
|
2020-08-27 15:10:21 +00:00
|
|
|
described_class.propagate(instance_integration)
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-29 15:10:08 +00:00
|
|
|
context 'with a project without integration' do
|
2020-10-07 00:08:24 +00:00
|
|
|
let(:another_project) { create(:project) }
|
2020-05-20 18:08:00 +00:00
|
|
|
|
2020-09-29 15:10:08 +00: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 15:10:08 +00:00
|
|
|
|
2020-09-29 15:10:08 +00:00
|
|
|
described_class.propagate(instance_integration)
|
2020-09-15 15:10:08 +00:00
|
|
|
end
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
|
|
|
|
2020-09-29 15:10:08 +00: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 18:08:00 +00:00
|
|
|
|
2020-09-29 15:10:08 +00:00
|
|
|
described_class.propagate(instance_integration)
|
|
|
|
end
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
2020-10-07 00:08:24 +00:00
|
|
|
|
|
|
|
context 'for a group-level integration' do
|
2021-11-12 06:10:23 +00:00
|
|
|
let(:group_integration) { create(:jira_integration, :group, group: group) }
|
2020-10-07 00:08:24 +00: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 18:08:31 +00:00
|
|
|
context 'with a subgroup without integration' do
|
2020-10-07 00:08:24 +00: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 18:08:31 +00:00
|
|
|
|
|
|
|
context 'with a subgroup with integration' do
|
|
|
|
let(:subgroup) { create(:group, parent: group) }
|
2021-11-12 06:10:23 +00:00
|
|
|
let(:subgroup_integration) { create(:jira_integration, :group, group: subgroup, inherit_from_id: group_integration.id) }
|
2020-10-23 18:08:31 +00: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-07 00:08:24 +00:00
|
|
|
end
|
2020-05-20 18:08:00 +00:00
|
|
|
end
|
|
|
|
end
|