|
|
|
@ -154,21 +154,47 @@ RSpec.describe Merge::MergeOrganisationsService do |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
|
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{deactivated_scheme.service_name} \(S/) |
|
|
|
merge_organisations_service.call |
|
|
|
merge_organisations_service.call |
|
|
|
|
|
|
|
|
|
|
|
absorbing_organisation.reload |
|
|
|
absorbing_organisation.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
|
|
|
deactivated_scheme.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) |
|
|
|
deactivated_location.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.first.old_id).to be_nil |
|
|
|
expect(absorbing_organisation.owned_schemes.count).to eq(2) |
|
|
|
expect(absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1) |
|
|
|
# moves active schemes and locations to absorbing organisation |
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) |
|
|
|
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) |
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil |
|
|
|
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) |
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil |
|
|
|
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.locations.count).to eq(2) |
|
|
|
|
|
|
|
expect(absorbed_active_location.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_visible_id).to be_nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# deactivates active schemes and locations on merging organisation |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# does not deactivate inactive locations on merging organisation again |
|
|
|
|
|
|
|
expect(scheme.locations.find_by(postcode: deactivated_location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive schemes and their locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_scheme = absorbing_organisation.owned_schemes.find_by(service_name: deactivated_scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivated_scheme.scheme_deactivation_periods.first.deactivation_date) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.first.location_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(deactivated_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive locations of active schemes to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_location = absorbed_active_scheme.locations.find_by(postcode: deactivated_location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.scheme_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.first.deactivation_date).to eq(deactivated_location.location_deactivation_periods.first.deactivation_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
@ -327,17 +353,47 @@ RSpec.describe Merge::MergeOrganisationsService do |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
|
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{deactivated_scheme.service_name} \(S/) |
|
|
|
merge_organisations_service.call |
|
|
|
merge_organisations_service.call |
|
|
|
|
|
|
|
|
|
|
|
absorbing_organisation.reload |
|
|
|
absorbing_organisation.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
|
|
|
deactivated_scheme.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) |
|
|
|
deactivated_location.reload |
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1) |
|
|
|
expect(absorbing_organisation.owned_schemes.count).to eq(2) |
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
|
|
|
|
# moves active schemes and locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) |
|
|
|
|
|
|
|
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.locations.count).to eq(2) |
|
|
|
|
|
|
|
expect(absorbed_active_location.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_visible_id).to be_nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# deactivates active schemes and locations on merging organisation |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# does not deactivate inactive locations on merging organisation again |
|
|
|
|
|
|
|
expect(scheme.locations.find_by(postcode: deactivated_location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive schemes and their locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_scheme = absorbing_organisation.owned_schemes.find_by(service_name: deactivated_scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivated_scheme.scheme_deactivation_periods.first.deactivation_date) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.first.location_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(deactivated_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive locations of active schemes to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_location = absorbed_active_scheme.locations.find_by(postcode: deactivated_location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.scheme_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.first.deactivation_date).to eq(deactivated_location.location_deactivation_periods.first.deactivation_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
@ -669,21 +725,47 @@ RSpec.describe Merge::MergeOrganisationsService do |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
|
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{deactivated_scheme.service_name} \(S/) |
|
|
|
merge_organisations_service.call |
|
|
|
merge_organisations_service.call |
|
|
|
|
|
|
|
|
|
|
|
new_absorbing_organisation.reload |
|
|
|
new_absorbing_organisation.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.count).to eq(1) |
|
|
|
deactivated_scheme.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) |
|
|
|
deactivated_location.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.old_id).to be_nil |
|
|
|
expect(new_absorbing_organisation.owned_schemes.count).to eq(2) |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1) |
|
|
|
# moves active schemes and locations to absorbing organisation |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) |
|
|
|
absorbed_active_scheme = new_absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil |
|
|
|
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil |
|
|
|
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.locations.count).to eq(2) |
|
|
|
|
|
|
|
expect(absorbed_active_location.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_visible_id).to be_nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# deactivates active schemes and locations on merging organisation |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# does not deactivate inactive locations on merging organisation again |
|
|
|
|
|
|
|
expect(scheme.locations.find_by(postcode: deactivated_location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive schemes and their locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_scheme = new_absorbing_organisation.owned_schemes.find_by(service_name: deactivated_scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivated_scheme.scheme_deactivation_periods.first.deactivation_date) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.first.location_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(deactivated_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive locations of active schemes to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_location = absorbed_active_scheme.locations.find_by(postcode: deactivated_location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.scheme_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.first.deactivation_date).to eq(deactivated_location.location_deactivation_periods.first.deactivation_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
@ -842,17 +924,47 @@ RSpec.describe Merge::MergeOrganisationsService do |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) |
|
|
|
|
|
|
|
expect(Rails.logger).to receive(:info).with(/\t#{deactivated_scheme.service_name} \(S/) |
|
|
|
merge_organisations_service.call |
|
|
|
merge_organisations_service.call |
|
|
|
|
|
|
|
|
|
|
|
new_absorbing_organisation.reload |
|
|
|
new_absorbing_organisation.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.count).to eq(1) |
|
|
|
deactivated_scheme.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) |
|
|
|
deactivated_location.reload |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1) |
|
|
|
expect(new_absorbing_organisation.owned_schemes.count).to eq(2) |
|
|
|
expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
|
|
|
|
# moves active schemes and locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_active_scheme = new_absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) |
|
|
|
|
|
|
|
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.old_visible_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.locations.count).to eq(2) |
|
|
|
|
|
|
|
expect(absorbed_active_location.postcode).to eq(location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_id).to be_nil |
|
|
|
|
|
|
|
expect(absorbed_active_location.old_visible_id).to be_nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# deactivates active schemes and locations on merging organisation |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
expect(scheme.locations.find_by(postcode: location.postcode).location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# does not deactivate inactive locations on merging organisation again |
|
|
|
|
|
|
|
expect(scheme.locations.find_by(postcode: deactivated_location.postcode).location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive schemes and their locations to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_scheme = new_absorbing_organisation.owned_schemes.find_by(service_name: deactivated_scheme.service_name) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.scheme_deactivation_periods.first.deactivation_date).to eq(deactivated_scheme.scheme_deactivation_periods.first.deactivation_date) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_scheme.locations.first.location_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(deactivated_scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# moves inactive locations of active schemes to absorbing organisation |
|
|
|
|
|
|
|
absorbed_inactive_location = absorbed_active_scheme.locations.find_by(postcode: deactivated_location.postcode) |
|
|
|
|
|
|
|
expect(absorbed_active_scheme.scheme_deactivation_periods.count).to eq(0) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.count).to eq(1) |
|
|
|
|
|
|
|
expect(absorbed_inactive_location.location_deactivation_periods.first.deactivation_date).to eq(deactivated_location.location_deactivation_periods.first.deactivation_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
it "moves relevant logs and assigns the new scheme" do |
|
|
|
|