From fd85f2a19e8388fab7729695591ec016d0f115d6 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Mon, 17 Oct 2022 10:01:22 +0100 Subject: [PATCH] [CLDC-1512] Add buyer1 income (#940) * Add tests for household wheelchair * [CLDC-1512] Add buyer 1 income * Add guidance to question --- app/models/form/sales/pages/buyer1_income.rb | 16 ++++++ .../form/sales/questions/buyer1_income.rb | 14 +++++ .../sales/questions/buyer1_income_known.rb | 21 +++++++ app/models/form/sales/sections/finances.rb | 12 ++++ .../income_benefits_and_outgoings.rb | 15 +++++ app/models/form_handler.rb | 1 + .../_what_counts_as_income_sales.html.erb | 17 ++++++ ...20221007142742_add_income1_to_sales_log.rb | 6 ++ db/schema.rb | 3 + spec/factories/sales_log.rb | 2 + .../form/sales/pages/buyer1_income_spec.rb | 33 +++++++++++ .../sales/pages/household_wheelchair_spec.rb | 33 +++++++++++ .../questions/buyer1_income_known_spec.rb | 55 +++++++++++++++++++ .../sales/questions/buyer1_income_spec.rb | 53 ++++++++++++++++++ .../questions/household_wheelchair_spec.rb | 49 +++++++++++++++++ .../form/sales/sections/finances_spec.rb | 33 +++++++++++ .../income_benefits_and_outgoings_spec.rb | 33 +++++++++++ spec/models/form_handler_spec.rb | 4 +- 18 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 app/models/form/sales/pages/buyer1_income.rb create mode 100644 app/models/form/sales/questions/buyer1_income.rb create mode 100644 app/models/form/sales/questions/buyer1_income_known.rb create mode 100644 app/models/form/sales/sections/finances.rb create mode 100644 app/models/form/sales/subsections/income_benefits_and_outgoings.rb create mode 100644 app/views/form/guidance/_what_counts_as_income_sales.html.erb create mode 100644 db/migrate/20221007142742_add_income1_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/buyer1_income_spec.rb create mode 100644 spec/models/form/sales/pages/household_wheelchair_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_income_known_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_income_spec.rb create mode 100644 spec/models/form/sales/questions/household_wheelchair_spec.rb create mode 100644 spec/models/form/sales/sections/finances_spec.rb create mode 100644 spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb diff --git a/app/models/form/sales/pages/buyer1_income.rb b/app/models/form/sales/pages/buyer1_income.rb new file mode 100644 index 000000000..e4f88be81 --- /dev/null +++ b/app/models/form/sales/pages/buyer1_income.rb @@ -0,0 +1,16 @@ +class Form::Sales::Pages::Buyer1Income < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_1_income" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::Buyer1IncomeKnown.new(nil, nil, self), + Form::Sales::Questions::Buyer1Income.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer1_income.rb b/app/models/form/sales/questions/buyer1_income.rb new file mode 100644 index 000000000..f4e586b39 --- /dev/null +++ b/app/models/form/sales/questions/buyer1_income.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::Buyer1Income < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income1" + @check_answer_label = "Buyer 1’s gross annual income" + @header = "Buyer 1’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/buyer1_income_known.rb b/app/models/form/sales/questions/buyer1_income_known.rb new file mode 100644 index 000000000..923045ef9 --- /dev/null +++ b/app/models/form/sales/questions/buyer1_income_known.rb @@ -0,0 +1,21 @@ +class Form::Sales::Questions::Buyer1IncomeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income1nk" + @check_answer_label = "Buyer 1’s gross annual income" + @header = "Do you know buyer 1’s annual income?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @guidance_position = GuidancePosition::BOTTOM + @guidance_partial = "what_counts_as_income_sales" + @conditional_for = { + "income1" => [0], + } + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/sections/finances.rb b/app/models/form/sales/sections/finances.rb new file mode 100644 index 000000000..c2c4082fd --- /dev/null +++ b/app/models/form/sales/sections/finances.rb @@ -0,0 +1,12 @@ +class Form::Sales::Sections::Finances < ::Form::Section + def initialize(id, hsh, form) + super + @id = "finances" + @label = "Finances" + @description = "" + @form = form + @subsections = [ + Form::Sales::Subsections::IncomeBenefitsAndOutgoings.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/subsections/income_benefits_and_outgoings.rb b/app/models/form/sales/subsections/income_benefits_and_outgoings.rb new file mode 100644 index 000000000..2c9d779b4 --- /dev/null +++ b/app/models/form/sales/subsections/income_benefits_and_outgoings.rb @@ -0,0 +1,15 @@ +class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection + def initialize(id, hsh, section) + super + @id = "income_benefits_and_outgoings" + @label = "Income, benefits and outgoings" + @section = section + @depends_on = [{ "setup" => "completed" }] + end + + def pages + @pages ||= [ + Form::Sales::Pages::Buyer1Income.new(nil, nil, self), + ] + end +end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index c9d45e876..c6dde13ab 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -22,6 +22,7 @@ class FormHandler sales_sections = [ Form::Sales::Sections::PropertyInformation, Form::Sales::Sections::Household, + Form::Sales::Sections::Finances, ] current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales") diff --git a/app/views/form/guidance/_what_counts_as_income_sales.html.erb b/app/views/form/guidance/_what_counts_as_income_sales.html.erb new file mode 100644 index 000000000..c5e2c7116 --- /dev/null +++ b/app/views/form/guidance/_what_counts_as_income_sales.html.erb @@ -0,0 +1,17 @@ +<%= govuk_details(summary_text: "What counts as income?") do %> +

You should include any income from:

+ + +

Don’t include:

+ +<% end %> diff --git a/db/migrate/20221007142742_add_income1_to_sales_log.rb b/db/migrate/20221007142742_add_income1_to_sales_log.rb new file mode 100644 index 000000000..a1e509532 --- /dev/null +++ b/db/migrate/20221007142742_add_income1_to_sales_log.rb @@ -0,0 +1,6 @@ +class AddIncome1ToSalesLog < ActiveRecord::Migration[7.0] + change_table :sales_logs, bulk: true do |t| + t.column :income1, :int + t.column :income1nk, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index 51aa4c704..2af1b4f54 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -364,6 +364,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do t.integer "age5_known" t.integer "age6" t.integer "age6_known" + t.integer "proplen" + t.integer "income1" + t.integer "income1nk" 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 f35d60adb..903e3c041 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -47,6 +47,8 @@ FactoryBot.define do age5 { 40 } age6_known { 0 } age6 { 40 } + income1nk { 0 } + income1 { 10_000 } end end end diff --git a/spec/models/form/sales/pages/buyer1_income_spec.rb b/spec/models/form/sales/pages/buyer1_income_spec.rb new file mode 100644 index 000000000..a95a8ee5f --- /dev/null +++ b/spec/models/form/sales/pages/buyer1_income_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer1Income, 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[income1nk income1]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_1_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 be_nil + end +end diff --git a/spec/models/form/sales/pages/household_wheelchair_spec.rb b/spec/models/form/sales/pages/household_wheelchair_spec.rb new file mode 100644 index 000000000..f727bcbac --- /dev/null +++ b/spec/models/form/sales/pages/household_wheelchair_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::HouseholdWheelchair, 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[wheel]) + end + + it "has the correct id" do + expect(page.id).to eq("household_wheelchair") + 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 diff --git a/spec/models/form/sales/questions/buyer1_income_known_spec.rb b/spec/models/form/sales/questions/buyer1_income_known_spec.rb new file mode 100644 index 000000000..81edb985e --- /dev/null +++ b/spec/models/form/sales/questions/buyer1_income_known_spec.rb @@ -0,0 +1,55 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer1IncomeKnown, 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("income1nk") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know buyer 1’s annual income?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 1’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({ + "income1" => [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/buyer1_income_spec.rb b/spec/models/form/sales/questions/buyer1_income_spec.rb new file mode 100644 index 000000000..5ec84bb58 --- /dev/null +++ b/spec/models/form/sales/questions/buyer1_income_spec.rb @@ -0,0 +1,53 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer1Income, 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("income1") + end + + it "has the correct header" do + expect(question.header).to eq("Buyer 1’s gross annual income") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 1’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/questions/household_wheelchair_spec.rb b/spec/models/form/sales/questions/household_wheelchair_spec.rb new file mode 100644 index 000000000..8d641aef7 --- /dev/null +++ b/spec/models/form/sales/questions/household_wheelchair_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::HouseholdWheelchair, 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("wheel") + end + + it "has the correct header" do + expect(question.header).to eq("Does anyone in the household use a wheelchair?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to be_nil + 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" }, + "3" => { "value" => "Don't know" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to be_nil + end + + it "has the correct hint" do + expect(question.hint_text).to eq("This can be inside or outside the home") + end +end diff --git a/spec/models/form/sales/sections/finances_spec.rb b/spec/models/form/sales/sections/finances_spec.rb new file mode 100644 index 000000000..4797f6b4e --- /dev/null +++ b/spec/models/form/sales/sections/finances_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Sections::Finances, type: :model do + subject(:section) { described_class.new(section_id, section_definition, form) } + + let(:section_id) { nil } + let(:section_definition) { nil } + let(:form) { instance_double(Form) } + + it "has correct form" do + expect(section.form).to eq(form) + end + + it "has correct subsections" do + expect(section.subsections.map(&:id)).to eq( + %w[ + income_benefits_and_outgoings + ], + ) + end + + it "has the correct id" do + expect(section.id).to eq("finances") + end + + it "has the correct label" do + expect(section.label).to eq("Finances") + end + + it "has the correct description" do + expect(section.description).to eq("") + end +end diff --git a/spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb new file mode 100644 index 000000000..add0a6952 --- /dev/null +++ b/spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :model do + subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) } + + let(:subsection_id) { nil } + let(:subsection_definition) { nil } + let(:section) { instance_double(Form::Sales::Sections::Household) } + + it "has correct section" do + expect(subsection.section).to eq(section) + end + + it "has correct pages" do + expect(subsection.pages.map(&:id)).to eq( + %w[ + buyer_1_income + ], + ) + end + + it "has the correct id" do + expect(subsection.id).to eq("income_benefits_and_outgoings") + end + + it "has the correct label" do + expect(subsection.label).to eq("Income, benefits and outgoings") + end + + it "has correct depends on" do + expect(subsection.depends_on).to eq([{ "setup" => "completed" }]) + end +end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 07390df41..5108a56c3 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(39) + expect(form.pages.count).to eq(40) 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(39) + expect(form.pages.count).to eq(40) expect(form.name).to eq("2021_2022_sales") end end