From d568f23ac6268f69388083385148c5fa0bc46621 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Fri, 23 Dec 2022 12:15:14 +0000 Subject: [PATCH 1/2] feat: add question page and subsection (#1120) * feat: add question page and subsection * refactor: linting * feat: remove schema rows from other branch * feat: slight refactor, fix tag behaviour and add section tests * test: update and add tests * feat: update status behaviour * feat: update subsection status tag * refactor: linting --- app/models/form/question.rb | 6 +++ .../form/sales/pages/buyers_organisations.rb | 15 ++++++ .../sales/questions/buyers_organisations.rb | 19 ++++++++ app/models/form/sales/sections/household.rb | 1 + .../sales/subsections/household_situation.rb | 15 ++++++ app/models/form/subsection.rb | 2 +- ...9_add_buyers_organisations_to_sales_log.rb | 10 ++++ db/schema.rb | 6 ++- spec/factories/sales_log.rb | 4 ++ .../sales/pages/buyers_organisations_spec.rb | 33 +++++++++++++ .../questions/buyers_organisations_spec.rb | 48 +++++++++++++++++++ .../form/sales/sections/household_spec.rb | 1 + .../sales/subsections/household_needs_spec.rb | 34 +++++++++++++ .../subsections/household_situation_spec.rb | 33 +++++++++++++ spec/models/form_handler_spec.rb | 4 +- 15 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 app/models/form/sales/pages/buyers_organisations.rb create mode 100644 app/models/form/sales/questions/buyers_organisations.rb create mode 100644 app/models/form/sales/subsections/household_situation.rb create mode 100644 db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/buyers_organisations_spec.rb create mode 100644 spec/models/form/sales/questions/buyers_organisations_spec.rb create mode 100644 spec/models/form/sales/subsections/household_needs_spec.rb create mode 100644 spec/models/form/sales/subsections/household_situation_spec.rb diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 5b4440e39..aa9689295 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -129,6 +129,12 @@ class Form::Question "/#{log.model_name.param_key.dasherize}s/#{log.id}/#{page_id.to_s.dasherize}?referrer=check_answers" end + def unanswered?(log) + return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox" + + log[id].blank? + end + def completed?(log) return answer_options.keys.any? { |key| value_is_yes?(log[key]) } if type == "checkbox" diff --git a/app/models/form/sales/pages/buyers_organisations.rb b/app/models/form/sales/pages/buyers_organisations.rb new file mode 100644 index 000000000..cc6f82984 --- /dev/null +++ b/app/models/form/sales/pages/buyers_organisations.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::BuyersOrganisations < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyers_organisations" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::BuyersOrganisations.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyers_organisations.rb b/app/models/form/sales/questions/buyers_organisations.rb new file mode 100644 index 000000000..dd3d87bd0 --- /dev/null +++ b/app/models/form/sales/questions/buyers_organisations.rb @@ -0,0 +1,19 @@ +class Form::Sales::Questions::BuyersOrganisations < ::Form::Question + def initialize(id, hsh, page) + super + @id = "buyers_organisations" + @check_answer_label = "Organisations buyers were registered with" + @header = "What organisations were the buyers registered with?" + @type = "checkbox" + @hint_text = "Select all that apply" + @page = page + @answer_options = ANSWER_OPTIONS + end + + ANSWER_OPTIONS = { + "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" }, + "pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, + "pregla" => { "value" => "Local Authority" }, + "pregghb" => { "value" => "Help to Buy Agent" }, + }.freeze +end diff --git a/app/models/form/sales/sections/household.rb b/app/models/form/sales/sections/household.rb index e6f71a26d..3c7eae085 100644 --- a/app/models/form/sales/sections/household.rb +++ b/app/models/form/sales/sections/household.rb @@ -7,6 +7,7 @@ class Form::Sales::Sections::Household < ::Form::Section @form = form @subsections = [ Form::Sales::Subsections::HouseholdCharacteristics.new(nil, nil, self), + Form::Sales::Subsections::HouseholdSituation.new(nil, nil, self), Form::Sales::Subsections::HouseholdNeeds.new(nil, nil, self), ] end diff --git a/app/models/form/sales/subsections/household_situation.rb b/app/models/form/sales/subsections/household_situation.rb new file mode 100644 index 000000000..2be48f68c --- /dev/null +++ b/app/models/form/sales/subsections/household_situation.rb @@ -0,0 +1,15 @@ +class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection + def initialize(id, hsh, section) + super + @id = "household_situation" + @label = "Household situation" + @section = section + @depends_on = [{ "setup_completed?" => true }] + end + + def pages + @pages ||= [ + Form::Sales::Pages::BuyersOrganisations.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 07e7fe65c..c3157b8c6 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -30,7 +30,7 @@ class Form::Subsection qs = applicable_questions(log) qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) } - return :not_started if qs.count.positive? && qs.all? { |question| log[question.id].blank? || question.read_only? || question.derived? } + return :not_started if qs.count.positive? && qs.all? { |question| question.unanswered?(log) || question.read_only? || question.derived? } return :completed if qs_optional_removed.all? { |question| question.completed?(log) } :in_progress diff --git a/db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb b/db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb new file mode 100644 index 000000000..4781fd7b3 --- /dev/null +++ b/db/migrate/20221222153059_add_buyers_organisations_to_sales_log.rb @@ -0,0 +1,10 @@ +class AddBuyersOrganisationsToSalesLog < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :pregyrha, :int + t.column :pregla, :int + t.column :pregghb, :int + t.column :pregother, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2d53aab20..c3fc7d946 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_12_21_172821) do +ActiveRecord::Schema[7.0].define(version: 2022_12_22_153059) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -415,6 +415,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_21_172821) do t.integer "ecstat4" t.integer "ecstat5" t.integer "ecstat6" + t.integer "pregyrha" + t.integer "pregla" + t.integer "pregghb" + t.integer "pregother" t.integer "disabled" 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" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 9b899b114..70ade2523 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -68,6 +68,10 @@ FactoryBot.define do ecstat5 { 2 } ecstat6 { 1 } disabled { 2 } + pregyrha { 1 } + pregla { 1 } + pregother { 1 } + pregghb { 1 } end end end diff --git a/spec/models/form/sales/pages/buyers_organisations_spec.rb b/spec/models/form/sales/pages/buyers_organisations_spec.rb new file mode 100644 index 000000000..f245fe7f5 --- /dev/null +++ b/spec/models/form/sales/pages/buyers_organisations_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::BuyersOrganisations, 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[buyers_organisations]) + end + + it "has the correct id" do + expect(page.id).to eq("buyers_organisations") + 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/buyers_organisations_spec.rb b/spec/models/form/sales/questions/buyers_organisations_spec.rb new file mode 100644 index 000000000..14bb944f4 --- /dev/null +++ b/spec/models/form/sales/questions/buyers_organisations_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::BuyersOrganisations, 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("buyers_organisations") + end + + it "has the correct header" do + expect(question.header).to eq("What organisations were the buyers registered with?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Organisations buyers were registered with") + end + + it "has the correct type" do + expect(question.type).to eq("checkbox") + 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 eq("Select all that apply") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq( + { + "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" }, + "pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, + "pregla" => { "value" => "Local Authority" }, + "pregghb" => { "value" => "Help to Buy Agent" }, + }, + ) + end +end diff --git a/spec/models/form/sales/sections/household_spec.rb b/spec/models/form/sales/sections/household_spec.rb index e415e8f0c..cff166510 100644 --- a/spec/models/form/sales/sections/household_spec.rb +++ b/spec/models/form/sales/sections/household_spec.rb @@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Sections::Household, type: :model do expect(household.subsections.map(&:id)).to eq( %w[ household_characteristics + household_situation household_needs ], ) diff --git a/spec/models/form/sales/subsections/household_needs_spec.rb b/spec/models/form/sales/subsections/household_needs_spec.rb new file mode 100644 index 000000000..f7b139ee5 --- /dev/null +++ b/spec/models/form/sales/subsections/household_needs_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::HouseholdNeeds, type: :model do + subject(:household_characteristics) { 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(household_characteristics.section).to eq(section) + end + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + household_wheelchair + household_disability + ], + ) + end + + it "has the correct id" do + expect(household_characteristics.id).to eq("household_needs") + end + + it "has the correct label" do + expect(household_characteristics.label).to eq("Household needs") + end + + it "has correct depends on" do + expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }]) + end +end diff --git a/spec/models/form/sales/subsections/household_situation_spec.rb b/spec/models/form/sales/subsections/household_situation_spec.rb new file mode 100644 index 000000000..8473971ef --- /dev/null +++ b/spec/models/form/sales/subsections/household_situation_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do + subject(:household_characteristics) { 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(household_characteristics.section).to eq(section) + end + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + buyers_organisations + ], + ) + end + + it "has the correct id" do + expect(household_characteristics.id).to eq("household_situation") + end + + it "has the correct label" do + expect(household_characteristics.label).to eq("Household situation") + end + + it "has correct depends on" do + expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }]) + end +end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index e1878f2c1..6c5f51a8e 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,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(69) + expect(form.pages.count).to eq(70) 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(69) + expect(form.pages.count).to eq(70) expect(form.name).to eq("2021_2022_sales") end end From a6a44bd065d6938888ad2acc20752ebe09faf4c5 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Fri, 23 Dec 2022 13:14:45 +0000 Subject: [PATCH 2/2] [CLDC-857] Add household wheelchair check (#1122) * [CLDC-857] Add household wheelchair check * Hide only if answered --- .../sales/pages/household_wheelchair_check.rb | 20 ++++++++ .../questions/household_wheelchair_check.rb | 25 ++++++++++ .../form/sales/subsections/household_needs.rb | 1 + .../validations/sales/soft_validations.rb | 6 +++ .../20221222105044_add_wheel_value_check.rb | 7 +++ db/schema.rb | 1 + spec/factories/sales_log.rb | 1 + .../pages/household_wheelchair_check_spec.rb | 33 +++++++++++++ .../household_wheelchair_check_spec.rb | 48 +++++++++++++++++++ 9 files changed, 142 insertions(+) create mode 100644 app/models/form/sales/pages/household_wheelchair_check.rb create mode 100644 app/models/form/sales/questions/household_wheelchair_check.rb create mode 100644 db/migrate/20221222105044_add_wheel_value_check.rb create mode 100644 spec/models/form/sales/pages/household_wheelchair_check_spec.rb create mode 100644 spec/models/form/sales/questions/household_wheelchair_check_spec.rb diff --git a/app/models/form/sales/pages/household_wheelchair_check.rb b/app/models/form/sales/pages/household_wheelchair_check.rb new file mode 100644 index 000000000..b4f4c06ae --- /dev/null +++ b/app/models/form/sales/pages/household_wheelchair_check.rb @@ -0,0 +1,20 @@ +class Form::Sales::Pages::HouseholdWheelchairCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "" + @description = "" + @subsection = subsection + @depends_on = [ + { + "wheelchair_when_not_disabled?" => true, + }, + ] + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::HouseholdWheelchairCheck.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/household_wheelchair_check.rb b/app/models/form/sales/questions/household_wheelchair_check.rb new file mode 100644 index 000000000..71cfcc23e --- /dev/null +++ b/app/models/form/sales/questions/household_wheelchair_check.rb @@ -0,0 +1,25 @@ +class Form::Sales::Questions::HouseholdWheelchairCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "wheel_value_check" + @check_answer_label = "Does anyone in the household use a wheelchair?" + @header = "Are you sure? You said previously that somebody in household uses a wheelchair" + @type = "interruption_screen" + @page = page + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "wheel_value_check" => 0, + }, + { + "wheel_value_check" => 1, + }, + ], + } + @page = page + end +end diff --git a/app/models/form/sales/subsections/household_needs.rb b/app/models/form/sales/subsections/household_needs.rb index ac60d1713..fe440dc72 100644 --- a/app/models/form/sales/subsections/household_needs.rb +++ b/app/models/form/sales/subsections/household_needs.rb @@ -11,6 +11,7 @@ class Form::Sales::Subsections::HouseholdNeeds < ::Form::Subsection @pages ||= [ Form::Sales::Pages::HouseholdWheelchair.new(nil, nil, self), Form::Sales::Pages::HouseholdDisability.new(nil, nil, self), + Form::Sales::Pages::HouseholdWheelchairCheck.new("wheelchair_check", nil, self), ] end end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 1caa7480c..d52d5cf9c 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -20,4 +20,10 @@ module Validations::Sales::SoftValidations income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0) mortgage > income_used_for_mortgage * 5 end + + def wheelchair_when_not_disabled? + return false unless disabled == 2 + + wheel == 1 + end end diff --git a/db/migrate/20221222105044_add_wheel_value_check.rb b/db/migrate/20221222105044_add_wheel_value_check.rb new file mode 100644 index 000000000..13c6d3bf4 --- /dev/null +++ b/db/migrate/20221222105044_add_wheel_value_check.rb @@ -0,0 +1,7 @@ +class AddWheelValueCheck < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :wheel_value_check, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c3fc7d946..ef796f983 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -420,6 +420,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_22_153059) do t.integer "pregghb" t.integer "pregother" t.integer "disabled" + t.integer "wheel_value_check" 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 70ade2523..c40200b90 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -72,6 +72,7 @@ FactoryBot.define do pregla { 1 } pregother { 1 } pregghb { 1 } + disabled { 1 } end end end diff --git a/spec/models/form/sales/pages/household_wheelchair_check_spec.rb b/spec/models/form/sales/pages/household_wheelchair_check_spec.rb new file mode 100644 index 000000000..c1388c7d3 --- /dev/null +++ b/spec/models/form/sales/pages/household_wheelchair_check_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::HouseholdWheelchairCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "buyer_1_income_mortgage_value_check" } + 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_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_1_income_mortgage_value_check") + end + + it "has the correct header" do + expect(page.header).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "wheelchair_when_not_disabled?" => true, + }, + ]) + end +end diff --git a/spec/models/form/sales/questions/household_wheelchair_check_spec.rb b/spec/models/form/sales/questions/household_wheelchair_check_spec.rb new file mode 100644 index 000000000..92f80fdb1 --- /dev/null +++ b/spec/models/form/sales/questions/household_wheelchair_check_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::HouseholdWheelchairCheck, 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_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure? You said previously that somebody in household uses a wheelchair") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Does anyone in the household use a wheelchair?") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + 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 the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "wheel_value_check" => 0 }, { "wheel_value_check" => 1 }] }) + end +end