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 relat6: RELAT, _suffix: true
enum relat7: RELAT, _suffix: true enum relat7: RELAT, _suffix: true
enum relat8: RELAT, _suffix: true enum relat8: RELAT, _suffix: true
enum sex1: GENDER, _suffix: true
enum sex2: GENDER, _suffix: true enum sex2: GENDER, _suffix: true
enum sex3: GENDER, _suffix: true enum sex3: GENDER, _suffix: true
enum sex4: 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| case_logs.each do |case_log|
form = doc.create_element("form") form = doc.create_element("form")
doc.at("forms") << 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) form << doc.create_element(key, value)
end end
end end

324
spec/fixtures/exports/case_logs.xml vendored

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<forms> <forms>
<form> <form>
<id>{id_1}</id> <id>{id}</id>
<status>completed</status> <status>2</status>
<created_at>2022-02-08 16:52:15 +0000</created_at> <created_at>2022-02-08 16:52:15 UTC</created_at>
<updated_at>2022-02-08 16:52:15 +0000</updated_at> <updated_at>2022-02-08 16:52:15 UTC</updated_at>
<tenant_code>BZ737</tenant_code> <tenant_code>BZ737</tenant_code>
<age1>35</age1> <age1>35</age1>
<sex1>Female</sex1> <sex1>F</sex1>
<ethnic>White: Irish</ethnic> <ethnic>2</ethnic>
<national>Estonia</national> <national>4</national>
<prevten>Private sector tenancy</prevten> <prevten>3</prevten>
<ecstat1>Part-time - Less than 30 hours</ecstat1> <ecstat1>2</ecstat1>
<hhmemb>2</hhmemb> <hhmemb>2</hhmemb>
<relat2>Partner</relat2> <relat2>P</relat2>
<age2>32</age2> <age2>32</age2>
<sex2>Male</sex2> <sex2>M</sex2>
<ecstat2>Not seeking work</ecstat2> <ecstat2>6</ecstat2>
<relat3/> <relat3/>
<age3/> <age3/>
<sex3/> <sex3/>
@ -41,57 +41,57 @@
<age8/> <age8/>
<sex8/> <sex8/>
<ecstat8/> <ecstat8/>
<homeless>Other homeless - not found statutorily homeless but considered homeless by landlord</homeless> <homeless>7</homeless>
<underoccupation_benefitcap>No</underoccupation_benefitcap> <underoccupation_benefitcap>2</underoccupation_benefitcap>
<leftreg>No - they left up to 5 years ago</leftreg> <leftreg>4</leftreg>
<reservist>No</reservist> <reservist>2</reservist>
<illness>Yes</illness> <illness>1</illness>
<preg_occ>Yes</preg_occ> <preg_occ>1</preg_occ>
<tenancy_code>BZ757</tenancy_code> <tenancy_code>BZ757</tenancy_code>
<startertenancy>No</startertenancy> <startertenancy>2</startertenancy>
<tenancylength>5</tenancylength> <tenancylength>5</tenancylength>
<tenancy>Secure (including flexible)</tenancy> <tenancy>1</tenancy>
<landlord>This landlord</landlord> <landlord>1</landlord>
<previous_postcode>SE2 6RT</previous_postcode> <previous_postcode>SE2 6RT</previous_postcode>
<rsnvac>Tenant abandoned property</rsnvac> <rsnvac>6</rsnvac>
<unittype_gn>House</unittype_gn> <unittype_gn>7</unittype_gn>
<beds>3</beds> <beds>3</beds>
<offered>2</offered> <offered>2</offered>
<wchair>Yes</wchair> <wchair>1</wchair>
<earnings>68</earnings> <earnings>68</earnings>
<incfreq>Weekly</incfreq> <incfreq>1</incfreq>
<benefits>Some</benefits> <benefits>2</benefits>
<period>Every 2 weeks</period> <period>2</period>
<layear>1 year but under 2 years</layear> <layear>7</layear>
<lawaitlist>Less than 1 year</lawaitlist> <lawaitlist>2</lawaitlist>
<property_postcode>NW1 5TY</property_postcode> <property_postcode>NW1 5TY</property_postcode>
<reasonpref>Yes</reasonpref> <reasonpref>1</reasonpref>
<cbl>Yes</cbl> <cbl>1</cbl>
<chr>Yes</chr> <chr>1</chr>
<cap>No</cap> <cap>0</cap>
<other_reason_for_leaving_last_settled_home/> <other_reason_for_leaving_last_settled_home/>
<housingneeds_a>Yes</housingneeds_a> <housingneeds_a>1</housingneeds_a>
<housingneeds_b>No</housingneeds_b> <housingneeds_b>0</housingneeds_b>
<housingneeds_c>No</housingneeds_c> <housingneeds_c>0</housingneeds_c>
<housingneeds_f>No</housingneeds_f> <housingneeds_f>0</housingneeds_f>
<housingneeds_g>No</housingneeds_g> <housingneeds_g>0</housingneeds_g>
<housingneeds_h>No</housingneeds_h> <housingneeds_h>0</housingneeds_h>
<accessibility_requirements_prefer_not_to_say>No</accessibility_requirements_prefer_not_to_say> <accessibility_requirements_prefer_not_to_say>0</accessibility_requirements_prefer_not_to_say>
<illness_type_1>No</illness_type_1> <illness_type_1>0</illness_type_1>
<illness_type_2>Yes</illness_type_2> <illness_type_2>1</illness_type_2>
<illness_type_3>No</illness_type_3> <illness_type_3>0</illness_type_3>
<illness_type_4>No</illness_type_4> <illness_type_4>0</illness_type_4>
<illness_type_8>No</illness_type_8> <illness_type_8>0</illness_type_8>
<illness_type_5>No</illness_type_5> <illness_type_5>0</illness_type_5>
<illness_type_6>No</illness_type_6> <illness_type_6>0</illness_type_6>
<illness_type_7>No</illness_type_7> <illness_type_7>0</illness_type_7>
<illness_type_9>No</illness_type_9> <illness_type_9>0</illness_type_9>
<illness_type_10>No</illness_type_10> <illness_type_10>0</illness_type_10>
<rp_homeless>Yes</rp_homeless> <rp_homeless>1</rp_homeless>
<rp_insan_unsat>No</rp_insan_unsat> <rp_insan_unsat>0</rp_insan_unsat>
<rp_medwel>No</rp_medwel> <rp_medwel>0</rp_medwel>
<rp_hardship>No</rp_hardship> <rp_hardship>0</rp_hardship>
<rp_dontknow>No</rp_dontknow> <rp_dontknow>0</rp_dontknow>
<tenancyother/> <tenancyother/>
<override_net_income_validation/> <override_net_income_validation/>
<property_owner_organisation>Test</property_owner_organisation> <property_owner_organisation>Test</property_owner_organisation>
@ -101,38 +101,38 @@
<rent_type>1</rent_type> <rent_type>1</rent_type>
<intermediate_rent_product_name>2</intermediate_rent_product_name> <intermediate_rent_product_name>2</intermediate_rent_product_name>
<purchaser_code>798794</purchaser_code> <purchaser_code>798794</purchaser_code>
<reason>Permanently decanted from another property owned by this landlord</reason> <reason>1</reason>
<propcode>123</propcode> <propcode>123</propcode>
<majorrepairs>Yes</majorrepairs> <majorrepairs>1</majorrepairs>
<la>Barnet</la> <la>E09000003</la>
<prevloc>Ashford</prevloc> <prevloc>E07000105</prevloc>
<hb>Housing benefit</hb> <hb>1</hb>
<hbrentshortfall>Yes</hbrentshortfall> <hbrentshortfall>1</hbrentshortfall>
<postcode>NW1</postcode> <postcode>NW1</postcode>
<postcod2>5TY</postcod2> <postcod2>5TY</postcod2>
<ppostc1>SE2</ppostc1> <ppostc1>SE2</ppostc1>
<ppostc2>6RT</ppostc2> <ppostc2>6RT</ppostc2>
<property_relet>No</property_relet> <property_relet>0</property_relet>
<mrcdate>2022-02-08 16:52:15 +0000</mrcdate> <mrcdate>2022-02-08 16:52:15 UTC</mrcdate>
<mrcday>8</mrcday> <mrcday>8</mrcday>
<mrcmonth>2</mrcmonth> <mrcmonth>2</mrcmonth>
<mrcyear>2022</mrcyear> <mrcyear>2022</mrcyear>
<other_hhmemb>1</other_hhmemb> <other_hhmemb>1</other_hhmemb>
<incref>No</incref> <incref>0</incref>
<sale_completion_date/> <sale_completion_date/>
<startdate>2022-02-08 16:52:15 +0000</startdate> <startdate>2022-02-08 16:52:15 UTC</startdate>
<armedforces>A current or former regular in the UK Armed Forces (excluding National Service)</armedforces> <armedforces>1</armedforces>
<first_time_property_let_as_social_housing/> <first_time_property_let_as_social_housing/>
<unitletas>Affordable rent basis</unitletas> <unitletas>2</unitletas>
<builtype>Purpose built</builtype> <builtype>1</builtype>
<property_void_date>2019-11-03 00:00:00 +0000</property_void_date> <property_void_date>2019-11-03 00:00:00 UTC</property_void_date>
<owning_organisation_id>{owning_org_id_1}</owning_organisation_id> <owning_organisation_id>{owning_org_id}</owning_organisation_id>
<managing_organisation_id>{managing_org_id_1}</managing_organisation_id> <managing_organisation_id>{managing_org_id}</managing_organisation_id>
<renttype/> <renttype/>
<needstype>General needs</needstype> <needstype>1</needstype>
<lettype>Affordable Rent General needs LA</lettype> <lettype>7</lettype>
<postcode_known>Yes</postcode_known> <postcode_known>1</postcode_known>
<la_known>Yes</la_known> <la_known>1</la_known>
<is_la_inferred>false</is_la_inferred> <is_la_inferred>false</is_la_inferred>
<day>8</day> <day>8</day>
<month>2</month> <month>2</month>
@ -140,12 +140,12 @@
<totchild>0</totchild> <totchild>0</totchild>
<totelder>0</totelder> <totelder>0</totelder>
<totadult>2</totadult> <totadult>2</totadult>
<net_income_known>Yes</net_income_known> <net_income_known>0</net_income_known>
<has_benefits>Yes</has_benefits> <has_benefits>Yes</has_benefits>
<nocharge>No</nocharge> <nocharge>0</nocharge>
<is_carehome>No</is_carehome> <is_carehome>0</is_carehome>
<letting_in_sheltered_accommodation>No</letting_in_sheltered_accommodation> <letting_in_sheltered_accommodation>3</letting_in_sheltered_accommodation>
<household_charge>Yes</household_charge> <household_charge>1</household_charge>
<referral/> <referral/>
<brent>200.0</brent> <brent>200.0</brent>
<scharge>50.0</scharge> <scharge>50.0</scharge>
@ -154,168 +154,8 @@
<tcharge>325.0</tcharge> <tcharge>325.0</tcharge>
<tshortfall>12.0</tshortfall> <tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge> <chcharge>7.0</chcharge>
<declaration>Yes</declaration> <declaration>1</declaration>
<previous_postcode_known>Yes</previous_postcode_known> <previous_postcode_known>1</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>
<previous_la_known/> <previous_la_known/>
<is_previous_la_inferred>false</is_previous_la_inferred> <is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/> <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_filepath) { "spec/fixtures/exports/case_logs.xml" }
let(:export_file) { File.open(export_filepath, "r:UTF-8") } 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(: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) def replace_entity_ids(export_template)
export_template.sub!(/\{id_1\}/, case_logs[0]["id"].to_s) export_template.sub!(/\{id\}/, case_log["id"].to_s)
export_template.sub!(/\{id_2\}/, case_logs[1]["id"].to_s) export_template.sub!(/\{owning_org_id\}/, case_log["owning_organisation_id"].to_s)
export_template.sub!(/\{owning_org_id_1\}/, case_logs[0]["owning_organisation_id"].to_s) export_template.sub!(/\{managing_org_id\}/, case_log["managing_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)
end end
context "when exporting case logs" do context "when exporting case logs" do
@ -21,7 +18,7 @@ RSpec.describe Exports::CaseLogExportService do
before do before do
Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00")) Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00"))
case_logs case_log
end end
it "generate an XML export file with the expected filename" do it "generate an XML export file with the expected filename" do

Loading…
Cancel
Save