diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 6ae34c3df..c5c685184 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -311,12 +311,10 @@ RSpec.describe Validations::Sales::FinancialValidations do context "when buyer 2 is not a child" do before do - record.update!(ecstat2: rand(0..8)) - record.reload + record.ecstat2 = rand(0..8) end it "does not add an error if buyer 2 has an income" do - record.ecstat2 = rand(0..8) record.income2 = 40_000 financial_validator.validate_child_income(record) expect(record.errors).to be_empty @@ -324,29 +322,31 @@ RSpec.describe Validations::Sales::FinancialValidations do end context "when buyer 2 is a child" do - it "does not add an error if buyer 2 has no income" do - record.saledate = Time.zone.local(2023, 4, 3) - record.ecstat2 = 9 - record.income2 = 0 - financial_validator.validate_child_income(record) - expect(record.errors).to be_empty - end - - it "adds errors if buyer 2 has an income" do - record.saledate = Time.zone.local(2023, 4, 3) - record.ecstat2 = 9 - record.income2 = 40_000 - financial_validator.validate_child_income(record) - expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.child_has_income")) - expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.child_has_income")) - end - - it "does not add an error if the saledate is before the 23/24 collection window" do - record.saledate = Time.zone.local(2022, 4, 3) - record.ecstat2 = 9 - record.income2 = 40_000 - financial_validator.validate_child_income(record) - expect(record.errors).to be_empty + context "and saledate is current" do + let(:record) { build(:sales_log, :saledate_today, ecstat2: 9) } + + it "does not add an error if buyer 2 has no income" do + record.income2 = 0 + financial_validator.validate_child_income(record) + expect(record.errors).to be_empty + end + + it "adds errors if buyer 2 has an income" do + record.income2 = 40_000 + financial_validator.validate_child_income(record) + expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.child_has_income")) + expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.child_has_income")) + end + end + + context "and saledate is before the 23/24 collection window" do + let(:record) { build(:sales_log, saledate: Time.zone.local(2022, 4, 3), ecstat2: 9) } + + it "does not add an error if the saledate is before the 23/24 collection window" do + record.income2 = 40_000 + financial_validator.validate_child_income(record) + expect(record.errors).to be_empty + end end end end diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index bdf9fcb99..a2e659011 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -75,7 +75,7 @@ RSpec.describe BulkUpload::Lettings::Validator do context "when uploading a 2023 logs for 2024 bulk upload" do let(:log) { build(:lettings_log, :completed, startdate: Time.zone.local(2023, 5, 6), tenancycode: "5234234234234") } - let(:bulk_upload) { build(:bulk_upload, user:, year: 2024)} + let(:bulk_upload) { build(:bulk_upload, user:, year: 2024) } context "with headers" do let(:seed) { rand } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 1d6d16b5f..1313ee12c 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -30,7 +30,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end before do - allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) LaRentRange.create!( diff --git a/spec/services/bulk_upload/sales/log_creator_spec.rb b/spec/services/bulk_upload/sales/log_creator_spec.rb index ccf9efae5..2353a74c6 100644 --- a/spec/services/bulk_upload/sales/log_creator_spec.rb +++ b/spec/services/bulk_upload/sales/log_creator_spec.rb @@ -93,7 +93,7 @@ RSpec.describe BulkUpload::Sales::LogCreator do deposit: 10_000, mortgageused: 1, mortgage: 100_000, - grant: 10_000 + grant: 10_000, ) end