Browse Source

Switch lettings ppcodenk

pull/1854/head
Jack S 3 years ago committed by Kat
parent
commit
e64eb1dbcb
  1. 5
      app/models/form/lettings/questions/ppcodenk.rb
  2. 7
      app/models/form/lettings/questions/ppostcode_full.rb
  3. 32
      app/models/form/question.rb
  4. 4
      app/models/lettings_log.rb
  5. 7
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  6. 4
      app/services/imports/lettings_logs_import_service.rb
  7. 2
      spec/factories/lettings_log.rb
  8. 50
      spec/models/form/question_spec.rb
  9. 8
      spec/models/lettings_log_spec.rb
  10. 40
      spec/models/validations/local_authority_validations_spec.rb
  11. 4
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  12. 4
      spec/services/bulk_upload/processor_spec.rb

5
app/models/form/lettings/questions/ppcodenk.rb

@ -14,5 +14,8 @@ class Form::Lettings::Questions::Ppcodenk < ::Form::Question
@disable_clearing_if_not_routed_or_dynamic_answer_options = true
end
ANSWER_OPTIONS = { "1" => { "value" => "Yes" }, "0" => { "value" => "No" } }.freeze
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

7
app/models/form/lettings/questions/ppostcode_full.rb

@ -6,7 +6,12 @@ class Form::Lettings::Questions::PpostcodeFull < ::Form::Question
@header = "Postcode for the previous accommodation"
@type = "text"
@width = 5
@inferred_check_answers_value = [{ "condition" => { "ppcodenk" => 0 }, "value" => "Not known" }]
@inferred_check_answers_value = [{
"condition" => {
"ppcodenk" => 1,
},
"value" => "Not known",
}]
@check_answers_card_number = 0
@hint_text = ""
@inferred_answers = { "prevloc" => { "is_previous_la_inferred" => true } }

32
app/models/form/question.rb

@ -116,20 +116,20 @@ class Form::Question
if is_derived_or_has_inferred_check_answers_value?(log)
"Change"
elsif type == "checkbox"
answer_options.keys.any? { |key| value_is_yes?(log[key], log.lettings?) } ? "Change" : "Answer"
answer_options.keys.any? { |key| value_is_yes?(log[key]) } ? "Change" : "Answer"
else
log[id].blank? ? "Answer" : "Change"
end
end
def unanswered?(log)
return answer_options.keys.none? { |key| value_is_yes?(log[key], log.lettings?) } if type == "checkbox"
return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox"
log[id].blank?
end
def completed?(log)
return answer_options.keys.any? { |key| value_is_yes?(log[key], log.lettings?) } if type == "checkbox"
return answer_options.keys.any? { |key| value_is_yes?(log[key]) } if type == "checkbox"
log[id].present? || !log.respond_to?(id.to_sym) || has_inferred_display_value?(log)
end
@ -166,28 +166,17 @@ class Form::Question
label || value.to_s
end
def value_is_yes?(value, is_lettings)
def value_is_yes?(value)
case type
when "checkbox"
value == 1
when "radio"
is_lettings ? RADIO_YES_VALUE_LETTINGS[id.to_sym]&.include?(value) : RADIO_YES_VALUE_SALES[id.to_sym]&.include?(value)
RADIO_YES_VALUE[id.to_sym]&.include?(value)
else
%w[yes].include?(value.downcase)
end
end
def value_is_no?(value, is_lettings)
case type
when "checkbox"
value && value.zero?
when "radio"
is_lettings ? RADIO_NO_VALUE_LETTINGS[id.to_sym]&.include?(value) : RADIO_NO_VALUE_SALES[id.to_sym]&.include?(value)
else
%w[no].include?(value.downcase)
end
end
def value_is_dont_know?(value)
type == "radio" && RADIO_DONT_KNOW_VALUE[id.to_sym]&.include?(value)
end
@ -272,9 +261,9 @@ private
def checkbox_answer_label(log)
answer = []
return "Yes" if id == "declaration" && value_is_yes?(log["declaration"], log.lettings?)
return "Yes" if id == "declaration" && value_is_yes?(log["declaration"])
answer_options.each { |key, options| value_is_yes?(log[key], log.lettings?) ? answer << options["value"] : nil }
answer_options.each { |key, options| value_is_yes?(log[key]) ? answer << options["value"] : nil }
answer.join(", ")
end
@ -338,6 +327,7 @@ private
is_carehome: [1],
hbrentshortfall: [1],
net_income_value_check: [0],
ppcodenk: [0],
}.freeze
RADIO_NO_VALUE = {
@ -362,13 +352,9 @@ private
is_carehome: [0],
hbrentshortfall: [2],
net_income_value_check: [1],
ppcodenk: [1],
}.freeze
RADIO_YES_VALUE_LETTINGS = RADIO_YES_VALUE.merge({ ppcodenk: [1] })
RADIO_YES_VALUE_SALES = RADIO_YES_VALUE.merge({ ppcodenk: [0] })
RADIO_NO_VALUE_LETTINGS = RADIO_NO_VALUE.merge({ ppcodenk: [0] })
RADIO_NO_VALUE_SALES = RADIO_NO_VALUE.merge({ ppcodenk: [1] })
RADIO_DONT_KNOW_VALUE = {
sheltered: [3],
underoccupation_benefitcap: [3],

4
app/models/lettings_log.rb

@ -260,8 +260,8 @@ class LettingsLog < Log
end
def previous_postcode_known?
# 1: Yes
ppcodenk == 1
# 0: Yes
postcode_known&.zero?
end
def previous_la_known?

7
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -1283,12 +1283,7 @@ private
end
def ppcodenk
case field_65
when 1
1
when 2
0
end
field_65 == 1 ? 0 : 1
end
def earnings

4
app/services/imports/lettings_logs_import_service.rb

@ -465,11 +465,11 @@ module Imports
def previous_postcode_known(xml_doc, previous_postcode, prevloc)
previous_postcode_known = string_or_nil(xml_doc, "Q12bnot")
if previous_postcode_known == "Temporary_or_Unknown" || (previous_postcode.nil? && prevloc.present?)
0 # not known
1 # not known
elsif previous_postcode.nil?
nil
else
1 # known
0 # known
end
end

2
spec/factories/lettings_log.rb

@ -166,7 +166,7 @@ FactoryBot.define do
joint { 3 }
address_line1 { "fake address" }
town_or_city { "London" }
ppcodenk { 0 }
ppcodenk { 1 }
tshortfall_known { 1 }
end
trait :export do

50
spec/models/form/question_spec.rb

@ -60,37 +60,9 @@ RSpec.describe Form::Question, type: :model do
end
it "has a yes value helper" do
expect(question).to be_value_is_yes("Yes", true)
expect(question).to be_value_is_yes("YES", true)
expect(question).not_to be_value_is_yes("random", true)
end
it "has a no value helper" do
expect(question).to be_value_is_no("No", true)
expect(question).to be_value_is_no("NO", true)
expect(question).not_to be_value_is_no("random", true)
end
context "when there are different value helper values for lettings and sales" do
context "with a lettings log" do
let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) }
let(:question) { Form::Lettings::Questions::Ppcodenk.new(nil, nil, Form::Lettings::Pages::PreviousPostcode.new("previous_postcode", nil, Form::Lettings::Subsections::HouseholdSituation.new(nil, nil, Form::Lettings::Sections::Household))) }
it "has the correct values" do
expect(question.value_is_yes?(1, lettings_log.lettings?)).to be true
expect(question.value_is_no?(0, lettings_log.lettings?)).to be true
end
end
context "with a sales log" do
let(:sales_log) { FactoryBot.build(:sales_log, :in_progress) }
let(:question) { Form::Sales::Questions::PreviousPostcodeKnown.new(nil, nil, Form::Sales::Pages::LastAccommodation.new("previous_postcode", nil, Form::Sales::Subsections::HouseholdSituation.new(nil, nil, Form::Sales::Sections::Household))) }
it "has the correct values" do
expect(question.value_is_yes?(0, sales_log.lettings?)).to be true
expect(question.value_is_no?(1, sales_log.lettings?)).to be true
end
end
expect(question).to be_value_is_yes("Yes")
expect(question).to be_value_is_yes("YES")
expect(question).not_to be_value_is_yes("random")
end
context "when type is numeric" do
@ -130,10 +102,8 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "illness" }
it "maps those options" do
expect(question).to be_value_is_yes(1, true)
expect(question).not_to be_value_is_no(1, true)
expect(question).to be_value_is_yes(1)
expect(question).not_to be_value_is_refused(1)
expect(question).to be_value_is_no(2, true)
expect(question).to be_value_is_dont_know(3)
end
end
@ -145,8 +115,7 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "layear" }
it "maps those options" do
expect(question).not_to be_value_is_yes(7, true)
expect(question).not_to be_value_is_no(7, true)
expect(question).not_to be_value_is_yes(7)
expect(question).not_to be_value_is_refused(7)
expect(question).to be_value_is_dont_know(7)
end
@ -231,13 +200,8 @@ RSpec.describe Form::Question, type: :model do
end
it "can map yes values" do
expect(question).to be_value_is_yes(1, true)
expect(question).not_to be_value_is_yes(0, true)
end
it "can map no values" do
expect(question).to be_value_is_no(0, true)
expect(question).not_to be_value_is_no(1, true)
expect(question).to be_value_is_yes(1)
expect(question).not_to be_value_is_yes(0)
end
end

8
spec/models/lettings_log_spec.rb

@ -1329,7 +1329,7 @@ RSpec.describe LettingsLog do
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
ppcodenk: 1,
ppcodenk: 0,
ppostcode_full: "M1 1AE",
})
end
@ -1369,7 +1369,7 @@ RSpec.describe LettingsLog do
end
it "correctly resets all fields if previous postcode not known" do
address_lettings_log.update!({ ppcodenk: 0 })
address_lettings_log.update!({ ppcodenk: 1 })
record_from_db = described_class.find(address_lettings_log.id)
expect(record_from_db["ppostcode_full"]).to eq(nil)
@ -1378,7 +1378,7 @@ RSpec.describe LettingsLog do
end
it "correctly resets la if la is not known" do
address_lettings_log.update!({ ppcodenk: 0 })
address_lettings_log.update!({ ppcodenk: 1 })
address_lettings_log.update!({ previous_la_known: 1, prevloc: "S92000003" })
record_from_db = described_class.find(address_lettings_log.id)
expect(record_from_db["prevloc"]).to eq("S92000003")
@ -1391,7 +1391,7 @@ RSpec.describe LettingsLog do
end
it "changes the prevloc if previous postcode changes from not known to known and provided" do
address_lettings_log.update!({ ppcodenk: 0 })
address_lettings_log.update!({ ppcodenk: 1 })
address_lettings_log.update!({ previous_la_known: 1, prevloc: "E09000033" })
record_from_db = described_class.find(address_lettings_log.id)

40
spec/models/validations/local_authority_validations_spec.rb

@ -4,35 +4,35 @@ RSpec.describe Validations::LocalAuthorityValidations do
subject(:local_auth_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::LocalAuthorityValidations } }
let(:record) { FactoryBot.create(:lettings_log) }
let(:log) { create(:lettings_log) }
describe "#validate_previous_accommodation_postcode" do
it "does not add an error if the record ppostcode_full is missing" do
record.ppostcode_full = nil
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
it "does not add an error if the log ppostcode_full is missing" do
log.ppostcode_full = nil
local_auth_validator.validate_previous_accommodation_postcode(log)
expect(log.errors).to be_empty
end
it "does not add an error if the record ppostcode_full is valid (uppercase space)" do
record.ppcodenk = 1
record.ppostcode_full = "M1 1AE"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
it "does not add an error if the log ppostcode_full is valid (uppercase space)" do
log.ppcodenk = 0
log.ppostcode_full = "M1 1AE"
local_auth_validator.validate_previous_accommodation_postcode(log)
expect(log.errors).to be_empty
end
it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do
record.ppcodenk = 1
record.ppostcode_full = "m11ae"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
it "does not add an error if the log ppostcode_full is valid (lowercase no space)" do
log.ppcodenk = 0
log.ppostcode_full = "m11ae"
local_auth_validator.validate_previous_accommodation_postcode(log)
expect(log.errors).to be_empty
end
it "does add an error when the postcode is invalid" do
record.ppcodenk = 1
record.ppostcode_full = "invalid"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).not_to be_empty
expect(record.errors["ppostcode_full"]).to include(match I18n.t("validations.postcode"))
log.ppcodenk = 0
log.ppostcode_full = "invalid"
local_auth_validator.validate_previous_accommodation_postcode(log)
expect(log.errors).not_to be_empty
expect(log.errors["ppostcode_full"]).to include(match I18n.t("validations.postcode"))
end
end
end

4
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -67,7 +67,7 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
waityear: 9,
joint: 2,
tenancy: 9,
ppcodenk: 0,
ppcodenk: 1,
)
end
@ -153,7 +153,7 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
waityear: 9,
joint: 2,
tenancy: 9,
ppcodenk: 0,
ppcodenk: 1,
)
end

4
spec/services/bulk_upload/processor_spec.rb

@ -176,7 +176,7 @@ RSpec.describe BulkUpload::Processor do
waityear: 9,
joint: 2,
tenancy: 9,
ppcodenk: 0,
ppcodenk: 1,
voiddate: nil,
mrcdate: nil,
startdate: Date.new(2022, 10, 1),
@ -385,7 +385,7 @@ RSpec.describe BulkUpload::Processor do
waityear: 9,
joint: 2,
tenancy: 2,
ppcodenk: 0,
ppcodenk: 1,
voiddate: Date.new(2022, 1, 1),
reason: 40,
leftreg: 3,

Loading…
Cancel
Save