Browse Source

Replaces enum text values in export by related numbers (#310)

pull/314/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
9545122114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/case_log.rb
  2. 3
      app/services/exports/case_log_export_service.rb
  3. 324
      spec/fixtures/exports/case_logs.xml
  4. 13
      spec/services/exports/case_log_export_service_spec.rb

1
app/models/case_log.rb

@ -55,6 +55,7 @@ class CaseLog < ApplicationRecord
enum relat6: RELAT, _suffix: true
enum relat7: RELAT, _suffix: true
enum relat8: RELAT, _suffix: true
enum sex1: GENDER, _suffix: true
enum sex2: GENDER, _suffix: true
enum sex3: GENDER, _suffix: true
enum sex4: GENDER, _suffix: true

3
app/services/exports/case_log_export_service.rb

@ -49,7 +49,8 @@ module Exports
case_logs.each do |case_log|
form = doc.create_element("form")
doc.at("forms") << form
case_log.attributes.each do |key, value|
case_log.attributes.each do |key, _|
value = case_log.read_attribute_before_type_cast(key)
form << doc.create_element(key, value)
end
end

324
spec/fixtures/exports/case_logs.xml vendored

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<forms>
<form>
<id>{id_1}</id>
<status>completed</status>
<created_at>2022-02-08 16:52:15 +0000</created_at>
<updated_at>2022-02-08 16:52:15 +0000</updated_at>
<id>{id}</id>
<status>2</status>
<created_at>2022-02-08 16:52:15 UTC</created_at>
<updated_at>2022-02-08 16:52:15 UTC</updated_at>
<tenant_code>BZ737</tenant_code>
<age1>35</age1>
<sex1>Female</sex1>
<ethnic>White: Irish</ethnic>
<national>Estonia</national>
<prevten>Private sector tenancy</prevten>
<ecstat1>Part-time - Less than 30 hours</ecstat1>
<sex1>F</sex1>
<ethnic>2</ethnic>
<national>4</national>
<prevten>3</prevten>
<ecstat1>2</ecstat1>
<hhmemb>2</hhmemb>
<relat2>Partner</relat2>
<relat2>P</relat2>
<age2>32</age2>
<sex2>Male</sex2>
<ecstat2>Not seeking work</ecstat2>
<sex2>M</sex2>
<ecstat2>6</ecstat2>
<relat3/>
<age3/>
<sex3/>
@ -41,57 +41,57 @@
<age8/>
<sex8/>
<ecstat8/>
<homeless>Other homeless - not found statutorily homeless but considered homeless by landlord</homeless>
<underoccupation_benefitcap>No</underoccupation_benefitcap>
<leftreg>No - they left up to 5 years ago</leftreg>
<reservist>No</reservist>
<illness>Yes</illness>
<preg_occ>Yes</preg_occ>
<homeless>7</homeless>
<underoccupation_benefitcap>2</underoccupation_benefitcap>
<leftreg>4</leftreg>
<reservist>2</reservist>
<illness>1</illness>
<preg_occ>1</preg_occ>
<tenancy_code>BZ757</tenancy_code>
<startertenancy>No</startertenancy>
<startertenancy>2</startertenancy>
<tenancylength>5</tenancylength>
<tenancy>Secure (including flexible)</tenancy>
<landlord>This landlord</landlord>
<tenancy>1</tenancy>
<landlord>1</landlord>
<previous_postcode>SE2 6RT</previous_postcode>
<rsnvac>Tenant abandoned property</rsnvac>
<unittype_gn>House</unittype_gn>
<rsnvac>6</rsnvac>
<unittype_gn>7</unittype_gn>
<beds>3</beds>
<offered>2</offered>
<wchair>Yes</wchair>
<wchair>1</wchair>
<earnings>68</earnings>
<incfreq>Weekly</incfreq>
<benefits>Some</benefits>
<period>Every 2 weeks</period>
<layear>1 year but under 2 years</layear>
<lawaitlist>Less than 1 year</lawaitlist>
<incfreq>1</incfreq>
<benefits>2</benefits>
<period>2</period>
<layear>7</layear>
<lawaitlist>2</lawaitlist>
<property_postcode>NW1 5TY</property_postcode>
<reasonpref>Yes</reasonpref>
<cbl>Yes</cbl>
<chr>Yes</chr>
<cap>No</cap>
<reasonpref>1</reasonpref>
<cbl>1</cbl>
<chr>1</chr>
<cap>0</cap>
<other_reason_for_leaving_last_settled_home/>
<housingneeds_a>Yes</housingneeds_a>
<housingneeds_b>No</housingneeds_b>
<housingneeds_c>No</housingneeds_c>
<housingneeds_f>No</housingneeds_f>
<housingneeds_g>No</housingneeds_g>
<housingneeds_h>No</housingneeds_h>
<accessibility_requirements_prefer_not_to_say>No</accessibility_requirements_prefer_not_to_say>
<illness_type_1>No</illness_type_1>
<illness_type_2>Yes</illness_type_2>
<illness_type_3>No</illness_type_3>
<illness_type_4>No</illness_type_4>
<illness_type_8>No</illness_type_8>
<illness_type_5>No</illness_type_5>
<illness_type_6>No</illness_type_6>
<illness_type_7>No</illness_type_7>
<illness_type_9>No</illness_type_9>
<illness_type_10>No</illness_type_10>
<rp_homeless>Yes</rp_homeless>
<rp_insan_unsat>No</rp_insan_unsat>
<rp_medwel>No</rp_medwel>
<rp_hardship>No</rp_hardship>
<rp_dontknow>No</rp_dontknow>
<housingneeds_a>1</housingneeds_a>
<housingneeds_b>0</housingneeds_b>
<housingneeds_c>0</housingneeds_c>
<housingneeds_f>0</housingneeds_f>
<housingneeds_g>0</housingneeds_g>
<housingneeds_h>0</housingneeds_h>
<accessibility_requirements_prefer_not_to_say>0</accessibility_requirements_prefer_not_to_say>
<illness_type_1>0</illness_type_1>
<illness_type_2>1</illness_type_2>
<illness_type_3>0</illness_type_3>
<illness_type_4>0</illness_type_4>
<illness_type_8>0</illness_type_8>
<illness_type_5>0</illness_type_5>
<illness_type_6>0</illness_type_6>
<illness_type_7>0</illness_type_7>
<illness_type_9>0</illness_type_9>
<illness_type_10>0</illness_type_10>
<rp_homeless>1</rp_homeless>
<rp_insan_unsat>0</rp_insan_unsat>
<rp_medwel>0</rp_medwel>
<rp_hardship>0</rp_hardship>
<rp_dontknow>0</rp_dontknow>
<tenancyother/>
<override_net_income_validation/>
<property_owner_organisation>Test</property_owner_organisation>
@ -101,38 +101,38 @@
<rent_type>1</rent_type>
<intermediate_rent_product_name>2</intermediate_rent_product_name>
<purchaser_code>798794</purchaser_code>
<reason>Permanently decanted from another property owned by this landlord</reason>
<reason>1</reason>
<propcode>123</propcode>
<majorrepairs>Yes</majorrepairs>
<la>Barnet</la>
<prevloc>Ashford</prevloc>
<hb>Housing benefit</hb>
<hbrentshortfall>Yes</hbrentshortfall>
<majorrepairs>1</majorrepairs>
<la>E09000003</la>
<prevloc>E07000105</prevloc>
<hb>1</hb>
<hbrentshortfall>1</hbrentshortfall>
<postcode>NW1</postcode>
<postcod2>5TY</postcod2>
<ppostc1>SE2</ppostc1>
<ppostc2>6RT</ppostc2>
<property_relet>No</property_relet>
<mrcdate>2022-02-08 16:52:15 +0000</mrcdate>
<property_relet>0</property_relet>
<mrcdate>2022-02-08 16:52:15 UTC</mrcdate>
<mrcday>8</mrcday>
<mrcmonth>2</mrcmonth>
<mrcyear>2022</mrcyear>
<other_hhmemb>1</other_hhmemb>
<incref>No</incref>
<incref>0</incref>
<sale_completion_date/>
<startdate>2022-02-08 16:52:15 +0000</startdate>
<armedforces>A current or former regular in the UK Armed Forces (excluding National Service)</armedforces>
<startdate>2022-02-08 16:52:15 UTC</startdate>
<armedforces>1</armedforces>
<first_time_property_let_as_social_housing/>
<unitletas>Affordable rent basis</unitletas>
<builtype>Purpose built</builtype>
<property_void_date>2019-11-03 00:00:00 +0000</property_void_date>
<owning_organisation_id>{owning_org_id_1}</owning_organisation_id>
<managing_organisation_id>{managing_org_id_1}</managing_organisation_id>
<unitletas>2</unitletas>
<builtype>1</builtype>
<property_void_date>2019-11-03 00:00:00 UTC</property_void_date>
<owning_organisation_id>{owning_org_id}</owning_organisation_id>
<managing_organisation_id>{managing_org_id}</managing_organisation_id>
<renttype/>
<needstype>General needs</needstype>
<lettype>Affordable Rent General needs LA</lettype>
<postcode_known>Yes</postcode_known>
<la_known>Yes</la_known>
<needstype>1</needstype>
<lettype>7</lettype>
<postcode_known>1</postcode_known>
<la_known>1</la_known>
<is_la_inferred>false</is_la_inferred>
<day>8</day>
<month>2</month>
@ -140,12 +140,12 @@
<totchild>0</totchild>
<totelder>0</totelder>
<totadult>2</totadult>
<net_income_known>Yes</net_income_known>
<net_income_known>0</net_income_known>
<has_benefits>Yes</has_benefits>
<nocharge>No</nocharge>
<is_carehome>No</is_carehome>
<letting_in_sheltered_accommodation>No</letting_in_sheltered_accommodation>
<household_charge>Yes</household_charge>
<nocharge>0</nocharge>
<is_carehome>0</is_carehome>
<letting_in_sheltered_accommodation>3</letting_in_sheltered_accommodation>
<household_charge>1</household_charge>
<referral/>
<brent>200.0</brent>
<scharge>50.0</scharge>
@ -154,168 +154,8 @@
<tcharge>325.0</tcharge>
<tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge>
<declaration>Yes</declaration>
<previous_postcode_known>Yes</previous_postcode_known>
<previous_la_known/>
<is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/>
</form>
<form>
<id>{id_2}</id>
<status>completed</status>
<created_at>2022-02-08 16:52:15 +0000</created_at>
<updated_at>2022-02-08 16:52:15 +0000</updated_at>
<tenant_code>BZ737</tenant_code>
<age1>35</age1>
<sex1>Female</sex1>
<ethnic>White: Irish</ethnic>
<national>Estonia</national>
<prevten>Private sector tenancy</prevten>
<ecstat1>Part-time - Less than 30 hours</ecstat1>
<hhmemb>2</hhmemb>
<relat2>Partner</relat2>
<age2>32</age2>
<sex2>Male</sex2>
<ecstat2>Not seeking work</ecstat2>
<relat3/>
<age3/>
<sex3/>
<ecstat3/>
<relat4/>
<age4/>
<sex4/>
<ecstat4/>
<relat5/>
<age5/>
<sex5/>
<ecstat5/>
<relat6/>
<age6/>
<sex6/>
<ecstat6/>
<relat7/>
<age7/>
<sex7/>
<ecstat7/>
<relat8/>
<age8/>
<sex8/>
<ecstat8/>
<homeless>Other homeless - not found statutorily homeless but considered homeless by landlord</homeless>
<underoccupation_benefitcap>No</underoccupation_benefitcap>
<leftreg>No - they left up to 5 years ago</leftreg>
<reservist>No</reservist>
<illness>Yes</illness>
<preg_occ>Yes</preg_occ>
<tenancy_code>BZ757</tenancy_code>
<startertenancy>No</startertenancy>
<tenancylength>5</tenancylength>
<tenancy>Secure (including flexible)</tenancy>
<landlord>This landlord</landlord>
<previous_postcode>SE2 6RT</previous_postcode>
<rsnvac>Tenant abandoned property</rsnvac>
<unittype_gn>House</unittype_gn>
<beds>3</beds>
<offered>2</offered>
<wchair>Yes</wchair>
<earnings>68</earnings>
<incfreq>Weekly</incfreq>
<benefits>Some</benefits>
<period>Every 2 weeks</period>
<layear>1 year but under 2 years</layear>
<lawaitlist>Less than 1 year</lawaitlist>
<property_postcode>NW1 5TY</property_postcode>
<reasonpref>Yes</reasonpref>
<cbl>Yes</cbl>
<chr>Yes</chr>
<cap>No</cap>
<other_reason_for_leaving_last_settled_home/>
<housingneeds_a>Yes</housingneeds_a>
<housingneeds_b>No</housingneeds_b>
<housingneeds_c>No</housingneeds_c>
<housingneeds_f>No</housingneeds_f>
<housingneeds_g>No</housingneeds_g>
<housingneeds_h>No</housingneeds_h>
<accessibility_requirements_prefer_not_to_say>No</accessibility_requirements_prefer_not_to_say>
<illness_type_1>No</illness_type_1>
<illness_type_2>Yes</illness_type_2>
<illness_type_3>No</illness_type_3>
<illness_type_4>No</illness_type_4>
<illness_type_8>No</illness_type_8>
<illness_type_5>No</illness_type_5>
<illness_type_6>No</illness_type_6>
<illness_type_7>No</illness_type_7>
<illness_type_9>No</illness_type_9>
<illness_type_10>No</illness_type_10>
<rp_homeless>Yes</rp_homeless>
<rp_insan_unsat>No</rp_insan_unsat>
<rp_medwel>No</rp_medwel>
<rp_hardship>No</rp_hardship>
<rp_dontknow>No</rp_dontknow>
<tenancyother/>
<override_net_income_validation/>
<property_owner_organisation>Test</property_owner_organisation>
<property_manager_organisation>Test</property_manager_organisation>
<sale_or_letting/>
<renewal>1</renewal>
<rent_type>1</rent_type>
<intermediate_rent_product_name>2</intermediate_rent_product_name>
<purchaser_code>798794</purchaser_code>
<reason>Permanently decanted from another property owned by this landlord</reason>
<propcode>123</propcode>
<majorrepairs>Yes</majorrepairs>
<la>Barnet</la>
<prevloc>Ashford</prevloc>
<hb>Housing benefit</hb>
<hbrentshortfall>Yes</hbrentshortfall>
<postcode>NW1</postcode>
<postcod2>5TY</postcod2>
<ppostc1>SE2</ppostc1>
<ppostc2>6RT</ppostc2>
<property_relet>No</property_relet>
<mrcdate>2022-02-08 16:52:15 +0000</mrcdate>
<mrcday>8</mrcday>
<mrcmonth>2</mrcmonth>
<mrcyear>2022</mrcyear>
<other_hhmemb>1</other_hhmemb>
<incref>No</incref>
<sale_completion_date/>
<startdate>2022-02-08 16:52:15 +0000</startdate>
<armedforces>A current or former regular in the UK Armed Forces (excluding National Service)</armedforces>
<first_time_property_let_as_social_housing/>
<unitletas>Affordable rent basis</unitletas>
<builtype>Purpose built</builtype>
<property_void_date>2019-11-03 00:00:00 +0000</property_void_date>
<owning_organisation_id>{owning_org_id_2}</owning_organisation_id>
<managing_organisation_id>{managing_org_id_2}</managing_organisation_id>
<renttype/>
<needstype>General needs</needstype>
<lettype>Affordable Rent General needs LA</lettype>
<postcode_known>Yes</postcode_known>
<la_known>Yes</la_known>
<is_la_inferred>false</is_la_inferred>
<day>8</day>
<month>2</month>
<year>2022</year>
<totchild>0</totchild>
<totelder>0</totelder>
<totadult>2</totadult>
<net_income_known>Yes</net_income_known>
<has_benefits>Yes</has_benefits>
<nocharge>No</nocharge>
<is_carehome>No</is_carehome>
<letting_in_sheltered_accommodation>No</letting_in_sheltered_accommodation>
<household_charge>Yes</household_charge>
<referral/>
<brent>200.0</brent>
<scharge>50.0</scharge>
<pscharge>40.0</pscharge>
<supcharg>35.0</supcharg>
<tcharge>325.0</tcharge>
<tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge>
<declaration>Yes</declaration>
<previous_postcode_known>Yes</previous_postcode_known>
<declaration>1</declaration>
<previous_postcode_known>1</previous_postcode_known>
<previous_la_known/>
<is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/>

13
spec/services/exports/case_log_export_service_spec.rb

@ -5,15 +5,12 @@ RSpec.describe Exports::CaseLogExportService do
let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" }
let(:export_file) { File.open(export_filepath, "r:UTF-8") }
let(:expected_filename) { "core_2022_02_08/dat_core_2022_02_08_0001.xml" }
let(:case_logs) { FactoryBot.create_list(:case_log, 2, :completed) }
let(:case_log) { FactoryBot.create(:case_log, :completed) }
def replace_entity_ids(export_template)
export_template.sub!(/\{id_1\}/, case_logs[0]["id"].to_s)
export_template.sub!(/\{id_2\}/, case_logs[1]["id"].to_s)
export_template.sub!(/\{owning_org_id_1\}/, case_logs[0]["owning_organisation_id"].to_s)
export_template.sub!(/\{owning_org_id_2\}/, case_logs[1]["owning_organisation_id"].to_s)
export_template.sub!(/\{managing_org_id_1\}/, case_logs[0]["managing_organisation_id"].to_s)
export_template.sub!(/\{managing_org_id_2\}/, case_logs[1]["managing_organisation_id"].to_s)
export_template.sub!(/\{id\}/, case_log["id"].to_s)
export_template.sub!(/\{owning_org_id\}/, case_log["owning_organisation_id"].to_s)
export_template.sub!(/\{managing_org_id\}/, case_log["managing_organisation_id"].to_s)
end
context "when exporting case logs" do
@ -21,7 +18,7 @@ RSpec.describe Exports::CaseLogExportService do
before do
Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00"))
case_logs
case_log
end
it "generate an XML export file with the expected filename" do

Loading…
Cancel
Save