Browse Source

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.
pull/1737/head
Aaron Spencer 2 years ago committed by GitHub
parent
commit
2dcafc8ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/models/form/sales/questions/mortgageused.rb
  2. 2
      app/models/validations/sales/sale_information_validations.rb
  3. 2
      app/models/validations/sales/soft_validations.rb
  4. 26
      spec/models/form/sales/questions/mortgageused_spec.rb

14
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

2
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?

2
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?

26
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

Loading…
Cancel
Save