Browse Source

CLDC-2545: answers dependant on staircase ownership, tests written.

CLDC-2454-add-q90-based-on-q78
Aaron Spencer 2 years ago
parent
commit
50ff1da476
  1. 8
      app/models/form/sales/questions/mortgageused.rb
  2. 2
      app/models/validations/sales/soft_validations.rb
  3. 16
      spec/models/form/sales/questions/mortgageused_spec.rb

8
app/models/form/sales/questions/mortgageused.rb

@ -16,15 +16,15 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
"3" => { "value" => "Don’t know" },
}.freeze
def displayed_answer_options(_log, _user = nil)
def displayed_answer_options(log, _user = nil)
if log.stairowned == 100 &&
ANSWER_OPTIONS
else
{
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}
end
def answer_options(_log, _user = null)
log.stairowned == 100
end
def question_number

2
app/models/validations/sales/soft_validations.rb

@ -135,7 +135,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?

16
spec/models/form/sales/questions/mortgageused_spec.rb

@ -48,10 +48,24 @@ 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
context "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 "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