Browse Source

Add mortgage length known question

pull/1356/head
Kat 3 years ago
parent
commit
8caef8680d
  1. 1
      app/models/form/sales/pages/mortgage_length.rb
  2. 4
      app/models/form/sales/questions/mortgage_length.rb
  3. 28
      app/models/form/sales/questions/mortgage_length_known.rb
  4. 2
      app/services/imports/sales_logs_import_service.rb
  5. 5
      db/migrate/20230228112317_add_mortgage_length_known.rb
  6. 7
      db/schema.rb
  7. 1
      spec/factories/sales_log.rb
  8. 2
      spec/models/form/sales/pages/mortgage_length_spec.rb
  9. 55
      spec/models/form/sales/questions/mortgage_length_known_spec.rb
  10. 9
      spec/models/form/sales/questions/mortgage_length_spec.rb

1
app/models/form/sales/pages/mortgage_length.rb

@ -8,6 +8,7 @@ class Form::Sales::Pages::MortgageLength < ::Form::Page
def questions
@questions ||= [
Form::Sales::Questions::MortgageLengthKnown.new(nil, nil, self),
Form::Sales::Questions::MortgageLength.new(nil, nil, self),
]
end

4
app/models/form/sales/questions/mortgage_length.rb

@ -10,5 +10,9 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question
@width = 5
@suffix = " years"
@hint_text = "You should round up to the nearest year. Value should not exceed 60 years."
@inferred_check_answers_value = [{
"condition" => { "mortlen_known" => 1 },
"value" => "Not known",
}]
end
end

28
app/models/form/sales/questions/mortgage_length_known.rb

@ -0,0 +1,28 @@
class Form::Sales::Questions::MortgageLengthKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mortlen_known"
@check_answer_label = "Mortgage length known"
@header = "Do you know the mortgage length?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"mortlen" => [0],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"mortlen_known" => 0,
},
{
"mortlen_known" => 1,
},
],
}
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

2
app/services/imports/sales_logs_import_service.rb

@ -118,6 +118,7 @@ module Imports
attributes["mortgagelender"] = mortgage_lender(xml_doc, attributes)
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["mortlen"] = mortgage_length(xml_doc, attributes)
attributes["mortlen_known"] = 0 if attributes["mortlen"].present?
attributes["extrabor"] = borrowing(xml_doc, attributes)
attributes["totadult"] = safe_string_as_integer(xml_doc, "TOTADULT") # would get overridden
attributes["totchild"] = safe_string_as_integer(xml_doc, "TOTCHILD") # would get overridden
@ -404,6 +405,7 @@ module Imports
attributes["hb"] ||= 4
attributes["prevown"] ||= 3
attributes["savingsnk"] ||= attributes["savings"].present? ? 0 : 1
attributes["mortlen_known"] ||= 1 if attributes["mortgage"].blank?
# attributes["noint"] = 1 # not interviewed
# buyer 1 characteristics

5
db/migrate/20230228112317_add_mortgage_length_known.rb

@ -0,0 +1,5 @@
class AddMortgageLengthKnown < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :mortlen_known, :integer
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_02_15_112932) do
ActiveRecord::Schema[7.0].define(version: 2023_02_28_112317) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -490,7 +490,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_15_112932) do
t.integer "prevten"
t.integer "mortgageused"
t.integer "wchair"
t.integer "income2_value_check"
t.integer "armedforcesspouse"
t.datetime "hodate", precision: nil
t.integer "hoday"
@ -527,10 +526,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_15_112932) do
t.integer "details_known_6"
t.integer "ethnic_group2"
t.integer "ethnicbuy2"
t.integer "proplen_asked"
t.integer "prevshared"
t.integer "staircasesale"
t.string "old_id"
t.integer "income2_value_check"
t.integer "proplen_asked"
t.integer "mortlen_known"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true

1
spec/factories/sales_log.rb

@ -95,6 +95,7 @@ FactoryBot.define do
armedforcesspouse { 5 }
mscharge_known { 1 }
mscharge { 100 }
mortlen_known { 0 }
mortlen { 10 }
pcodenk { 1 }
is_la_inferred { false }

2
spec/models/form/sales/pages/mortgage_length_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Form::Sales::Pages::MortgageLength, type: :model do
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[mortlen])
expect(page.questions.map(&:id)).to eq(%w[mortlen_known mortlen])
end
it "has the correct id" do

55
spec/models/form/sales/questions/mortgage_length_known_spec.rb

@ -0,0 +1,55 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MortgageLengthKnown, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("mortlen_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the mortgage length?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Mortgage length known")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"mortlen" => [0],
})
end
it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [{
"mortlen_known" => 0,
},
{ "mortlen_known" => 1 }],
})
end
end

9
spec/models/form/sales/questions/mortgage_length_spec.rb

@ -52,4 +52,13 @@ RSpec.describe Form::Sales::Questions::MortgageLength, type: :model do
it "has correct max" do
expect(question.max).to eq(60)
end
it "has correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([
{
"condition" => { "mortlen_known" => 1 },
"value" => "Not known",
},
])
end
end

Loading…
Cancel
Save