Browse Source

Update hbrentshortfall values and import corrections (#514)

pull/518/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
2643e707ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/case_log.rb
  2. 6
      app/models/form/question.rb
  3. 19
      app/services/imports/case_logs_import_service.rb
  4. 15
      config/forms/2021_2022.json
  5. 2
      docs/api/DLUHC-CORE-Data.v1.json
  6. 2
      spec/factories/case_log.rb
  7. 2
      spec/fixtures/complete_case_log.json
  8. 2
      spec/fixtures/exports/case_logs.xml
  9. 56
      spec/models/case_log_spec.rb
  10. 14
      spec/models/validations/financial_validations_spec.rb
  11. 3
      spec/services/imports/case_logs_import_service_spec.rb

4
app/models/case_log.rb

@ -166,8 +166,8 @@ class CaseLog < ApplicationRecord
end end
def has_hbrentshortfall? def has_hbrentshortfall?
# 0: Yes # 1: Yes
!!hbrentshortfall&.zero? hbrentshortfall == 1
end end
def postcode_known? def postcode_known?

6
app/models/form/question.rb

@ -254,7 +254,7 @@ private
net_income_known: [0], net_income_known: [0],
household_charge: [0], household_charge: [0],
is_carehome: [1], is_carehome: [1],
rent_shortfall: [0], hbrentshortfall: [1],
net_income_value_check: [0], net_income_value_check: [0],
}.freeze }.freeze
@ -278,7 +278,7 @@ private
net_income_known: [1], net_income_known: [1],
household_charge: [1], household_charge: [1],
is_carehome: [0], is_carehome: [0],
rent_shortfall: [1], hbrentshortfall: [2],
net_income_value_check: [1], net_income_value_check: [1],
}.freeze }.freeze
@ -286,7 +286,7 @@ private
letting_in_sheltered_accommodation: [3], letting_in_sheltered_accommodation: [3],
underoccupation_benefitcap: [3], underoccupation_benefitcap: [3],
reasonpref: [3], reasonpref: [3],
rent_shortfall: [1], hbrentshortfall: [3],
layear: [7], layear: [7],
reason_for_leaving_last_settled_home: [32], reason_for_leaving_last_settled_home: [32],
hb: [5], hb: [5],

19
app/services/imports/case_logs_import_service.rb

@ -149,10 +149,11 @@ module Imports
# Required for our form invalidated questions (not present in import) # Required for our form invalidated questions (not present in import)
attributes["previous_la_known"] = attributes["prevloc"].nil? ? 0 : 1 attributes["previous_la_known"] = attributes["prevloc"].nil? ? 0 : 1
attributes["is_la_inferred"] = false # Always keep the given LA attributes["is_la_inferred"] = attributes["postcode_full"].present?
attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"]) attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"])
attributes["declaration"] = declaration(xml_doc) attributes["declaration"] = declaration(xml_doc)
# Set charges to 0 if others are partially populated
unless attributes["brent"].nil? && unless attributes["brent"].nil? &&
attributes["scharge"].nil? && attributes["scharge"].nil? &&
attributes["pscharge"].nil? && attributes["pscharge"].nil? &&
@ -163,10 +164,18 @@ module Imports
attributes["supcharg"] ||= BigDecimal("0.0") attributes["supcharg"] ||= BigDecimal("0.0")
end end
# Handles confidential schemes
if attributes["postcode_full"] == "******"
attributes["postcode_known"] = 0
attributes["postcode_full"] = nil
end
previous_status = field_value(xml_doc, "meta", "status")
case_log = CaseLog.new(attributes) case_log = CaseLog.new(attributes)
save_case_log(case_log, attributes) save_case_log(case_log, attributes)
compute_differences(case_log, attributes) compute_differences(case_log, attributes)
check_status_completed(case_log) check_status_completed(case_log, previous_status)
end end
def save_case_log(case_log, attributes) def save_case_log(case_log, attributes)
@ -190,8 +199,8 @@ module Imports
@logger.warn "Differences found when saving log #{case_log.id}: #{differences}" unless differences.empty? @logger.warn "Differences found when saving log #{case_log.id}: #{differences}" unless differences.empty?
end end
def check_status_completed(case_log) def check_status_completed(case_log, previous_status)
unless case_log.status == "completed" if previous_status.include?("submitted") && case_log.status != "completed"
@logger.warn "Case log #{case_log.id} is not completed" @logger.warn "Case log #{case_log.id} is not completed"
end end
end end
@ -338,7 +347,7 @@ module Imports
end end
def details_known(index, attributes) def details_known(index, attributes)
return nil if attributes["hhmemb"].present? && index > attributes["hhmemb"] return nil if attributes["hhmemb"].nil? || index > attributes["hhmemb"]
if attributes["age#{index}_known"] == 1 && if attributes["age#{index}_known"] == 1 &&
attributes["sex#{index}"] == "R" && attributes["sex#{index}"] == "R" &&

15
config/forms/2021_2022.json

@ -5672,11 +5672,14 @@
"hint_text": "Also known as the ‘outstanding amount’.", "hint_text": "Also known as the ‘outstanding amount’.",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "1": {
"value": "Yes" "value": "Yes"
}, },
"1": { "2": {
"value": "No" "value": "No"
},
"3": {
"value": "Don’t know"
} }
} }
} }
@ -5735,19 +5738,19 @@
"depends_on": [ "depends_on": [
{ {
"hb": 1, "hb": 1,
"hbrentshortfall": 0 "hbrentshortfall": 1
}, },
{ {
"hb": 6, "hb": 6,
"hbrentshortfall": 0 "hbrentshortfall": 1
}, },
{ {
"hb": 7, "hb": 7,
"hbrentshortfall": 0 "hbrentshortfall": 1
}, },
{ {
"hb": 8, "hb": 8,
"hbrentshortfall": 0 "hbrentshortfall": 1
} }
] ]
} }

2
docs/api/DLUHC-CORE-Data.v1.json

@ -359,7 +359,7 @@
"cbl": 1, "cbl": 1,
"chr": 1, "chr": 1,
"cap": 0, "cap": 0,
"hbrentshortfall": 0, "hbrentshortfall": 1,
"tshortfall": 12, "tshortfall": 12,
"reasonother": null, "reasonother": null,
"housingneeds_a": 1, "housingneeds_a": 1,

2
spec/factories/case_log.rb

@ -115,7 +115,7 @@ FactoryBot.define do
la { "E09000003" } la { "E09000003" }
prevloc { "E07000105" } prevloc { "E07000105" }
hb { 6 } hb { 6 }
hbrentshortfall { 0 } hbrentshortfall { 1 }
tshortfall { 12 } tshortfall { 12 }
property_relet { 0 } property_relet { 0 }
mrcdate { Time.utc(2020, 5, 0o5, 10, 36, 49) } mrcdate { Time.utc(2020, 5, 0o5, 10, 36, 49) }

2
spec/fixtures/complete_case_log.json vendored

@ -83,7 +83,7 @@
"cbl": 1, "cbl": 1,
"chr": 1, "chr": 1,
"cap": 0, "cap": 0,
"hbrentshortfall": 0, "hbrentshortfall": 1,
"tshortfall": 12, "tshortfall": 12,
"reasonother": null, "reasonother": null,
"housingneeds_a": 1, "housingneeds_a": 1,

2
spec/fixtures/exports/case_logs.xml vendored

@ -96,7 +96,7 @@
<la>E09000003</la> <la>E09000003</la>
<prevloc>E07000105</prevloc> <prevloc>E07000105</prevloc>
<hb>6</hb> <hb>6</hb>
<hbrentshortfall>0</hbrentshortfall> <hbrentshortfall>1</hbrentshortfall>
<property_relet>0</property_relet> <property_relet>0</property_relet>
<mrcdate>2020-05-05 10:36:49 UTC</mrcdate> <mrcdate>2020-05-05 10:36:49 UTC</mrcdate>
<incref>0</incref> <incref>0</incref>

56
spec/models/case_log_spec.rb

@ -298,7 +298,7 @@ RSpec.describe CaseLog do
context "when the tenant is not in receipt of applicable benefits" do context "when the tenant is not in receipt of applicable benefits" do
it "correctly resets total shortfall" do it "correctly resets total shortfall" do
case_log.update!(wtshortfall: 100, hb: 9) case_log.update!(hbrentshortfall: 2, wtshortfall: 100, hb: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to be_nil expect(case_log.wtshortfall).to be_nil
expect(record_from_db["wtshortfall"]).to be_nil expect(record_from_db["wtshortfall"]).to be_nil
@ -344,7 +344,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0) expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0) expect(record_from_db["wtshortfall"]).to eq(50.0)
@ -353,7 +353,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0) expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0) expect(record_from_db["wtshortfall"]).to eq(50.0)
@ -362,7 +362,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0) expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0) expect(record_from_db["wtshortfall"]).to eq(50.0)
@ -425,7 +425,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -434,7 +434,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -443,7 +443,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -506,7 +506,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -515,7 +515,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -524,7 +524,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0) expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0) expect(record_from_db["wtshortfall"]).to eq(30.0)
@ -587,7 +587,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0) expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0) expect(record_from_db["wtshortfall"]).to eq(125.0)
@ -596,7 +596,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0) expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0) expect(record_from_db["wtshortfall"]).to eq(125.0)
@ -605,7 +605,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0) expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0) expect(record_from_db["wtshortfall"]).to eq(125.0)
@ -668,7 +668,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5) expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5) expect(record_from_db["wtshortfall"]).to eq(122.5)
@ -677,7 +677,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5) expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5) expect(record_from_db["wtshortfall"]).to eq(122.5)
@ -686,7 +686,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5) expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5) expect(record_from_db["wtshortfall"]).to eq(122.5)
@ -749,7 +749,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0) expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0) expect(record_from_db["wtshortfall"]).to eq(120.0)
@ -758,7 +758,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0) expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0) expect(record_from_db["wtshortfall"]).to eq(120.0)
@ -767,7 +767,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0) expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0) expect(record_from_db["wtshortfall"]).to eq(120.0)
@ -830,7 +830,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5) expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5) expect(record_from_db["wtshortfall"]).to eq(117.5)
@ -839,7 +839,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5) expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5) expect(record_from_db["wtshortfall"]).to eq(117.5)
@ -848,7 +848,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5) expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5) expect(record_from_db["wtshortfall"]).to eq(117.5)
@ -911,7 +911,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0) expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0) expect(record_from_db["wtshortfall"]).to eq(115.0)
@ -920,7 +920,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0) expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0) expect(record_from_db["wtshortfall"]).to eq(115.0)
@ -929,7 +929,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0) expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0) expect(record_from_db["wtshortfall"]).to eq(115.0)
@ -992,7 +992,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 1) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0) expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0) expect(record_from_db["wtshortfall"]).to eq(130.0)
@ -1001,7 +1001,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 6) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0) expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0) expect(record_from_db["wtshortfall"]).to eq(130.0)
@ -1010,7 +1010,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 8) case_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0) expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0) expect(record_from_db["wtshortfall"]).to eq(130.0)

14
spec/models/validations/financial_validations_spec.rb

@ -68,7 +68,7 @@ RSpec.describe Validations::FinancialValidations do
describe "outstanding rent amount validations" do describe "outstanding rent amount validations" do
context "when outstanding rent or charges is no" do context "when outstanding rent or charges is no" do
it "validates that no shortfall is provided" do it "validates that no shortfall is provided" do
record.hbrentshortfall = 1 record.hbrentshortfall = 2
record.tshortfall = 99 record.tshortfall = 99
financial_validator.validate_outstanding_rent_amount(record) financial_validator.validate_outstanding_rent_amount(record)
expect(record.errors["tshortfall"]) expect(record.errors["tshortfall"])
@ -78,7 +78,7 @@ RSpec.describe Validations::FinancialValidations do
context "when outstanding rent or charges is yes" do context "when outstanding rent or charges is yes" do
it "expects that a shortfall is provided" do it "expects that a shortfall is provided" do
record.hbrentshortfall = 0 record.hbrentshortfall = 1
record.tshortfall = 99 record.tshortfall = 99
financial_validator.validate_outstanding_rent_amount(record) financial_validator.validate_outstanding_rent_amount(record)
expect(record.errors["tshortfall"]).to be_empty expect(record.errors["tshortfall"]).to be_empty
@ -111,7 +111,7 @@ RSpec.describe Validations::FinancialValidations do
describe "housing benefit rent shortfall validations" do describe "housing benefit rent shortfall validations" do
context "when shortfall is yes" do context "when shortfall is yes" do
it "validates that housing benefit is not none" do it "validates that housing benefit is not none" do
record.hbrentshortfall = 0 record.hbrentshortfall = 1
record.hb = 9 record.hb = 9
financial_validator.validate_tshortfall(record) financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"]) expect(record.errors["tshortfall"])
@ -119,7 +119,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "validates that housing benefit is not don't know" do it "validates that housing benefit is not don't know" do
record.hbrentshortfall = 0 record.hbrentshortfall = 1
record.hb = 3 record.hb = 3
financial_validator.validate_tshortfall(record) financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"]) expect(record.errors["tshortfall"])
@ -127,7 +127,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "validates that housing benefit is not Universal Credit without housing benefit" do it "validates that housing benefit is not Universal Credit without housing benefit" do
record.hbrentshortfall = 0 record.hbrentshortfall = 1
record.hb = 7 record.hb = 7
financial_validator.validate_tshortfall(record) financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"]) expect(record.errors["tshortfall"])
@ -135,7 +135,7 @@ RSpec.describe Validations::FinancialValidations do
end end
it "validates that housing benefit is provided" do it "validates that housing benefit is provided" do
record.hbrentshortfall = 0 record.hbrentshortfall = 1
record.hb = 1 record.hb = 1
financial_validator.validate_tshortfall(record) financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"]).to be_empty expect(record.errors["tshortfall"]).to be_empty
@ -212,7 +212,7 @@ RSpec.describe Validations::FinancialValidations do
describe "rent and charges validations" do describe "rent and charges validations" do
context "when shortfall amount is provided" do context "when shortfall amount is provided" do
it "validates that basic rent is no less than double the shortfall" do it "validates that basic rent is no less than double the shortfall" do
record.hbrentshortfall = 1 record.hbrentshortfall = 2
record.tshortfall = 99.50 record.tshortfall = 99.50
record.brent = 198 record.brent = 198
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)

3
spec/services/imports/case_logs_import_service_spec.rb

@ -28,6 +28,9 @@ RSpec.describe Imports::CaseLogsImportService do
.and_return(open_file(fixture_directory, case_log_id2), open_file(fixture_directory, case_log_id2)) .and_return(open_file(fixture_directory, case_log_id2), open_file(fixture_directory, case_log_id2))
# Stub the form handler to use the real form # Stub the form handler to use the real form
allow(FormHandler.instance).to receive(:get_form).with(anything).and_return(real_2021_2022_form) allow(FormHandler.instance).to receive(:get_form).with(anything).and_return(real_2021_2022_form)
WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/LS166FT/)
.to_return(status: 200, body: '{"status":200,"result":{"codes":{"admin_district":"E08000035"}}}', headers: {})
end end
it "successfully create all case logs" do it "successfully create all case logs" do

Loading…
Cancel
Save