From 84e539be0bf7311d8b9b3877f001df8a9e2a727e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 5 Dec 2023 15:11:22 +0000 Subject: [PATCH] feat: update tests --- spec/models/scheme_spec.rb | 1 - .../merge/merge_organisations_service_spec.rb | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index ba1127908..41ca7a6a8 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -299,7 +299,6 @@ RSpec.describe Scheme, type: :model do end it "returns activating soon if the scheme has a future startdate" do - Timecop.freeze(2022, 6, 4) scheme.startdate = Time.zone.local(2022, 7, 7) scheme.save! expect(scheme.status).to eq(:activating_soon) diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb index 1c82318e5..5f2cf5e83 100644 --- a/spec/services/merge/merge_organisations_service_spec.rb +++ b/spec/services/merge/merge_organisations_service_spec.rb @@ -305,9 +305,6 @@ RSpec.describe Merge::MergeOrganisationsService do context "and merging organisation schemes and locations" do let!(:scheme) { create(:scheme, owning_organisation: merging_organisation) } let!(:location) { create(:location, scheme:) } - let!(:location_without_startdate) { create(:location, scheme:, startdate: nil) } - let!(:location_with_past_startdate) { create(:location, scheme:, startdate: Time.zone.today - 2.months) } - let!(:location_with_future_startdate) { create(:location, scheme:, startdate: Time.zone.today + 2.months) } let!(:deactivated_location) { create(:location, scheme:) } let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) } let!(:owned_lettings_log) { create(:lettings_log, :sh, scheme:, location:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) } @@ -321,25 +318,31 @@ RSpec.describe Merge::MergeOrganisationsService do create(:lettings_log, startdate: Time.zone.tomorrow, managing_organisation: merging_organisation) end - it "combines organisation schemes and locations" do - expect(Rails.logger).to receive(:info).with("Merged users from fake org:") - expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})") - 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(/\t#{scheme.service_name} \(S/) - merge_organisations_service.call - - absorbing_organisation.reload - expect(absorbing_organisation.owned_schemes.count).to eq(1) - expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) - expect(absorbing_organisation.owned_schemes.first.startdate).to eq(Time.zone.yesterday) - expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(4) - expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate).to eq(Time.zone.today + 2.months) - expect(scheme.scheme_deactivation_periods.count).to eq(1) - expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) + context "with multiple locations" do + let!(:location_without_startdate) { create(:location, scheme:, startdate: nil) } + let!(:location_with_past_startdate) { create(:location, scheme:, startdate: Time.zone.today - 2.months) } + let!(:location_with_future_startdate) { create(:location, scheme:, startdate: Time.zone.today + 2.months) } + + it "combines organisation schemes and locations" do + expect(Rails.logger).to receive(:info).with("Merged users from fake org:") + expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})") + 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(/\t#{scheme.service_name} \(S/) + merge_organisations_service.call + + absorbing_organisation.reload + expect(absorbing_organisation.owned_schemes.count).to eq(1) + expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) + expect(absorbing_organisation.owned_schemes.first.startdate).to eq(Time.zone.yesterday) + expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(4) + expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) + expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) + expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) + expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate).to eq(Time.zone.today + 2.months) + expect(scheme.scheme_deactivation_periods.count).to eq(1) + expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) + end end it "moves relevant logs and assigns the new scheme" do