Browse Source

CLDC-4215, CLDC-4216: Add mortgage used Don't Know option (#3208)

* CLDC-4215: Show Don't Know on all paths of mortgageused

* CLDC-4215: Update tests

* fixup! CLDC-4215: Show Don't Know on all paths of mortgageused

* fixup! CLDC-4215: Update tests

cover all cases

* fixup! CLDC-4215: Show Don't Know on all paths of mortgageused

* fixup! CLDC-4215: Update tests
pull/3223/head^2
Samuel Young 6 days ago committed by GitHub
parent
commit
599307029d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/form/sales/questions/mortgageused.rb
  2. 5
      app/models/validations/sales/sale_information_validations.rb
  3. 129
      spec/models/form/sales/questions/mortgageused_spec.rb
  4. 162
      spec/models/validations/sales/sale_information_validations_spec.rb
  5. 11
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  6. 24
      spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

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

@ -10,9 +10,7 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
end
def displayed_answer_options(log, _user = nil)
if log.outright_sale? && log.saledate && !form.start_year_2024_or_later?
answer_options_without_dont_know
elsif log.stairowned_100? || log.outright_sale? || (log.is_staircase? && form.start_year_2025_or_later?)
if form.start_year_2026_or_later? || log.stairowned_100? || log.outright_sale? || (log.is_staircase? && form.start_year_2025_or_later?)
ANSWER_OPTIONS
else
answer_options_without_dont_know

5
app/models/validations/sales/sale_information_validations.rb

@ -372,14 +372,11 @@ module Validations::Sales::SaleInformationValidations
def validate_mortgage_used_dont_know(record)
return unless record.mortgage_use_unknown?
return if record.form.start_year_2026_or_later?
if record.discounted_ownership_sale?
record.errors.add :mortgageused, I18n.t("validations.invalid_option", question: "was a mortgage used for the purchase of this property?")
end
if record.outright_sale? && record.saledate && !record.form.start_year_2024_or_later?
record.errors.add :mortgageused, I18n.t("validations.invalid_option", question: "was a mortgage used for the purchase of this property?")
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.mortgage_used_year")
end
if record.shared_ownership_scheme? && record.is_not_staircasing?
record.errors.add :mortgageused, I18n.t("validations.invalid_option", question: "was a mortgage used for the purchase of this property?")
record.errors.add :staircase, I18n.t("validations.sales.sale_information.staircase.mortgage_used_value")

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

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch:) }
let(:question_id) { nil }
@ -9,25 +11,41 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
let(:staircase) { nil }
let(:saledate) { Time.zone.today }
let(:log) { build(:sales_log, :in_progress, ownershipsch:, stairowned:, staircase:) }
context "when the form start year is 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2026_or_later?: false) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: "shared_ownership")) }
let(:saledate) { Time.zone.local(2024, 5, 1) }
let(:start_year_2024_or_later?) { true }
let(:start_year_2025_or_later?) { true }
let(:start_year_2026_or_later?) { true }
let(:subsection_id) { "shared_ownership_initial_purchase" }
let(:form) { instance_double(Form, start_date: saledate, start_year_2024_or_later?: start_year_2024_or_later?, start_year_2025_or_later?: start_year_2025_or_later?, start_year_2026_or_later?: start_year_2026_or_later?) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: subsection_id)) }
context "when it is a shared ownership scheme" do
let(:ownershipsch) { 1 }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: false)
it "has the correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("financial_calculations_shared_ownership")
end
end
context "when it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
it "has the correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("financial_calculations_discounted_ownership")
end
end
context "when it is an outright sale" do
let(:ownershipsch) { 3 }
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"divider" => { "value" => true },
"3" => { "value" => "Don’t know" },
})
it "has the correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("financial_calculations_outright_sale")
end
end
context "when the form start year is 2024", metadata: { year: 24 } do
let(:saledate) { collection_start_date_for_year(2024) }
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
context "when it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
@ -44,24 +62,22 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
context "when it is an outright sale" do
let(:ownershipsch) { 3 }
context "and the saledate is before 24/25" do
let(:saledate) { Time.zone.local(2023, 5, 1) }\
it "does show the don't know option" do
expect_the_question_to_show_dont_know
end
it "shows the correct question number" do
expect(question.question_number).to eq 112
end
context "and the saledate is 24/25" do
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
end
context "when it is a shared ownership scheme" do
let(:ownershipsch) { 1 }
it "shows the correct question number" do
expect(question.question_number).to eq 91
end
context "and it is a staircasing transaction" do
let(:staircase) { 1 }
@ -92,15 +108,9 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
end
end
context "when the form start year is 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2026_or_later?: false) }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: subsection_id)) }
let(:saledate) { Time.zone.local(2025, 5, 1) }
let(:subsection_id) { "shared_ownership_initial_purchase" }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true)
end
context "when the form start year is 2025", metadata: { year: 25 } do
let(:saledate) { collection_start_date_for_year(2025) }
let(:start_year_2026_or_later?) { false }
context "when it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
@ -118,10 +128,14 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
context "when it is a shared ownership scheme" do
let(:ownershipsch) { 1 }
it "shows the correct question number" do
expect(question.question_number).to eq 82
end
context "and it is a staircasing transaction" do
let(:staircase) { 1 }
it "does show the don't know option" do
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
@ -144,6 +158,53 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
end
end
context "when the form start year is 2026", metadata: { year: 26 } do
let(:saledate) { collection_start_date_for_year(2026) }
context "when it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
let(:subsection_id) { "discounted_ownership_scheme" }
it "shows the correct question number" do
expect(question.question_number).to eq 116
end
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
end
context "when it is a shared ownership scheme" do
let(:ownershipsch) { 1 }
context "and it is a staircasing transaction" do
let(:staircase) { 1 }
let(:subsection_id) { "shared_ownership_staircasing_transaction" }
it "shows the correct question number" do
expect(question.question_number).to eq 107
end
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
end
context "and it is not a staircasing transaction" do
let(:staircase) { 2 }
let(:subsection_id) { "shared_ownership_initial_purchase" }
it "shows the correct question number" do
expect(question.question_number).to eq 90
end
it "shows the don't know option" do
expect_the_question_to_show_dont_know
end
end
end
end
private
def expect_the_question_not_to_show_dont_know

162
spec/models/validations/sales/sale_information_validations_spec.rb

@ -1501,76 +1501,156 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
sale_information_validator.validate_mortgage_used_dont_know(sales_log)
end
context "when mortgageused is don't know" do
let(:mortgageused) { 3 }
context "when 2025", metadata: { year: 25 } do
let(:saledate) { collection_start_date_for_year(2025) }
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
context "when mortgageused is don't know" do
let(:mortgageused) { 3 }
it "adds an error" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
it "adds an error" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
end
end
end
context "and it is an outright sale" do
let(:ownershipsch) { 3 }
context "and it is an outright sale" do
let(:ownershipsch) { 3 }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
end
context "and it is a shared ownership scheme sale" do
let(:ownershipsch) { 1 }
context "and it is a shared ownership scheme sale" do
let(:ownershipsch) { 1 }
context "and a staircasing transaction" do
let(:staircase) { 1 }
context "and a staircasing transaction" do
let(:staircase) { 1 }
context "and stairowned is nil" do
let(:stairowned) { nil }
context "and stairowned is nil" do
let(:stairowned) { nil }
it "does not add an error" do
expect(sales_log.errors).to be_empty
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
context "and stairowned is less than 100" do
let(:stairowned) { 50 }
context "and stairowned is less than 100" do
let(:stairowned) { 50 }
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
expect(sales_log.errors[:stairowned]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
expect(sales_log.errors[:stairowned]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
end
end
context "and stairowned is 100" do
let(:stairowned) { 100 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
context "and stairowned is 100" do
let(:stairowned) { 100 }
context "and not a staircasing transaction" do
let(:staircase) { 2 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
expect(sales_log.errors[:staircase]).to include "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for staircasing transactions."
end
end
end
end
context "and not a staircasing transaction" do
let(:staircase) { 2 }
context "when mortgageused is not don't know" do
let(:mortgageused) { 1 }
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
expect(sales_log.errors[:staircase]).to include "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for staircasing transactions."
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
end
context "when mortgageused is not don't know" do
let(:mortgageused) { 1 }
context "when 2026", metadata: { year: 26 } do
let(:saledate) { collection_start_date_for_year(2026) }
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
context "when mortgageused is don't know" do
let(:mortgageused) { 3 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
context "and it is an outright sale" do
let(:ownershipsch) { 3 }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
context "and it is a shared ownership scheme sale" do
let(:ownershipsch) { 1 }
context "and a staircasing transaction" do
let(:staircase) { 1 }
context "and stairowned is nil" do
let(:stairowned) { nil }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
context "and stairowned is less than 100" do
let(:stairowned) { 50 }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
context "and stairowned is 100" do
let(:stairowned) { 100 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
context "and not a staircasing transaction" do
let(:staircase) { 2 }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
end
end
context "when mortgageused is not don't know" do
let(:mortgageused) { 1 }
context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
end

11
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -1136,17 +1136,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
end
end
describe "#field_128" do
let(:attributes) { valid_attributes.merge({ field_7: "3", field_10: "10", field_128: "3", field_12: "2" }) }
it "does not allow 3 (don't know) as an option for outright sale" do
expect(parser.errors[:field_128]).to include("Enter a valid value for was a mortgage used for the purchase of this property?")
parser.log.blank_invalid_non_setup_fields!
parser.log.save!
expect(parser.log.mortgageused).to be_nil
end
end
end
describe "#log" do

24
spec/services/bulk_upload/sales/year2026/row_parser_spec.rb

@ -1321,13 +1321,9 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
context "when value is 3 and stairowned is not 100" do
let(:attributes) { setup_section_params.merge(field_109: "3", field_10: "1", field_96: "50", field_97: "99", field_120: nil) }
it "returns correct errors" do
it "does not add errors" do
parser.valid?
expect(parser.errors[:field_109]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'")
parser.log.blank_invalid_non_setup_fields!
parser.log.save!
expect(parser.log.mortgageused).to be_nil
expect(parser.errors[:field_109]).to be_empty
end
end
@ -1371,13 +1367,9 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
context "when value is 3 and stairowned is not answered" do
let(:attributes) { setup_section_params.merge(field_88: "3", field_10: "2", field_96: "50", field_97: nil, field_120: nil) }
it "returns correct errors" do
it "does not add errors" do
parser.valid?
expect(parser.errors[:field_88]).to include(I18n.t("validations.invalid_option", question: "was a mortgage used for the purchase of this property?"))
parser.log.blank_invalid_non_setup_fields!
parser.log.save!
expect(parser.log.mortgageused).to be_nil
expect(parser.errors[:field_88]).to be_empty
end
end
@ -1413,13 +1405,9 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do
describe "#field_116" do
let(:attributes) { valid_attributes.merge({ field_8: "2", field_11: "9", field_116: "3" }) }
it "does not allow 3 (don't know) as an option for discounted ownership" do
it "allows 3 (don't know) as an option for discounted ownership" do
parser.valid?
expect(parser.errors[:field_116]).to include(I18n.t("validations.invalid_option", question: "was a mortgage used for the purchase of this property?"))
parser.log.blank_invalid_non_setup_fields!
parser.log.save!
expect(parser.log.mortgageused).to be_nil
expect(parser.errors[:field_116]).to be_empty
end
context "when validate_discounted_ownership_value is triggered" do

Loading…
Cancel
Save