|
|
|
|
@ -3,24 +3,12 @@ require "rails_helper"
|
|
|
|
|
RSpec.describe Merge::MergeOrganisationsService do |
|
|
|
|
subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids]) } |
|
|
|
|
|
|
|
|
|
let(:absorbing_organisation) do |
|
|
|
|
create(:organisation, |
|
|
|
|
holds_own_stock: false, |
|
|
|
|
choice_based_lettings: false, |
|
|
|
|
common_housing_register: true, |
|
|
|
|
choice_allocation_policy: true) |
|
|
|
|
end |
|
|
|
|
let(:absorbing_organisation) { create(:organisation, holds_own_stock: false) } |
|
|
|
|
let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) } |
|
|
|
|
|
|
|
|
|
describe "#call" do |
|
|
|
|
context "when merging a single organisation into an existing organisation" do |
|
|
|
|
let(:merging_organisation) do |
|
|
|
|
create(:organisation, |
|
|
|
|
holds_own_stock: true, |
|
|
|
|
choice_based_lettings: false, |
|
|
|
|
common_housing_register: false, |
|
|
|
|
choice_allocation_policy: true) |
|
|
|
|
end |
|
|
|
|
let(:merging_organisation) { create(:organisation, holds_own_stock: true) } |
|
|
|
|
|
|
|
|
|
let(:merging_organisation_ids) { [merging_organisation.id] } |
|
|
|
|
let!(:merging_organisation_user) { create(:user, organisation: merging_organisation) } |
|
|
|
|
@ -43,15 +31,6 @@ RSpec.describe Merge::MergeOrganisationsService do
|
|
|
|
|
|
|
|
|
|
absorbing_organisation.reload |
|
|
|
|
expect(absorbing_organisation.holds_own_stock).to eq(true) |
|
|
|
|
expect(absorbing_organisation.choice_based_lettings).to eq(false) |
|
|
|
|
expect(absorbing_organisation.common_housing_register).to eq(true) |
|
|
|
|
expect(absorbing_organisation.choice_allocation_policy).to eq(true) |
|
|
|
|
# expect(absorbing_organisation.cbl_proportion_percentage).to eq(0) |
|
|
|
|
# expect(absorbing_organisation.enter_affordable_logs).to eq(true) |
|
|
|
|
# expect(absorbing_organisation.owns_affordable_logs).to eq(true) |
|
|
|
|
# expect(absorbing_organisation.general_needs_units).to eq(2) |
|
|
|
|
# expect(absorbing_organisation.supported_housing_units).to eq(2) |
|
|
|
|
# expect(absorbing_organisation.unspecified_units).to eq(2) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and merging organisation rent periods" do |
|
|
|
|
@ -95,6 +74,31 @@ RSpec.describe Merge::MergeOrganisationsService do
|
|
|
|
|
expect(absorbing_organisation.child_organisations.count).to eq(3) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and merging organisation schemes and locations" do |
|
|
|
|
let!(:scheme) { create(:scheme, owning_organisation: merging_organisation) } |
|
|
|
|
let!(:location) { create(:location, scheme:) } |
|
|
|
|
let!(:deactivated_location) { create(:location, scheme:) } |
|
|
|
|
let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) } |
|
|
|
|
let!(:deactivated_scheme_location) { create(:location, scheme: deactivated_scheme) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month) |
|
|
|
|
create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "combines organisation relationships" do |
|
|
|
|
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.locations.count).to eq(1) |
|
|
|
|
expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) |
|
|
|
|
expect(scheme.scheme_deactivation_periods.count).to eq(1) |
|
|
|
|
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|