Browse Source

Adjust xml export to export refused details, update refused to take into account details_unknown

pull/1938/head
Kat 3 years ago
parent
commit
d6596ebc46
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 4
      app/models/lettings_log.rb
  3. 11
      app/services/exports/lettings_log_export_service.rb
  4. 47
      spec/models/lettings_log_spec.rb
  5. 26
      spec/services/exports/lettings_log_export_service_spec.rb

2
app/models/derived_variables/lettings_log_variables.rb

@ -186,7 +186,7 @@ private
end
def get_refused
return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused?
return 1 if details_unknown? || age_refused? || sex_refused? || relat_refused? || ecstat_refused?
0
end

4
app/models/lettings_log.rb

@ -703,6 +703,10 @@ private
[ecstat1, ecstat2, ecstat3, ecstat4, ecstat5, ecstat6, ecstat7, ecstat8].any?(10)
end
def details_unknown?
[details_known_2, details_known_3, details_known_4, details_known_5, details_known_6, details_known_7, details_known_8].any?(1)
end
def soft_value_for_period(value)
num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period]
return "" unless value && num_of_weeks

11
app/services/exports/lettings_log_export_service.rb

@ -210,6 +210,17 @@ module Exports
add_location_fields!(lettings_log.location, attribute_hash) if lettings_log.location
attribute_hash.delete("unittype_gn")
end
# details unknown fields
(2..8).each do |index|
next unless lettings_log["details_known_#{index}"] == 1
attribute_hash["age#{index}"] = -9
attribute_hash["sex#{index}"] = "R"
attribute_hash["relat#{index}"] = "R"
attribute_hash["ecstat#{index}"] = 10
end
attribute_hash
end

47
spec/models/lettings_log_spec.rb

@ -1810,22 +1810,41 @@ RSpec.describe LettingsLog do
end
context "when answering the household characteristics questions" do
let!(:lettings_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
age1_known: 1,
sex1: "R",
relat2: "R",
ecstat1: 10,
})
context "and some person details are refused" do
let!(:lettings_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
age1_known: 1,
sex1: "R",
relat2: "R",
ecstat1: 10,
})
end
it "correctly derives and saves refused" do
record_from_db = described_class.find(lettings_log.id)
expect(record_from_db["refused"]).to eq(1)
expect(lettings_log["refused"]).to eq(1)
end
end
it "correctly derives and saves refused" do
record_from_db = described_class.find(lettings_log.id)
expect(record_from_db["refused"]).to eq(1)
expect(lettings_log["refused"]).to eq(1)
context "and some person details are not known" do
let!(:lettings_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
details_known_2: 1,
})
end
it "correctly derives and saves refused" do
record_from_db = described_class.find(lettings_log.id)
expect(record_from_db["refused"]).to eq(1)
expect(lettings_log["refused"]).to eq(1)
end
end
end

26
spec/services/exports/lettings_log_export_service_spec.rb

@ -150,6 +150,32 @@ RSpec.describe Exports::LettingsLogExportService do
end
end
context "and one lettings log with unknown user details is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, created_by: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
def replace_person_details(export_file)
export_file.sub!("<age2>32</age2>", "<age2>-9</age2>")
export_file.sub!("<ecstat2>6</ecstat2>", "<ecstat2>10</ecstat2>")
export_file.sub!("<sex2>M</sex2>", "<sex2>R</sex2>")
export_file.sub!("<relat2>P</relat2>", "<relat2>R</relat2>")
export_file.sub!("<refused>0</refused>", "<refused>1</refused>")
export_file.sub!("<hhtype>4</hhtype>", "<hhtype>3</hhtype>")
export_file.sub!("<totadult>2</totadult>", "<totadult>1</totadult>")
end
it "generates an XML export file with the expected content within the ZIP file" do
expected_content = replace_entity_ids(lettings_log, xml_export_file.read)
expected_content = replace_person_details(expected_content)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|
entry = Zip::File.open_buffer(content).find_entry(expected_data_filename)
expect(entry).not_to be_nil
expect(entry.get_input_stream.read).to eq(expected_content)
end
export_service.export_xml_lettings_logs
end
end
context "with 23/24 collection period" do
before do
Timecop.freeze(Time.zone.local(2023, 4, 3))

Loading…
Cancel
Save