Browse Source

[CLDC-1513] Add buyer 1 mortgage question (#1025)

* Rename section from outgoings to savings

* Fix specs

* Add inc1mort column
pull/1033/head
Jack S 2 years ago committed by GitHub
parent
commit
8de3570e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/models/form/sales/pages/buyer1_mortgage.rb
  2. 16
      app/models/form/sales/questions/buyer1_mortgage.rb
  3. 2
      app/models/form/sales/sections/finances.rb
  4. 7
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 7
      db/migrate/20221124102329_add_mortgage1_to_sales.rb
  6. 3
      db/schema.rb
  7. 1
      spec/factories/sales_log.rb
  8. 33
      spec/models/form/sales/pages/buyer1_mortgage_spec.rb
  9. 40
      spec/models/form/sales/questions/buyer1_mortgage_spec.rb
  10. 2
      spec/models/form/sales/sections/finances_spec.rb
  11. 7
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  12. 4
      spec/models/form_handler_spec.rb

15
app/models/form/sales/pages/buyer1_mortgage.rb

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

16
app/models/form/sales/questions/buyer1_mortgage.rb

@ -0,0 +1,16 @@
class Form::Sales::Questions::Buyer1Mortgage < ::Form::Question
def initialize(id, hsh, page)
super
@id = "inc1mort"
@check_answer_label = "Buyer 1's income used for mortgage application"
@header = "Was buyer 1's income used for a mortgage application"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

2
app/models/form/sales/sections/finances.rb

@ -6,7 +6,7 @@ class Form::Sales::Sections::Finances < ::Form::Section
@description = ""
@form = form
@subsections = [
Form::Sales::Subsections::IncomeBenefitsAndOutgoings.new(nil, nil, self),
Form::Sales::Subsections::IncomeBenefitsAndSavings.new(nil, nil, self),
]
end
end

7
app/models/form/sales/subsections/income_benefits_and_outgoings.rb → app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -1,8 +1,8 @@
class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection
class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "income_benefits_and_outgoings"
@label = "Income, benefits and outgoings"
@id = "income_benefits_and_savings"
@label = "Income, benefits and savings"
@section = section
@depends_on = [{ "setup_completed?" => true }]
end
@ -10,6 +10,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self),
]
end
end

7
db/migrate/20221124102329_add_mortgage1_to_sales.rb

@ -0,0 +1,7 @@
class AddMortgage1ToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :inc1mort, :int
end
end
end

3
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: 2022_11_22_130928) do
ActiveRecord::Schema[7.0].define(version: 2022_11_24_102329) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -383,6 +383,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "age5_known"
t.integer "age6"
t.integer "age6_known"
t.integer "inc1mort"
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 ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

1
spec/factories/sales_log.rb

@ -52,6 +52,7 @@ FactoryBot.define do
age6 { 40 }
income1nk { 0 }
income1 { 10_000 }
inc1mort { 1 }
la_known { "1" }
la { "E09000003" }
end

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

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1Mortgage, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
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[inc1mort])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_mortgage")
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

40
spec/models/form/sales/questions/buyer1_mortgage_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1Mortgage, 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("inc1mort")
end
it "has the correct header" do
expect(question.header).to eq("Was buyer 1's income used for a mortgage application")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's income used for mortgage application")
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({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
end

2
spec/models/form/sales/sections/finances_spec.rb

@ -14,7 +14,7 @@ RSpec.describe Form::Sales::Sections::Finances, type: :model do
it "has correct subsections" do
expect(section.subsections.map(&:id)).to eq(
%w[
income_benefits_and_outgoings
income_benefits_and_savings
],
)
end

7
spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb → spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -1,6 +1,6 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :model do
RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model do
subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
@ -15,16 +15,17 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :mode
expect(subsection.pages.map(&:id)).to eq(
%w[
buyer_1_income
buyer_1_mortgage
],
)
end
it "has the correct id" do
expect(subsection.id).to eq("income_benefits_and_outgoings")
expect(subsection.id).to eq("income_benefits_and_savings")
end
it "has the correct label" do
expect(subsection.label).to eq("Income, benefits and outgoings")
expect(subsection.label).to eq("Income, benefits and savings")
end
it "has correct depends on" do

4
spec/models/form_handler_spec.rb

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

Loading…
Cancel
Save