diff --git a/spec/models/form/sales/questions/mortgageused_spec.rb b/spec/models/form/sales/questions/mortgageused_spec.rb index 93ce3ed4c..bdf9ef4f8 100644 --- a/spec/models/form/sales/questions/mortgageused_spec.rb +++ b/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,16 +11,17 @@ 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)) } - 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(: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: "shared_ownership")) } + + context "when the form start year is 2024", metadata: { year: 24 } do + let(:saledate) { collection_start_date_for_year(2024) } let(:ownershipsch) { 1 } - - before do - allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: false) - end + let(:start_year_2025_or_later?) { false } + let(:start_year_2026_or_later?) { false } it "has the correct answer_options" do expect(question.answer_options).to eq({ @@ -44,18 +47,8 @@ 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 - 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 @@ -92,14 +85,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)) } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:, id: "shared_ownership")) } - let(:saledate) { Time.zone.local(2025, 5, 1) } - - 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 } @@ -142,6 +130,42 @@ 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 } + + it "shows the correct question number" do + expect(question.question_number).to eq 106 + end + + it "does show 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 } + + it "does show 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 } + + it "does show 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 diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 1731f19ac..533bdd4af 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -1385,76 +1385,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 diff --git a/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb index e34559d92..050a50a9b 100644 --- a/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb @@ -1312,13 +1312,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 @@ -1362,13 +1358,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 @@ -1404,13 +1396,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