Browse Source

CLDC-1749 Add mortgage lender question (#1164)

* Add mortgage lender fields to the sales table

* Add mortgage lender page and question

* Add mortgage lender other question

* Add guidance for motrgage

* Update mortgage lender other question
pull/1175/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
802754c612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/models/form/sales/pages/mortgage_lender.rb
  2. 17
      app/models/form/sales/pages/mortgage_lender_other.rb
  3. 58
      app/models/form/sales/questions/mortgage_lender.rb
  4. 10
      app/models/form/sales/questions/mortgage_lender_other.rb
  5. 2
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  6. 2
      app/models/form/sales/subsections/outright_sale.rb
  7. 2
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  8. 7
      app/views/form/guidance/_mortgage_lender.html.erb
  9. 8
      db/migrate/20230109144039_add_mortgage_lender.rb
  10. 2
      db/schema.rb
  11. 1
      spec/factories/sales_log.rb
  12. 35
      spec/models/form/sales/pages/mortgage_lender_other_spec.rb
  13. 33
      spec/models/form/sales/pages/mortgage_lender_spec.rb
  14. 37
      spec/models/form/sales/questions/mortgage_lender_other_spec.rb
  15. 88
      spec/models/form/sales/questions/mortgage_lender_spec.rb
  16. 2
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  17. 2
      spec/models/form/sales/subsections/outright_sale_spec.rb
  18. 2
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  19. 4
      spec/models/form_handler_spec.rb

14
app/models/form/sales/pages/mortgage_lender.rb

@ -0,0 +1,14 @@
class Form::Sales::Pages::MortgageLender < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::MortgageLender.new(nil, nil, self),
]
end
end

17
app/models/form/sales/pages/mortgage_lender_other.rb

@ -0,0 +1,17 @@
class Form::Sales::Pages::MortgageLenderOther < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"mortgagelender" => 40,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::MortgageLenderOther.new(nil, nil, self),
]
end
end

58
app/models/form/sales/questions/mortgage_lender.rb

@ -0,0 +1,58 @@
class Form::Sales::Questions::MortgageLender < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mortgagelender"
@check_answer_label = "Mortgage Lender"
@header = "What is the name of the mortgage lender?"
@type = "select"
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
@guidance_position = GuidancePosition::BOTTOM
@guidance_partial = "mortgage_lender"
end
ANSWER_OPTIONS = {
"" => "Select an option",
"1" => "Atom Bank",
"2" => "Barclays Bank PLC",
"3" => "Bath Building Society",
"4" => "Buckinghamshire Building Society",
"5" => "Cambridge Building Society",
"6" => "Coventry Building Society",
"7" => "Cumberland Building Society",
"8" => "Darlington Building Society",
"9" => "Dudley Building Society",
"10" => "Ecology Building Society",
"11" => "Halifax",
"12" => "Hanley Economic Building Society",
"13" => "Hinckley and Rugby Building Society",
"14" => "Holmesdale Building Society",
"15" => "Ipswich Building Society",
"16" => "Leeds Building Society",
"17" => "Lloyds Bank",
"18" => "Mansfield Building Society",
"19" => "Market Harborough Building Society",
"20" => "Melton Mowbray Building Society",
"21" => "Nationwide Building Society",
"22" => "Natwest",
"23" => "Nedbank Private Wealth",
"24" => "Newbury Building Society",
"25" => "OneSavings Bank",
"26" => "Parity Trust",
"27" => "Penrith Building Society",
"28" => "Pepper Homeloans",
"29" => "Royal Bank of Scotland",
"30" => "Santander",
"31" => "Skipton Building Society",
"32" => "Teachers Building Society",
"33" => "The Co-operative Bank",
"34" => "Tipton & Coseley Building Society",
"35" => "TSB",
"36" => "Ulster Bank",
"37" => "Virgin Money",
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"40" => "Other",
}.freeze
end

10
app/models/form/sales/questions/mortgage_lender_other.rb

@ -0,0 +1,10 @@
class Form::Sales::Questions::MortgageLenderOther < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mortgagelenderother"
@check_answer_label = "Other Mortgage Lender"
@header = "What is the other mortgage lender?"
@type = "text"
@page = page
end
end

2
app/models/form/sales/subsections/discounted_ownership_scheme.rb

@ -13,6 +13,8 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),

2
app/models/form/sales/subsections/outright_sale.rb

@ -11,6 +11,8 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
Form::Sales::Pages::PurchasePrice.new(nil, nil, self), Form::Sales::Pages::PurchasePrice.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_outright_sale", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self),

2
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -22,6 +22,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self), Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self), Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),

7
app/views/form/guidance/_mortgage_lender.html.erb

@ -0,0 +1,7 @@
<%= govuk_details(summary_text: "Can’t find the mortgage lender you’re looking for?") do %>
<ul class="govuk-list govuk-list--bullet">
<li>Double check the spelling and try again</li>
<li>Type the first few letters to see the suggestions</li>
<li>Type Other and continue - we’ll ask you to type in your answer in the next question</li>
</ul>
<% end %>

8
db/migrate/20230109144039_add_mortgage_lender.rb

@ -0,0 +1,8 @@
class AddMortgageLender < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :mortgagelender, :integer
t.column :mortgagelenderother, :string
end
end
end

2
db/schema.rb

@ -491,6 +491,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_13_125117) do
t.integer "pcodenk" t.integer "pcodenk"
t.string "postcode_full" t.string "postcode_full"
t.boolean "is_la_inferred" t.boolean "is_la_inferred"
t.integer "mortgagelender"
t.string "mortgagelenderother"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

1
spec/factories/sales_log.rb

@ -98,6 +98,7 @@ FactoryBot.define do
mortlen { 10 } mortlen { 10 }
pcodenk { 1 } pcodenk { 1 }
is_la_inferred { false } is_la_inferred { false }
mortgagelender { 5 }
end end
end end
end end

35
spec/models/form/sales/pages/mortgage_lender_other_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MortgageLenderOther, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "mortgage_lender_other" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[mortgagelenderother])
end
it "has the correct id" do
expect(page.id).to eq("mortgage_lender_other")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"mortgagelender" => 40,
}])
end
end

33
spec/models/form/sales/pages/mortgage_lender_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MortgageLender, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "mortgage_lender" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[mortgagelender])
end
it "has the correct id" do
expect(page.id).to eq("mortgage_lender")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

37
spec/models/form/sales/questions/mortgage_lender_other_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MortgageLenderOther, 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("mortgagelenderother")
end
it "has the correct header" do
expect(question.header).to eq("What is the other mortgage lender?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Other Mortgage Lender")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
end

88
spec/models/form/sales/questions/mortgage_lender_spec.rb

@ -0,0 +1,88 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MortgageLender, 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("mortgagelender")
end
it "has the correct header" do
expect(question.header).to eq("What is the name of the mortgage lender?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Mortgage Lender")
end
it "has the correct type" do
expect(question.type).to eq("select")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "is has correct guidance_position" do
expect(question.top_guidance?).to be false
expect(question.bottom_guidance?).to be true
end
it "is has correct guidance_partial" do
expect(question.guidance_partial).to eq("mortgage_lender")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"" => "Select an option",
"1" => "Atom Bank",
"2" => "Barclays Bank PLC",
"3" => "Bath Building Society",
"4" => "Buckinghamshire Building Society",
"5" => "Cambridge Building Society",
"6" => "Coventry Building Society",
"7" => "Cumberland Building Society",
"8" => "Darlington Building Society",
"9" => "Dudley Building Society",
"10" => "Ecology Building Society",
"11" => "Halifax",
"12" => "Hanley Economic Building Society",
"13" => "Hinckley and Rugby Building Society",
"14" => "Holmesdale Building Society",
"15" => "Ipswich Building Society",
"16" => "Leeds Building Society",
"17" => "Lloyds Bank",
"18" => "Mansfield Building Society",
"19" => "Market Harborough Building Society",
"20" => "Melton Mowbray Building Society",
"21" => "Nationwide Building Society",
"22" => "Natwest",
"23" => "Nedbank Private Wealth",
"24" => "Newbury Building Society",
"25" => "OneSavings Bank",
"26" => "Parity Trust",
"27" => "Penrith Building Society",
"28" => "Pepper Homeloans",
"29" => "Royal Bank of Scotland",
"30" => "Santander",
"31" => "Skipton Building Society",
"32" => "Teachers Building Society",
"33" => "The Co-operative Bank",
"34" => "Tipton & Coseley Building Society",
"35" => "TSB",
"36" => "Ulster Bank",
"37" => "Virgin Money",
"38" => "West Bromwich Building Society",
"39" => "Yorkshire Building Society",
"40" => "Other",
})
end
end

2
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -19,6 +19,8 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
about_price_not_rtb about_price_not_rtb
mortgage_used_discounted_ownership mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership mortgage_amount_discounted_ownership
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
mortgage_length_discounted_ownership mortgage_length_discounted_ownership
about_deposit_discounted_ownership about_deposit_discounted_ownership
discounted_ownership_deposit_value_check discounted_ownership_deposit_value_check

2
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -17,6 +17,8 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
purchase_price purchase_price
mortgage_used_outright_sale mortgage_used_outright_sale
mortgage_amount_outright_sale mortgage_amount_outright_sale
mortgage_lender_outright_sale
mortgage_lender_other_outright_sale
mortgage_length_outright_sale mortgage_length_outright_sale
about_deposit_outright_sale about_deposit_outright_sale
outright_sale_deposit_value_check outright_sale_deposit_value_check

2
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -28,6 +28,8 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_price_shared_ownership about_price_shared_ownership
mortgage_used_shared_ownership mortgage_used_shared_ownership
mortgage_amount_shared_ownership mortgage_amount_shared_ownership
mortgage_lender_shared_ownership
mortgage_lender_other_shared_ownership
mortgage_length_shared_ownership mortgage_length_shared_ownership
about_deposit_with_discount about_deposit_with_discount
about_deposit_shared_ownership about_deposit_shared_ownership

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(138) expect(form.pages.count).to eq(144)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(138) expect(form.pages.count).to eq(144)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

Loading…
Cancel
Save