Browse Source

Adjust test data to fit with the mappings that are known so far

pull/1331/head
Kat 3 years ago
parent
commit
5d2838b4d9
  1. 9
      app/services/imports/sales_logs_import_service.rb
  2. 4
      spec/fixtures/imports/sales_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml
  3. 42
      spec/fixtures/imports/sales_logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml
  4. 4
      spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  5. 4
      spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml
  6. 6
      spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
  7. 6
      spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
  8. 43
      spec/services/imports/sales_logs_import_service_spec.rb

9
app/services/imports/sales_logs_import_service.rb

@ -416,7 +416,7 @@ module Imports
attributes["national"] ||= 13
attributes["ecstat1"] ||= 10
attributes["income1nk"] ||= attributes["income1"].present? ? 0 : 1
attributes["hholdcount"] ||= 0 # just for testing, might need to change
attributes["hholdcount"] ||= default_household_count(attributes) # just for testing, might need to change
# buyer 2 characteristics
if attributes["jointpur"] == 1
@ -439,5 +439,12 @@ module Imports
applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log) }.flatten
applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id)
end
# just for testing, logic might need to change
def default_household_count(attributes)
return 0 if attributes["hhmemb"].zero? || attributes["hhmemb"].blank?
attributes["jointpur"] == 1 ? attributes["hhmemb"] - 2 : attributes["hhmemb"] - 1
end
end
end

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

@ -219,7 +219,9 @@
<Group>
<P1IncKnown>2 No</P1IncKnown>
<Q2Person1Income/>
<Q2Person1Mortgage/>
<!-- replace with commented options to test in the future -->
<!-- <Q2Person1Mortgage/> -->
<Q2Person1Mortgage>2 No</Q2Person1Mortgage>
<P2IncKnown/>
<Q2Person2Income/>
<Q2Person2MortApplication/>

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

@ -14,7 +14,9 @@
<meta:rules assert-valid="true"/>
</meta:metadata>
<Group>
<Qdp>Yes</Qdp>
<!-- replace with commented options to test in the future -->
<!-- <Qdp>Yes</Qdp> -->
<Qdp/>
<CompletionDate>2023-02-01</CompletionDate>
<PurchaserCode>Discount ownership example</PurchaserCode>
<Ownership>2 Yes - a discount ownership scheme</Ownership>
@ -33,8 +35,11 @@
<Q12PropertyType>3 House</Q12PropertyType>
<Q13BuildingType>1 Purpose built</Q13BuildingType>
<Q14Postcode override-field="">SW1A 1AA</Q14Postcode>
<Q14PropertyLocation>Westminster</Q14PropertyLocation>
<Q14ONSLACode>E09000033</Q14ONSLACode>
<!-- replace with commented options to test in the future -->
<!-- <Q14PropertyLocation>Westminster</Q14PropertyLocation>
<Q14ONSLACode>E09000033</Q14ONSLACode> -->
<Q14PropertyLocation>Cheltenham</Q14PropertyLocation>
<Q14ONSLACode>E07000078</Q14ONSLACode>
<Q15Wheelchair>3 Don&#x2019;t know</Q15Wheelchair>
</Group>
<Group>
@ -193,17 +198,24 @@
<EXYEAR/>
<PPOSTC1>GL51</PPOSTC1>
<PPOSTC2>9EX</PPOSTC2>
<PCODE1>SW1A</PCODE1>
<PCODE2>1AA</PCODE2>
<!-- replace with commented options to test in the future -->
<!-- <PCODE1>SW1A</PCODE1>
<PCODE2>1AA</PCODE2> -->
<PCODE1>GL51</PCODE1>
<PCODE2>9EX</PCODE2>
<NOINT>1</NOINT>
</Group>
<Group>
<Q6PrevTenure/>
<!-- replace with commented options to test in the future -->
<!-- <Q6PrevTenure/> -->
<Q6PrevTenure>3 Private tenant</Q6PrevTenure>
<Q7Postcode override-field="">GL51 9EX</Q7Postcode>
<Q7UnknownPostcode/>
<Q7PrevLocation>Cheltenham</Q7PrevLocation>
<Q7ONSLACode>E07000078</Q7ONSLACode>
<PREGYRHA/>
<!-- replace with commented options to test in the future -->
<!-- <PREGYRHA/> -->
<PREGYRHA>Yes</PREGYRHA>
<PREGORHA/>
<PREGLA/>
<PREGHBA/>
@ -219,7 +231,9 @@
<Group>
<P1IncKnown/>
<Q2Person1Income/>
<Q2Person1Mortgage/>
<Q2Person1Mortgage>1 Yes</Q2Person1Mortgage>
<!-- replace with commented options to test in the future -->
<!-- <Q2Person1Mortgage/> -->
<P2IncKnown/>
<Q2Person2Income/>
<Q2Person2MortApplication/>
@ -229,7 +243,9 @@
<Q4PrevOwnedProperty/>
</Group>
<Group>
<Q16aProplen2/>
<!-- replace with commented options to test in the future -->
<!-- <Q16aProplen2/> -->
<Q16aProplen2>1</Q16aProplen2>
<Q17aStaircase/>
<PercentBought override-field=""/>
<PercentOwns/>
@ -260,7 +276,9 @@
<MortgageUsedDO>1 Yes</MortgageUsedDO>
<Q34Mortgage override-field="true">134750</Q34Mortgage>
<Q34a>Halifax</Q34a>
<Q34b/>
<!-- replace with commented options to test in the future -->
<!-- <Q34b/> -->
<Q34b>33</Q34b>
<Q35Borrowing>2 No</Q35Borrowing>
<Q36CashDeposit>0</Q36CashDeposit>
<Q37MonthlyCharges>0.00</Q37MonthlyCharges>
@ -280,7 +298,9 @@
<TOTCHILD>0</TOTCHILD>
</Group>
<Group>
<HHTYPE>3 = 1 adult</HHTYPE>
<HHTYPE>9 = other</HHTYPE>
<!-- replace with commented options to test in the future -->
<!-- <HHTYPE>3 = 1 adult</HHTYPE> -->
</Group>
<Group>
<DerSaleType>14 Preserved Right to Buy (PRTB)</DerSaleType>

4
spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -229,7 +229,9 @@
<Q4PrevOwnedProperty>1 Yes</Q4PrevOwnedProperty>
</Group>
<Group>
<Q16aProplen2/>
<!-- replace with commented options to test in the future -->
<!-- <Q16aProplen2/> -->
<Q16aProplen2>1</Q16aProplen2>
<Q17aStaircase>2 No</Q17aStaircase>
<PercentBought override-field=""/>
<PercentOwns>30</PercentOwns>

4
spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml vendored

@ -229,7 +229,9 @@
<Q4PrevOwnedProperty>1 Yes</Q4PrevOwnedProperty>
</Group>
<Group>
<Q16aProplen2/>
<!-- replace with commented options to test in the future -->
<!-- <Q16aProplen2/> -->
<Q16aProplen2>1</Q16aProplen2>
<Q17aStaircase>2 No</Q17aStaircase>
<PercentBought override-field=""/>
<PercentOwns>30</PercentOwns>

6
spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml vendored

@ -229,7 +229,9 @@
<Q4PrevOwnedProperty>1 Yes</Q4PrevOwnedProperty>
</Group>
<Group>
<Q16aProplen2/>
<!-- replace with commented options to test in the future -->
<!-- <Q16aProplen2/> -->
<Q16aProplen2>1</Q16aProplen2>
<Q17aStaircase>2 No</Q17aStaircase>
<PercentBought override-field=""/>
<PercentOwns>30</PercentOwns>
@ -250,7 +252,7 @@
<Q26CashDeposit override-field="">89000</Q26CashDeposit>
<Q27SocialHomeBuy/>
<Q28MonthlyRent>912.00</Q28MonthlyRent>
<Q29MonthlyCharges>134.24</Q29MonthlyCharges>
<Q29MonthlyCharges></Q29MonthlyCharges>
</Group>
<Group>
<Q16aProplensec2/>

6
spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml vendored

@ -219,7 +219,7 @@
<Group>
<P1IncKnown>1 Yes</P1IncKnown>
<Q2Person1Income>47000</Q2Person1Income>
<Q2Person1Mortgage>1 Yes</Q2Person1Mortgage>
<Q2Person1Mortgage></Q2Person1Mortgage>
<P2IncKnown/>
<Q2Person2Income/>
<Q2Person2MortApplication/>
@ -229,7 +229,9 @@
<Q4PrevOwnedProperty>1 Yes</Q4PrevOwnedProperty>
</Group>
<Group>
<Q16aProplen2/>
<!-- replace with commented options to test in the future -->
<!-- <Q16aProplen2/> -->
<Q16aProplen2>1</Q16aProplen2>
<Q17aStaircase>2 No</Q17aStaircase>
<PercentBought override-field=""/>
<PercentOwns>30</PercentOwns>

43
spec/services/imports/sales_logs_import_service_spec.rb

@ -553,6 +553,49 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.prevown).to eq(2)
end
end
context "when inferring household count" do
let(:sales_log_id) { discounted_ownership_sales_log_id }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets hholdcount to hhmemb - 1 if not answered and not joint purchase" do
sales_log_xml.at_xpath("//xmlns:HHMEMB").content = "3"
sales_log_xml.at_xpath("//xmlns:joint").content = "2 No"
sales_log_xml.at_xpath("//xmlns:LiveInOther").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.hholdcount).to eq(2)
end
it "sets hholdcount to hhmemb - 2 if not answered and joint purchase" do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No"
sales_log_xml.at_xpath("//xmlns:HHMEMB").content = "3"
sales_log_xml.at_xpath("//xmlns:LiveInOther").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.hholdcount).to eq(1)
end
it "sets hholdcount to 0 if HHMEMB is 0" do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No"
sales_log_xml.at_xpath("//xmlns:HHMEMB").content = "0"
sales_log_xml.at_xpath("//xmlns:LiveInOther").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.hholdcount).to eq(0)
end
end
end
end
end

Loading…
Cancel
Save