Browse Source

CLDC-1785-import-organisation-relationship (#1149)

* creates organisation relationship

* refactor
pull/1145/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
419bcbd94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/services/imports/lettings_logs_import_service.rb
  2. 2
      spec/fixtures/imports/logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml
  3. 2
      spec/fixtures/imports/logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml
  4. 9
      spec/services/imports/lettings_logs_import_service_spec.rb

9
app/services/imports/lettings_logs_import_service.rb

@ -246,6 +246,7 @@ module Imports
apply_date_consistency!(attributes)
apply_household_consistency!(attributes)
create_organisation_relationship!(attributes)
lettings_log = save_lettings_log(attributes, previous_status)
compute_differences(lettings_log, attributes)
@ -681,5 +682,13 @@ module Imports
0
end
end
def create_organisation_relationship!(attributes)
parent_organisation_id = attributes["owning_organisation_id"]
child_organisation_id = attributes["managing_organisation_id"]
return if parent_organisation_id == child_organisation_id
OrganisationRelationship.find_or_create_by!(parent_organisation_id:, child_organisation_id:)
end
end
end

2
spec/fixtures/imports/logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml vendored

@ -413,7 +413,7 @@
<HCNUM>655</HCNUM>
<MANHCNUM>655</MANHCNUM>
<LAHA/>
<MANINGORGID>1</MANINGORGID>
<MANINGORGID>2</MANINGORGID>
<HBTYPE1/>
<HBTYPE2/>
<HBTYPE3>3</HBTYPE3>

2
spec/fixtures/imports/logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml vendored

@ -413,7 +413,7 @@
<HCNUM>N/A</HCNUM>
<MANHCNUM>N/A</MANHCNUM>
<LAHA/>
<MANINGORGID>1</MANINGORGID>
<MANINGORGID>2</MANINGORGID>
<Q28same1>false</Q28same1>
<HBTYPE1/>
<HBTYPE2/>

9
spec/services/imports/lettings_logs_import_service_spec.rb

@ -11,6 +11,7 @@ RSpec.describe Imports::LettingsLogsImportService do
let(:fixture_directory) { "spec/fixtures/imports/logs" }
let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") }
let(:managing_organisation) { FactoryBot.create(:organisation, old_visible_id: "2", provider_type: "PRP") }
let(:scheme1) { FactoryBot.create(:scheme, old_visible_id: "0123", owning_organisation: organisation) }
let(:scheme2) { FactoryBot.create(:scheme, old_visible_id: "456", owning_organisation: organisation) }
@ -24,6 +25,7 @@ RSpec.describe Imports::LettingsLogsImportService do
allow(Organisation).to receive(:find_by).and_return(nil)
allow(Organisation).to receive(:find_by).with(old_visible_id: organisation.old_visible_id).and_return(organisation)
allow(Organisation).to receive(:find_by).with(old_visible_id: managing_organisation.old_visible_id).and_return(managing_organisation)
# Created by users
FactoryBot.create(:user, old_user_id: "c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa", organisation:)
@ -80,6 +82,13 @@ RSpec.describe Imports::LettingsLogsImportService do
.to change(LettingsLog, :count).by(4)
end
it "creates organisation relationship once" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect { lettings_log_service.create_logs(remote_folder) }
.to change(OrganisationRelationship, :count).by(1)
end
context "when there are status discrepancies" do
let(:lettings_log_id5) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" }
let(:lettings_log_id6) { "5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd" }

Loading…
Cancel
Save