2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe BulkUpdateIntegrationService, feature_category: :integrations do
|
2022-07-23 23:45:48 +05:30
|
|
|
include JiraIntegrationHelpers
|
2021-01-03 14:25:43 +05:30
|
|
|
|
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
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:excluded_attributes) do
|
|
|
|
%w[
|
2022-11-25 23:54:43 +05:30
|
|
|
id project_id group_id inherit_from_id instance template
|
|
|
|
created_at updated_at encrypted_properties encrypted_properties_iv
|
2022-06-21 17:19:12 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
let(:batch) do
|
2021-06-08 01:23:25 +05:30
|
|
|
Integration.inherited_descendants_from_self_or_ancestors_from(subgroup_integration).where(id: group_integration.id..integration.id)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
2021-12-11 22:18:48 +05:30
|
|
|
let_it_be(:group_integration) { create(:jira_integration, :group, group: group, url: 'http://group.jira.com') }
|
|
|
|
let_it_be(:excluded_integration) { create(:jira_integration, :group, group: create(:group), url: 'http://another.jira.com', push_events: false) }
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:subgroup_integration) do
|
2021-12-11 22:18:48 +05:30
|
|
|
create(:jira_integration, :group,
|
2021-01-29 00:20:46 +05:30
|
|
|
group: subgroup,
|
2021-12-11 22:18:48 +05:30
|
|
|
inherit_from_id: group_integration.id,
|
2021-01-29 00:20:46 +05:30
|
|
|
url: 'http://subgroup.jira.com',
|
|
|
|
push_events: true
|
2021-01-03 14:25:43 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:integration) do
|
2021-12-11 22:18:48 +05:30
|
|
|
create(:jira_integration,
|
2021-01-29 00:20:46 +05:30
|
|
|
project: create(:project, group: subgroup),
|
|
|
|
inherit_from_id: subgroup_integration.id,
|
|
|
|
url: 'http://project.jira.com',
|
|
|
|
push_events: false
|
2021-01-03 14:25:43 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with inherited integration' do
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'updates the integration', :aggregate_failures do
|
2021-10-27 15:23:28 +05:30
|
|
|
described_class.new(subgroup_integration.reload, batch).execute
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(integration.reload.inherit_from_id).to eq(group_integration.id)
|
|
|
|
expect(integration.reload.attributes.except(*excluded_attributes))
|
2021-10-27 15:23:28 +05:30
|
|
|
.to eq(subgroup_integration.reload.attributes.except(*excluded_attributes))
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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))
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'does not change the created_at timestamp' do
|
2023-06-20 00:43:36 +05:30
|
|
|
subgroup_integration.update_column(:created_at, Time.utc(2022, 1, 1))
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
|
|
|
end.not_to change { integration.reload.created_at }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'sets the updated_at timestamp to the current time', time_travel_to: Time.utc(2022, 1, 1) do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
|
|
|
end.to change { integration.reload.updated_at }.to(Time.current)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'with integration with data fields' do
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:excluded_attributes) do
|
2022-08-27 11:52:29 +05:30
|
|
|
%w[id integration_id created_at updated_at encrypted_properties encrypted_properties_iv]
|
2022-06-21 17:19:12 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'updates the data fields from the integration', :aggregate_failures do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(integration.reload.data_fields.attributes.except(*excluded_attributes))
|
|
|
|
.to eq(subgroup_integration.reload.data_fields.attributes.except(*excluded_attributes))
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(integration.data_fields.attributes.except(*excluded_attributes))
|
|
|
|
.not_to eq(excluded_integration.data_fields.attributes.except(*excluded_attributes))
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
it 'does not change the created_at timestamp' do
|
2023-06-20 00:43:36 +05:30
|
|
|
subgroup_integration.data_fields.update_column(:created_at, Time.utc(2022, 1, 2))
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
|
|
|
end.not_to change { integration.data_fields.reload.created_at }
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it 'sets the updated_at timestamp to the current time', time_travel_to: Time.utc(2022, 1, 1) do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect do
|
|
|
|
described_class.new(subgroup_integration, batch).execute
|
|
|
|
end.to change { integration.data_fields.reload.updated_at }.to(Time.current)
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
it 'works with batch as an ActiveRecord::Relation' do
|
|
|
|
expect do
|
|
|
|
described_class.new(group_integration, Integration.where(id: integration.id)).execute
|
|
|
|
end.to change { integration.reload.url }.to(group_integration.url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with batch as an array of ActiveRecord objects' do
|
|
|
|
expect do
|
|
|
|
described_class.new(group_integration, [integration]).execute
|
|
|
|
end.to change { integration.reload.url }.to(group_integration.url)
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
context 'with different foreign key of data_fields' do
|
|
|
|
let(:integration) { create(:zentao_integration, project: create(:project, group: group)) }
|
|
|
|
let(:group_integration) do
|
|
|
|
create(:zentao_integration, :group,
|
|
|
|
group: group,
|
|
|
|
url: 'https://group.zentao.net',
|
|
|
|
api_token: 'GROUP_TOKEN',
|
|
|
|
zentao_product_xid: '1'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with batch as an array of ActiveRecord objects' do
|
|
|
|
expect do
|
|
|
|
described_class.new(group_integration, [integration]).execute
|
|
|
|
end.to change { integration.reload.url }.to(group_integration.url)
|
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|