Browse Source

update import services for lettings and sales to import creation method

write tests to cover this
pull/1744/head
Arthur Campbell 3 years ago
parent
commit
7a16fc34ca
  1. 1
      app/services/imports/lettings_logs_import_service.rb
  2. 10
      app/services/imports/logs_import_service.rb
  3. 1
      app/services/imports/sales_logs_import_service.rb
  4. 2
      spec/fixtures/imports/sales_logs/shared_ownership_sales_log2.xml
  5. 22
      spec/services/imports/lettings_logs_import_service_spec.rb
  6. 24
      spec/services/imports/sales_logs_import_service_spec.rb

1
app/services/imports/lettings_logs_import_service.rb

@ -66,6 +66,7 @@ module Imports
attributes["startdate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR") attributes["startdate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR")
attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID")
attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID") attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID")
attributes["creation_method"] = get_creation_method(xml_doc)
attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint")
attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a")
attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b")

10
app/services/imports/logs_import_service.rb

@ -25,6 +25,16 @@ module Imports
end end
end end
CREATION_METHODS = {
"Bulk Upload" => "bulk upload",
"Manual Entry" => "single log",
}.freeze
def get_creation_method(xml_doc)
upload_method = meta_field_value(xml_doc, "upload-method")
CREATION_METHODS[upload_method]
end
def find_organisation_id(xml_doc, id_field) def find_organisation_id(xml_doc, id_field)
old_visible_id = string_or_nil(xml_doc, id_field) old_visible_id = string_or_nil(xml_doc, id_field)
organisation = Organisation.find_by(old_visible_id:) organisation = Organisation.find_by(old_visible_id:)

1
app/services/imports/sales_logs_import_service.rb

@ -31,6 +31,7 @@ module Imports
attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID")
attributes["type"] = unsafe_string_as_integer(xml_doc, "DerSaleType") attributes["type"] = unsafe_string_as_integer(xml_doc, "DerSaleType")
attributes["old_id"] = meta_field_value(xml_doc, "document-id") attributes["old_id"] = meta_field_value(xml_doc, "document-id")
attributes["creation_method"] = get_creation_method(xml_doc)
attributes["created_at"] = Time.zone.parse(meta_field_value(xml_doc, "created-date")) attributes["created_at"] = Time.zone.parse(meta_field_value(xml_doc, "created-date"))
attributes["updated_at"] = Time.zone.parse(meta_field_value(xml_doc, "modified-date")) attributes["updated_at"] = Time.zone.parse(meta_field_value(xml_doc, "modified-date"))
attributes["purchid"] = string_or_nil(xml_doc, "PurchaserCode") attributes["purchid"] = string_or_nil(xml_doc, "PurchaserCode")

2
spec/fixtures/imports/sales_logs/shared_ownership_sales_log2.xml vendored

@ -9,7 +9,7 @@
<meta:modified-date>2023-02-22T11:00:06.575832Z</meta:modified-date> <meta:modified-date>2023-02-22T11:00:06.575832Z</meta:modified-date>
<meta:status>submitted-valid</meta:status> <meta:status>submitted-valid</meta:status>
<meta:reporting-year>2022</meta:reporting-year> <meta:reporting-year>2022</meta:reporting-year>
<meta:upload-method>Manual Entry</meta:upload-method> <meta:upload-method>Bulk Upload</meta:upload-method>
<meta:schema assert-valid="true"/> <meta:schema assert-valid="true"/>
<meta:rules assert-valid="true"/> <meta:rules assert-valid="true"/>
</meta:metadata> </meta:metadata>

22
spec/services/imports/lettings_logs_import_service_spec.rb

@ -478,6 +478,28 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "when the log being imported was manually entered" do
it "sets the creation method correctly" do
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log.creation_method).to eq "single log"
end
end
context "when the log being imported was bulk uploaded" do
before do
lettings_log_xml.at_xpath("//meta:upload-method", { "meta" => "http://data.gov.uk/core/metadata" }).content = "Bulk Upload"
end
it "sets the creation method correctly" do
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log.creation_method).to eq "bulk upload"
end
end
context "and income over the max" do context "and income over the max" do
before do before do
lettings_log_xml.at_xpath("//xmlns:Q8Money").content = "25000" lettings_log_xml.at_xpath("//xmlns:Q8Money").content = "25000"

24
spec/services/imports/sales_logs_import_service_spec.rb

@ -263,8 +263,6 @@ RSpec.describe Imports::SalesLogsImportService do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
example.run example.run
end end
Timecop.return
Singleton.__init__(FormHandler)
end end
before do before do
@ -1056,6 +1054,28 @@ RSpec.describe Imports::SalesLogsImportService do
end end
end end
context "when the log being imported was manually entered" do
let(:sales_log_id) { "shared_ownership_sales_log" }
it "sets the creation method correctly" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.creation_method).to eq "single log"
end
end
context "when the log being imported was bulk uploaded" do
let(:sales_log_id) { "shared_ownership_sales_log2" }
it "sets the creation method correctly" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.creation_method).to eq "bulk upload"
end
end
context "when inferring age known" do context "when inferring age known" do
let(:sales_log_id) { "discounted_ownership_sales_log" } let(:sales_log_id) { "discounted_ownership_sales_log" }

Loading…
Cancel
Save