From 2dcafc8ecd0fa2e9a23a0bc1b9e2a76d30a1284f Mon Sep 17 00:00:00 2001 From: Aaron Spencer <62190777+Airk0n@users.noreply.github.com> Date: Thu, 29 Jun 2023 14:46:10 +0100 Subject: [PATCH] CLDC 2454: add answer option to q90 depending on q78 (#1717) * CDLC-2545: Wip * CLDC-2545: answers dependant on staircase ownership, tests written. * CLDC-2545: linting * CLDC-2545: Mortgage used validation condition * CLDC-2545: lint and type removal. * CLDC-2454: lint and type removal. --- .../form/sales/questions/mortgageused.rb | 14 ++++++---- .../sales/sale_information_validations.rb | 2 +- .../validations/sales/soft_validations.rb | 2 +- .../form/sales/questions/mortgageused_spec.rb | 26 +++++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/models/form/sales/questions/mortgageused.rb b/app/models/form/sales/questions/mortgageused.rb index 7f87b9230..e8f8d0e6b 100644 --- a/app/models/form/sales/questions/mortgageused.rb +++ b/app/models/form/sales/questions/mortgageused.rb @@ -16,11 +16,15 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question "3" => { "value" => "Don’t know" }, }.freeze - def displayed_answer_options(_log, _user = nil) - { - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - } + def displayed_answer_options(log, _user = nil) + if log.stairowned == 100 + ANSWER_OPTIONS + else + { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + } + end end def question_number diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index bf3c2af86..b802fa08f 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -50,7 +50,7 @@ module Validations::Sales::SaleInformationValidations def validate_discounted_ownership_value(record) return unless record.saledate && collection_start_year_for_date(record.saledate) >= 2024 return unless record.value && record.deposit && record.ownershipsch - return unless record.mortgage || record.mortgageused == 2 + return unless record.mortgage || record.mortgageused == 2 || record.mortgageused == 3 return unless record.discount || record.grant || record.type == 29 if record.mortgage_deposit_and_grant_total != record.value_with_discount && record.discounted_ownership_sale? diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 52a89550a..b821bc480 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -141,7 +141,7 @@ module Validations::Sales::SoftValidations def discounted_ownership_value_invalid? return unless saledate && collection_start_year <= 2023 return unless value && deposit && ownershipsch - return unless mortgage || mortgageused == 2 + return unless mortgage || mortgageused == 2 || mortgageused == 3 return unless discount || grant || type == 29 mortgage_deposit_and_grant_total != value_with_discount && discounted_ownership_sale? diff --git a/spec/models/form/sales/questions/mortgageused_spec.rb b/spec/models/form/sales/questions/mortgageused_spec.rb index 32fdfde72..e423aaf80 100644 --- a/spec/models/form/sales/questions/mortgageused_spec.rb +++ b/spec/models/form/sales/questions/mortgageused_spec.rb @@ -48,10 +48,26 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do expect(question.hint_text).to be_nil end - it "has the correct displayed_answer_options" do - expect(question.displayed_answer_options(log)).to eq({ - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - }) + context "when staircase owned percentage is 100%" do + let(:log) { build(:sales_log, stairowned: 100) } + + it "show's the don't know option" do + expect(question.displayed_answer_options(log)).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don’t know" }, + }) + end + end + + context "when staircase owned percentage is less than 100%" do + let(:log) { build(:sales_log, stairowned: 99) } + + it "show's the don't know option" do + expect(question.displayed_answer_options(log)).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) + end end end