From 464e5f96278c6a9eb744be3cb473bc9627d4a9ef Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Fri, 25 Nov 2022 17:11:03 +0000 Subject: [PATCH] [CLDC-1514] Add buyer 2 income question (#1036) --- app/models/form/sales/pages/buyer2_income.rb | 19 +++++++ .../form/sales/questions/buyer2_income.rb | 14 +++++ .../sales/questions/buyer2_income_known.rb | 21 +++++++ .../income_benefits_and_savings.rb | 1 + .../20221125142847_add_buyer2_to_sales.rb | 6 ++ db/schema.rb | 4 +- spec/factories/sales_log.rb | 2 + .../form/sales/pages/buyer2_income_spec.rb | 33 +++++++++++ .../questions/buyer2_income_known_spec.rb | 55 +++++++++++++++++++ .../sales/questions/buyer2_income_spec.rb | 53 ++++++++++++++++++ .../income_benefits_and_savings_spec.rb | 1 + spec/models/form_handler_spec.rb | 4 +- 12 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 app/models/form/sales/pages/buyer2_income.rb create mode 100644 app/models/form/sales/questions/buyer2_income.rb create mode 100644 app/models/form/sales/questions/buyer2_income_known.rb create mode 100644 db/migrate/20221125142847_add_buyer2_to_sales.rb create mode 100644 spec/models/form/sales/pages/buyer2_income_spec.rb create mode 100644 spec/models/form/sales/questions/buyer2_income_known_spec.rb create mode 100644 spec/models/form/sales/questions/buyer2_income_spec.rb diff --git a/app/models/form/sales/pages/buyer2_income.rb b/app/models/form/sales/pages/buyer2_income.rb new file mode 100644 index 000000000..207b6ec46 --- /dev/null +++ b/app/models/form/sales/pages/buyer2_income.rb @@ -0,0 +1,19 @@ +class Form::Sales::Pages::Buyer2Income < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_2_income" + @header = "" + @description = "" + @subsection = subsection + @depends_on = [{ + "jointpur" => 1, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::Buyer2IncomeKnown.new(nil, nil, self), + Form::Sales::Questions::Buyer2Income.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer2_income.rb b/app/models/form/sales/questions/buyer2_income.rb new file mode 100644 index 000000000..4abb306a0 --- /dev/null +++ b/app/models/form/sales/questions/buyer2_income.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::Buyer2Income < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income2" + @check_answer_label = "Buyer 2’s gross annual income" + @header = "Buyer 2’s gross annual income" + @type = "numeric" + @page = page + @min = 0 + @step = 1 + @width = 5 + @prefix = "£" + end +end diff --git a/app/models/form/sales/questions/buyer2_income_known.rb b/app/models/form/sales/questions/buyer2_income_known.rb new file mode 100644 index 000000000..f0897f6be --- /dev/null +++ b/app/models/form/sales/questions/buyer2_income_known.rb @@ -0,0 +1,21 @@ +class Form::Sales::Questions::Buyer2IncomeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income2nk" + @check_answer_label = "Buyer 2’s gross annual income" + @header = "Do you know buyer 2’s annual income?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @guidance_position = GuidancePosition::BOTTOM + @guidance_partial = "what_counts_as_income_sales" + @conditional_for = { + "income2" => [0], + } + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index a9e7080db..26ab3310b 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -11,6 +11,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection @pages ||= [ Form::Sales::Pages::Buyer1Income.new(nil, nil, self), Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self), + Form::Sales::Pages::Buyer2Income.new(nil, nil, self), ] end end diff --git a/db/migrate/20221125142847_add_buyer2_to_sales.rb b/db/migrate/20221125142847_add_buyer2_to_sales.rb new file mode 100644 index 000000000..883ad44dd --- /dev/null +++ b/db/migrate/20221125142847_add_buyer2_to_sales.rb @@ -0,0 +1,6 @@ +class AddBuyer2ToSales < ActiveRecord::Migration[7.0] + change_table :sales_logs, bulk: true do |t| + t.column :income2, :int + t.column :income2nk, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index 4ceb57dbc..e5a4d27e4 100644 --- a/db/schema.rb +++ b/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_24_102329) do +ActiveRecord::Schema[7.0].define(version: 2022_11_25_142847) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -384,6 +384,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_24_102329) do t.integer "age6" t.integer "age6_known" t.integer "inc1mort" + t.integer "income2" + t.integer "income2nk" 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" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index e6c45a009..e55287d67 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -53,6 +53,8 @@ FactoryBot.define do income1nk { 0 } income1 { 10_000 } inc1mort { 1 } + income2nk { 0 } + income2 { 10_000 } la_known { "1" } la { "E09000003" } end diff --git a/spec/models/form/sales/pages/buyer2_income_spec.rb b/spec/models/form/sales/pages/buyer2_income_spec.rb new file mode 100644 index 000000000..0450ceed1 --- /dev/null +++ b/spec/models/form/sales/pages/buyer2_income_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer2Income, 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[income2nk income2]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_2_income") + 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([{ "jointpur" => 1 }]) + end +end diff --git a/spec/models/form/sales/questions/buyer2_income_known_spec.rb b/spec/models/form/sales/questions/buyer2_income_known_spec.rb new file mode 100644 index 000000000..06e7afc3e --- /dev/null +++ b/spec/models/form/sales/questions/buyer2_income_known_spec.rb @@ -0,0 +1,55 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer2IncomeKnown, 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("income2nk") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know buyer 2’s annual income?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 2’s gross annual income") + 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({ + "income2" => [0], + }) + end + + it "has the correct guidance_partial" do + expect(question.guidance_partial).to eq("what_counts_as_income_sales") + end + + it "has the correct guidance position", :aggregate_failures do + expect(question.bottom_guidance?).to eq(true) + expect(question.top_guidance?).to eq(false) + end +end diff --git a/spec/models/form/sales/questions/buyer2_income_spec.rb b/spec/models/form/sales/questions/buyer2_income_spec.rb new file mode 100644 index 000000000..b7828918a --- /dev/null +++ b/spec/models/form/sales/questions/buyer2_income_spec.rb @@ -0,0 +1,53 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer2Income, 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("income2") + end + + it "has the correct header" do + expect(question.header).to eq("Buyer 2’s gross annual income") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 2’s gross annual income") + end + + it "has the correct type" do + expect(question.type).to eq("numeric") + 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 + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct step" do + expect(question.step).to eq(1) + end + + it "has correct prefix" do + expect(question.prefix).to eq("£") + end + + it "has correct min" do + expect(question.min).to eq(0) + end +end diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index 0ebbac6ab..bea0fe88d 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model %w[ buyer_1_income buyer_1_mortgage + buyer_2_income ], ) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 7db258b53..6a335e232 100644 --- a/spec/models/form_handler_spec.rb +++ b/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(45) + expect(form.pages.count).to eq(46) 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(45) + expect(form.pages.count).to eq(46) expect(form.name).to eq("2021_2022_sales") end end