Browse Source

CLDC-4074: Update tests for 2023 edit closing (#3095)

* CLDC-4074: Fix model tests

* CLDC-4074: Fix requests tests

* CLDC-4074: Fix services tests

* CLDC-4074: Fix rake tasks tests

the broken ones only make sense for 2024 logs so feels like timecop is the only option

* CLDC-4074: Specify why some tests are not validated based on year
pull/3093/head
Samuel Young 1 month ago committed by GitHub
parent
commit
812d1e0dc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/helpers/collection_time_helper.rb
  2. 7
      spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb
  3. 7
      spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb
  4. 6
      spec/models/log_spec.rb
  5. 2
      spec/models/scheme_spec.rb
  6. 4
      spec/models/validations/date_validations_spec.rb
  7. 164
      spec/models/validations/household_validations_spec.rb
  8. 343
      spec/models/validations/sales/financial_validations_spec.rb
  9. 389
      spec/models/validations/sales/household_validations_spec.rb
  10. 75
      spec/models/validations/sales/property_validations_spec.rb
  11. 793
      spec/models/validations/sales/sale_information_validations_spec.rb
  12. 93
      spec/models/validations/sales/soft_validations_spec.rb
  13. 98
      spec/requests/collection_resources_controller_spec.rb
  14. 165
      spec/requests/duplicate_logs_controller_spec.rb
  15. 188
      spec/services/csv/lettings_log_csv_service_spec.rb
  16. 12
      spec/services/documentation_generator_spec.rb

4
app/helpers/collection_time_helper.rb

@ -42,6 +42,10 @@ module CollectionTimeHelper
current_collection_start_year + 1
end
def next_collection_end_year
next_collection_start_year + 1
end
def previous_collection_start_year
current_collection_start_year - 1
end

7
spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb

@ -2,12 +2,19 @@ require "rails_helper"
require "rake"
RSpec.describe "recalculate_invalid_reasonpref_dontknow" do
include CollectionTimeHelper
subject(:task) { Rake::Task["recalculate_invalid_rpdontknow"] }
before do
Rake.application.rake_require("tasks/recalculate_invalid_reasonpref_dontknow")
Rake::Task.define_task(:environment)
task.reenable
Timecop.freeze(previous_collection_end_date)
end
after do
Timecop.return
end
let(:invalid_logs) { create_list(:lettings_log, 5, :completed, :ignore_validation_errors, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0), startdate: Time.zone.local(2024, rand(4..12), rand(1..30))) }

7
spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb

@ -2,10 +2,17 @@ require "rails_helper"
require "rake"
RSpec.describe "update_manual_address_entry_selected_preexisting_logs_spec", type: :task do
include CollectionTimeHelper
before do
Rake.application.rake_require("tasks/update_manual_address_entry_selected_prexisting_logs")
Rake::Task.define_task(:environment)
task.reenable
Timecop.freeze(previous_collection_end_date)
end
after do
Timecop.return
end
describe "bulk_update:update_manual_address_entry_selected" do

6
spec/models/log_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Log, type: :model do
include CollectionTimeHelper
it "has two child log classes" do
expect(SalesLog).to be < described_class
expect(LettingsLog).to be < described_class
@ -62,12 +64,12 @@ RSpec.describe Log, type: :model do
end
context "when a non setup field is invalid for a lettings log" do
subject(:model) { build_stubbed(:lettings_log, :completed, startdate: Time.zone.local(2023, 12, 12), offered: 234) }
subject(:model) { build_stubbed(:lettings_log, :completed, startdate: current_collection_start_date, age1: 234) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.offered).to be_nil
expect(model.age1).to be_nil
end
end

2
spec/models/scheme_spec.rb

@ -472,7 +472,7 @@ RSpec.describe Scheme, type: :model do
context "when the most recently created deactivation is not the current one" do
before do
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.today - 300.days, reactivation_date: Time.zone.today - 200.days, scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.today - 5.days, reactivation_date: Time.zone.today - 4.days, scheme:)
end
it "returns reactivating_soon" do

4
spec/models/validations/date_validations_spec.rb

@ -56,7 +56,7 @@ RSpec.describe Validations::DateValidations do
context "with 2024 logs or earlier" do
it "cannot be more than 10 years before the tenancy start date" do
record.startdate = Time.zone.local(2024, 2, 1)
record.startdate = Time.zone.local(2024, 4, 1)
record.mrcdate = Time.zone.local(2014, 1, 31)
date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"])
@ -150,7 +150,7 @@ RSpec.describe Validations::DateValidations do
context "with 2024 logs or earlier" do
it "cannot be more than 10 years before the tenancy start date" do
record.startdate = Time.zone.local(2024, 2, 1)
record.startdate = Time.zone.local(2024, 4, 1)
record.voiddate = Time.zone.local(2014, 1, 31)
date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"])

164
spec/models/validations/household_validations_spec.rb

@ -50,17 +50,6 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["reasonother"]).to be_empty
end
context "when form year is before 2024" do
let(:startdate) { Time.zone.local(2024, 1, 1) }
it "does not validate the content of reasonother for phrases indicating homelessness" do
record.reason = 20
record.reasonother = "Temp accommodation"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]).to be_empty
end
end
context "when form year is >= 2024" do
let(:startdate) { Time.zone.local(2024, 4, 1) }
@ -273,53 +262,7 @@ RSpec.describe Validations::HouseholdValidations do
end
end
describe "#validate_partner_count" do
let(:startdate) { Time.zone.local(2023, 4, 1) }
it "validates that only 1 partner exists" do
record.relat2 = "P"
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.lettings.household.relat.one_partner"))
expect(record.errors["relat3"])
.to include(match I18n.t("validations.lettings.household.relat.one_partner"))
expect(record.errors["relat4"])
.not_to include(match I18n.t("validations.lettings.household.relat.one_partner"))
end
it "expects that a tenant can have a partner" do
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["base"]).to be_empty
end
end
describe "#validate_person_age_matches_relationship" do
context "with 2023 logs" do
let(:startdate) { Time.zone.local(2023, 4, 1) }
context "when the household contains a person under 16" do
it "validates that person must be a child of the tenant" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.lettings.household.relat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.lettings.household.age.child_under_16_relat", person_num: 2))
end
it "expects that person is a child of the tenant" do
record.age2 = 14
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
end
end
context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) }
@ -342,41 +285,6 @@ RSpec.describe Validations::HouseholdValidations do
end
describe "#validate_person_age_matches_economic_status" do
context "with 2023 logs" do
let(:startdate) { Time.zone.local(2023, 4, 1) }
context "when the household contains a person under 16" do
it "validates that person's economic status must be Child" do
record.age2 = 14
record.ecstat2 = 1
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.lettings.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num: 2))
end
it "expects that person's economic status is Child" do
record.age2 = 14
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "validates that a person with economic status 'child' must be under 16" do
record.age2 = 21
record.relat2 = "C"
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.lettings.household.ecstat.child_over_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.lettings.household.age.child_over_16", person_num: 2))
end
end
end
context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) }
@ -393,78 +301,6 @@ RSpec.describe Validations::HouseholdValidations do
end
describe "#validate_person_age_and_relationship_matches_economic_status" do
context "with 2023 logs" do
let(:startdate) { Time.zone.local(2023, 4, 1) }
context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "validates that person's economic status must be full time student or refused" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 1
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.lettings.household.ecstat.student_16_19.must_be_student", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.lettings.household.age.student_16_19.cannot_be_16_19.child_not_student", person_num: 2))
expect(record.errors["relat2"])
.to include(match I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2))
end
it "expects that person can be a full time student" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 7
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
it "expects that person can refuse to share their work status" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 10
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
it "does not add an error for a person aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 18
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "adds errors for a person who is a child of the lead tenant and a student but not aged 16-19" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.student_not_16_19"))
expect(record.errors["age2"])
.to include(match I18n.t("validations.lettings.household.age.student_16_19.must_be_16_19"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.lettings.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
end
end
context "with 2024 logs" do
let(:startdate) { Time.zone.local(2024, 4, 1) }

343
spec/models/validations/sales/financial_validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Validations::Sales::FinancialValidations do
include CollectionTimeHelper
subject(:financial_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } }
@ -208,47 +210,28 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
describe "#validate_percentage_bought_not_equal_percentage_owned" do
let(:record) { FactoryBot.build(:sales_log) }
context "with 24/25 logs" do
before do
record.saledate = Time.zone.local(2024, 4, 3)
end
it "does not add an error if the percentage bought is less than the percentage owned" do
record.stairbought = 20
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
it "adds an error if the percentage bought is equal to the percentage owned" do
record.stairbought = 30
record.stairowned = 30
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors["stairowned"]).to eq([I18n.t("validations.sales.financial.stairowned.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)])
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)])
end
let(:record) { FactoryBot.build(:sales_log, :saledate_today) }
it "does not add an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do
record.stairbought = 50
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
it "does not add an error if the percentage bought is less than the percentage owned" do
record.stairbought = 20
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
context "with 23/24 logs" do
before do
record.saledate = Time.zone.local(2023, 4, 3)
end
it "adds an error if the percentage bought is equal to the percentage owned" do
record.stairbought = 30
record.stairowned = 30
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors["stairowned"]).to eq([I18n.t("validations.sales.financial.stairowned.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)])
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)])
end
it "does not add an error if the percentage bought is equal to the percentage owned" do
record.stairbought = 30
record.stairowned = 30
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
it "does not add an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do
record.stairbought = 50
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
end
@ -348,195 +331,151 @@ RSpec.describe Validations::Sales::FinancialValidations do
describe "#validate_equity_in_range_for_year_and_type" do
let(:record) { FactoryBot.build(:sales_log, saledate:, resale: nil) }
context "with a log in the 22/23 collection year" do
let(:saledate) { Time.zone.local(2023, 1, 1) }
it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25))
end
it "adds an error for type 30, equity below min with the correct percentage" do
record.type = 30
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10))
end
it "does not add an error for equity in range with the correct percentage" do
record.type = 2
record.equity = 50
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "adds an error for equity above max with the correct percentage" do
record.type = 2
record.equity = 90
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75))
end
let(:saledate) { current_collection_start_date }
it "does not add an error if it's a resale" do
record.type = 2
record.equity = 90
record.resale = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25))
end
context "with a log in 23/24 collection year" do
let(:saledate) { Time.zone.local(2024, 1, 1) }
it "adds an error for type 30, equity below min with the correct percentage" do
record.type = 30
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10))
end
it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25))
end
it "adds an error for type 18, low equity below min with the correct percentage" do
record.type = 18
record.equity = 10
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25))
end
it "adds an error for type 30, equity below min with the correct percentage" do
record.type = 30
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10))
end
it "does not add an error for type 30, low equity in range with the correct percentage" do
record.type = 30
record.equity = 10
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "does not add an error for equity in range with the correct percentage" do
record.type = 2
record.equity = 50
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "does not add an error for equity in range with the correct percentage" do
record.type = 2
record.equity = 50
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "adds an error for equity above max with the correct percentage" do
record.type = 2
record.equity = 90
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75))
end
it "adds an error for equity above max with the correct percentage" do
record.type = 2
record.equity = 90
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75))
expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75))
end
end
describe "#validate_staircase_difference" do
let(:record) { FactoryBot.build(:sales_log, saledate:) }
context "with a log in the 23/24 collection year" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:saledate) { current_collection_start_date }
it "does not add an error" do
record.stairbought = 2
record.stairowned = 3
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "adds errors if equity is more than stairowned - stairbought for joint purchase" do
record.stairbought = 2.5
record.stairowned = 3
record.equity = 2
record.jointpur = 1
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
end
context "with a log in 24/25 collection year" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
it "adds errors if equity is more than stairowned - stairbought for joint purchase" do
record.stairbought = 2.5
record.stairowned = 3
record.equity = 2
record.jointpur = 1
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5))
end
it "adds errors if equity is more than stairowned - stairbought for non joint purchase" do
record.stairbought = 2
record.stairowned = 3
record.equity = 2.5
record.jointpur = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
end
it "adds errors if equity is more than stairowned - stairbought for non joint purchase" do
record.stairbought = 2
record.stairowned = 3
record.equity = 2.5
record.jointpur = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0))
end
it "does not add errors if equity is less than stairowned - stairbought and stairnum is nil" do
record.stairbought = 2
record.stairowned = 10
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if equity is less than stairowned - stairbought and stairnum is nil" do
record.stairbought = 2
record.stairowned = 10
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if equity is equal stairowned - stairbought and stairnum is nil" do
record.stairbought = 2
record.stairowned = 10
record.equity = 8
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if equity is equal stairowned - stairbought and stairnum is nil" do
record.stairbought = 2
record.stairowned = 10
record.equity = 8
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairbought is not given" do
record.stairbought = nil
record.stairowned = 10
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairbought is not given" do
record.stairbought = nil
record.stairowned = 10
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairowned is not given" do
record.stairbought = 2
record.stairowned = nil
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairowned is not given" do
record.stairbought = 2
record.stairowned = nil
record.equity = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if equity is not given" do
record.stairbought = 2
record.stairowned = 10
record.equity = 0
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if equity is not given" do
record.stairbought = 2
record.stairowned = 10
record.equity = 0
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "adds errors if stairnum is present and stairowned is not enough more than stairbought + equity" do
record.stairowned = 20
record.stairbought = 10
record.equity = 9
record.numstair = 3
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.more_than_stairowned_minus_stairbought_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.less_than_stairbought_plus_equity_plus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.more_than_stairowned_minus_equity_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["numstair"]).to include(I18n.t("validations.sales.financial.numstair.too_high_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["firststair"]).to include(I18n.t("validations.sales.financial.firststair.invalid_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
end
it "adds errors if stairnum is present and stairowned is not enough more than stairbought + equity" do
record.stairowned = 20
record.stairbought = 10
record.equity = 9
record.numstair = 3
financial_validator.validate_staircase_difference(record)
expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.more_than_stairowned_minus_stairbought_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.less_than_stairbought_plus_equity_plus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.more_than_stairowned_minus_equity_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["numstair"]).to include(I18n.t("validations.sales.financial.numstair.too_high_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
expect(record.errors["firststair"]).to include(I18n.t("validations.sales.financial.firststair.invalid_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20))
end
it "does not add errors if stairnum is present and stairowned is enough more than stairbought + equity" do
record.stairowned = 25
record.stairbought = 10
record.equity = 9
record.numstair = 3
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairnum is present and stairowned is enough more than stairbought + equity" do
record.stairowned = 25
record.stairbought = 10
record.equity = 9
record.numstair = 3
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairnum is present and stairowned exactly equals minimum" do
record.stairowned = 20
record.stairbought = 10
record.equity = 9
record.numstair = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
it "does not add errors if stairnum is present and stairowned exactly equals minimum" do
record.stairowned = 20
record.stairbought = 10
record.equity = 9
record.numstair = 2
financial_validator.validate_staircase_difference(record)
expect(record.errors).to be_empty
end
end
end

389
spec/models/validations/sales/household_validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Validations::Sales::HouseholdValidations do
include CollectionTimeHelper
subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } }
@ -8,272 +10,112 @@ RSpec.describe Validations::Sales::HouseholdValidations do
let(:saledate) { Time.zone.now }
describe "#validate_partner_count" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:saledate) { current_collection_start_date }
it "validates that only 1 partner exists" do
it "does not validate for years >= 2024" do
record.relat2 = "P"
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.relat.one_partner"))
expect(record.errors["relat3"])
.to include(match I18n.t("validations.sales.household.relat.one_partner"))
expect(record.errors["relat4"])
.not_to include(match I18n.t("validations.sales.household.relat.one_partner"))
end
it "expects that a tenant can have a partner" do
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["base"]).to be_empty
expect(record.errors["relat2"]).to be_empty
expect(record.errors["relat3"]).to be_empty
expect(record.errors["relat4"]).to be_empty
end
end
describe "#validate_person_age_matches_relationship" do
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
context "when the household contains a person under 16" do
it "expects that person is a child of the tenant" do
record.age2 = 14
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
let(:saledate) { current_collection_start_date }
it "validates that a person under 16 must not be a partner of the buyer" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.relat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_under_16", person_num: 2))
end
end
it "validates that a person over 20 must not be a child of the buyer" do
record.age2 = 21
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.relat.child_over_20"))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_over_20"))
end
it "does not add error if person under 16 is a partner" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
context "with 2024 logs" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
it "does not add error if person under 16 is a partner" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add error if person over 19 is a child" do
record.age2 = 20
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
it "does not add error if person over 19 is a child" do
record.age2 = 20
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
describe "#validate_person_age_matches_economic_status" do
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:saledate) { current_collection_start_date }
it "validates that person's economic status must be Child" do
record.age2 = 14
record.ecstat2 = 1
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.sales.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_under_16_ecstat", person_num: 2))
end
it "expects that person's economic status is Child" do
record.age2 = 14
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "validates that a person with economic status 'child' must be under 16" do
record.age2 = 21
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.sales.household.ecstat.child_over_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_over_16", person_num: 2))
end
end
context "with 2024 logs" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
it "does not run the validation" do
record.age2 = 14
record.ecstat2 = 1
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.not_to include(match I18n.t("validations.sales.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.not_to include(match I18n.t("validations.sales.household.age.child_under_16_ecstat", person_num: 2))
end
it "validates that a person with economic status 'child' must be under 16" do
record.age2 = 21
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.sales.household.ecstat.child_over_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_over_16", person_num: 2))
end
end
describe "#validate_child_12_years_younger" do
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
it "validates the child is at least 12 years younger than buyer 1" do
record.age1 = 30
record.age2 = record.age1 - 11
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age1"])
.to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2))
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2))
end
it "expects the child is at least 12 years younger than buyer 1" do
record.age1 = 30
record.age2 = record.age1 - 12
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age1"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relate2"]).to be_empty
end
end
context "with 2024 logs" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
let(:saledate) { current_collection_start_date }
it "does not validate that child is at least 12 year younger than buyer" do
record.age1 = 20
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age1"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
it "does not validate that child is at least 12 year younger than buyer" do
record.age1 = 20
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age1"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
describe "#validate_person_age_and_relationship_matches_economic_status" do
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:saledate) { current_collection_start_date }
it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 18
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "adds errors for a person aged 16-19 who is a child of the buyer but not a student" do
context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" do
record.age2 = 17
record.ecstat2 = "1"
record.relat2 = "C"
record.ecstat2 = 1
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.relat.student_16_19.cannot_be_child.16_19_not_student"))
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.student_16_19.cannot_be_16_19.child_not_student"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.sales.household.ecstat.student_16_19.must_be_student"))
end
it "adds errors for a person who is a child of the buyer and a student but not aged 16-19" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.sales.household.relat.student_16_19.cannot_be_child.student_not_16_19"))
.to be_empty
expect(record.errors["age2"])
.to include(match I18n.t("validations.sales.household.age.student_16_19.must_be_16_19"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.sales.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
.to be_empty
expect(record.errors["relat2"])
.to be_empty
end
end
context "with 2024 logs" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 1
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to be_empty
expect(record.errors["age2"])
.to be_empty
expect(record.errors["relat2"])
.to be_empty
end
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add errors" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add errors for a person who is a student and aged 16-19 but not child" do
record.age2 = 17
record.ecstat2 = "7"
record.relat2 = "X"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add errors" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add errors for a person who is a student and aged 16-19 but not child" do
record.age2 = 17
record.ecstat2 = "7"
record.relat2 = "X"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
end
@ -310,16 +152,12 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(sales_log.errors).to be_empty
end
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
it "triggers a validation if buyer two will also not live in the property" do
sales_log.buy2livein = 2
household_validator.validate_buyers_living_in_property(sales_log)
expect(sales_log.errors[:buylivein]).to include I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent")
expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.sales.household.buy2livein.buyers_will_live_in_property_values_inconsistent")
expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent")
end
it "triggers a validation if buyer two will also not live in the property" do
sales_log.buy2livein = 2
household_validator.validate_buyers_living_in_property(sales_log)
expect(sales_log.errors[:buylivein]).to include I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent")
expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.sales.household.buy2livein.buyers_will_live_in_property_values_inconsistent")
expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent")
end
end
@ -383,60 +221,31 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(record.errors).to be_empty
end
end
context "with 23/24 logs" do
let(:saledate) { Time.zone.local(2023, 4, 4) }
it "does not add an error for outright sale" do
record.ownershipsch = 2
[1, 2, 3, 4, 5, 6, 7, 9, 0].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
end
end
end
describe "#validate_buyer_not_child" do
context "with 2023 logs" do
let(:saledate) { Time.zone.local(2023, 4, 1) }
it "does not add an error if either buyer is a child" do
record.jointpur = 1
record.ecstat1 = 9
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat1"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
end
end
context "with 2024 logs" do
let(:saledate) { Time.zone.local(2024, 4, 1) }
let(:saledate) { current_collection_start_date }
it "validates buyer 1 isn't a child" do
record.ecstat1 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat1"])
.to include("Buyer 1 cannot have a working situation of child under 16.")
end
it "validates buyer 1 isn't a child" do
record.ecstat1 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat1"])
.to include("Buyer 1 cannot have a working situation of child under 16.")
end
it "validates buyer 2 isn't a child" do
record.jointpur = 1
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"])
.to include("Buyer 2 cannot have a working situation of child under 16.")
end
it "validates buyer 2 isn't a child" do
record.jointpur = 1
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"])
.to include("Buyer 2 cannot have a working situation of child under 16.")
end
it "allows person 2 to be a child" do
record.jointpur = 2
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"]).to be_empty
end
it "allows person 2 to be a child" do
record.jointpur = 2
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"]).to be_empty
end
end
end

75
spec/models/validations/sales/property_validations_spec.rb

@ -1,80 +1,21 @@
require "rails_helper"
RSpec.describe Validations::Sales::PropertyValidations do
include CollectionTimeHelper
subject(:property_validator) { property_validator_class.new }
let(:property_validator_class) { Class.new { include Validations::Sales::PropertyValidations } }
describe "#validate_postcodes_match_if_discounted_ownership" do
context "when ownership scheme is not discounted ownership" do
let(:record) { build(:sales_log, ownershipsch: 1) }
it "when postcodes match no error is added" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 1AA"
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
end
end
context "when ownership scheme is discounted ownership" do
let(:record) { build(:sales_log, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 5)) }
it "when ppostcode_full is not present no error is added" do
record.postcode_full = "SW1A 1AA"
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
expect(record.errors["ownershipsch"]).to be_empty
end
let(:record) { build(:sales_log, ownershipsch: 1, saledate: current_collection_start_date) }
it "when postcode_full is not present no error is added" do
record.ppostcode_full = "SW1A 1AA"
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
expect(record.errors["ownershipsch"]).to be_empty
end
it "when postcodes match no error is added" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 1AA"
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
expect(record.errors["ownershipsch"]).to be_empty
end
it "when postcodes do not match an error is added for joint purchase" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.jointpur = 1
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.")
expect(record.errors["ppostcode_full"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.")
expect(record.errors["ownershipsch"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.")
end
it "when postcodes do not match an error is added for non joint purchase" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.jointpur = 2
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.")
expect(record.errors["ppostcode_full"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.")
expect(record.errors["ownershipsch"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.")
end
it "is not validated for years >= 2024" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
it "does not add error for 2024 log" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.saledate = Time.zone.local(2024, 4, 5)
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
expect(record.errors["ownershipsch"]).to be_empty
end
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
end
end

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

File diff suppressed because it is too large Load Diff

93
spec/models/validations/sales/soft_validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Validations::Sales::SoftValidations do
include CollectionTimeHelper
let(:record) { build(:sales_log) }
describe "income validations" do
@ -404,87 +406,16 @@ RSpec.describe Validations::Sales::SoftValidations do
end
context "when validating extra borrowing" do
context "when the log is for 2023" do
let(:record) { build(:sales_log, saledate: Time.zone.local(2023, 12, 1)) }
it "returns false if extrabor not present" do
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if mortgage not present" do
record.extrabor = 2
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if deposit not present" do
record.extrabor = 2
record.mortgage = 50_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if value not present" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if discount not present" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns false if extra borrowing expected and reported" do
record.extrabor = 1
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
it "returns true if extra borrowing expected but not reported" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.to be_extra_borrowing_expected_but_not_reported
end
end
context "when the log is for 2024" do
let(:record) { build(:sales_log, saledate: Time.zone.local(2024, 12, 1)) }
it "returns false for logs from 2024 onwards" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
let(:record) { build(:sales_log, saledate: previous_collection_start_date) }
it "returns false for logs from 2024 onwards" do
record.extrabor = 2
record.mortgage = 50_000
record.deposit = 40_000
record.value = 100_000
record.discount = 11
expect(record)
.not_to be_extra_borrowing_expected_but_not_reported
end
end
end

98
spec/requests/collection_resources_controller_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe CollectionResourcesController, type: :request do
include CollectionTimeHelper
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil, delete_file: nil) }
@ -56,10 +58,10 @@ RSpec.describe CollectionResourcesController, type: :request do
it "displays collection resources" do
get collection_resources_path
expect(page).to have_content("Lettings 2024 to 2025")
expect(page).to have_content("Lettings 2025 to 2026")
expect(page).to have_content("Sales 2024 to 2025")
expect(page).to have_content("Sales 2025 to 2026")
expect(page).to have_content("Lettings #{next_collection_start_year} to #{next_collection_end_year}")
expect(page).to have_content("Lettings #{current_collection_start_year} to #{current_collection_end_year}")
expect(page).to have_content("Sales #{next_collection_start_year} to #{next_collection_end_year}")
expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}")
end
it "displays mandatory files" do
@ -73,10 +75,10 @@ RSpec.describe CollectionResourcesController, type: :request do
it "allows uploading new resources" do
get collection_resources_path
expect(page).to have_link("Add new sales 2024 to 2025 resource", href: new_collection_resource_path(year: 2024, log_type: "sales"))
expect(page).to have_link("Add new lettings 2024 to 2025 resource", href: new_collection_resource_path(year: 2024, log_type: "lettings"))
expect(page).to have_link("Add new sales 2025 to 2026 resource", href: new_collection_resource_path(year: 2025, log_type: "sales"))
expect(page).to have_link("Add new lettings 2025 to 2026 resource", href: new_collection_resource_path(year: 2025, log_type: "lettings"))
expect(page).to have_link("Add new sales #{next_collection_start_year} to #{next_collection_end_year} resource", href: new_collection_resource_path(year: next_collection_start_year, log_type: "sales"))
expect(page).to have_link("Add new lettings #{next_collection_start_year} to #{next_collection_end_year} resource", href: new_collection_resource_path(year: next_collection_start_year, log_type: "lettings"))
expect(page).to have_link("Add new sales #{current_collection_start_year} to #{current_collection_end_year} resource", href: new_collection_resource_path(year: current_collection_start_year, log_type: "sales"))
expect(page).to have_link("Add new lettings #{current_collection_start_year} to #{current_collection_end_year} resource", href: new_collection_resource_path(year: current_collection_start_year, log_type: "lettings"))
end
context "when files are on S3" do
@ -86,36 +88,36 @@ RSpec.describe CollectionResourcesController, type: :request do
end
it "displays file names with download links" do
expect(page).to have_link("2024_25_lettings_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("bulk-upload-lettings-template-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("bulk-upload-lettings-specification-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("2024_25_sales_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("bulk-upload-sales-template-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("bulk-upload-sales-specification-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("2025_26_lettings_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("bulk-upload-lettings-template-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("bulk-upload-lettings-specification-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("2025_26_sales_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("bulk-upload-sales-template-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("bulk-upload-sales-specification-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
end
it "displays change links" do
expect(page).to have_selector(:link_or_button, "Change", count: 12)
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
end
context "when the collection year has not started yet" do
@ -157,19 +159,19 @@ RSpec.describe CollectionResourcesController, type: :request do
it "displays upload links" do
expect(page).to have_selector(:link_or_button, "Upload", count: 12)
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification"))
end
context "when the collection year has not started yet" do
@ -333,9 +335,9 @@ RSpec.describe CollectionResourcesController, type: :request do
end
it "displays update collection resources page content" do
get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")
get edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")
expect(page).to have_content("Sales 2024 to 2025")
expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}")
expect(page).to have_content("Change the bulk upload template")
expect(page).to have_content("This file will be available for all users to download.")
expect(page).to have_content("Upload file")
@ -351,9 +353,9 @@ RSpec.describe CollectionResourcesController, type: :request do
end
it "displays upload collection resources page content" do
get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")
get edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")
expect(page).to have_content("Sales 2024 to 2025")
expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}")
expect(page).to have_content("Upload the bulk upload template")
expect(page).to have_content("This file will be available for all users to download.")
expect(page).to have_content("Upload file")

165
spec/requests/duplicate_logs_controller_spec.rb

@ -4,19 +4,9 @@ RSpec.describe DuplicateLogsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { create(:user, :data_coordinator) }
let(:lettings_log) { create(:lettings_log, :duplicate, assigned_to: user) }
let(:sales_log) { create(:sales_log, :duplicate, assigned_to: user) }
let(:sales_log) { create(:sales_log, :duplicate, staircase: 2, assigned_to: user) }
describe "GET show" do
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when user is not signed in" do
it "redirects to sign in page" do
get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
@ -64,11 +54,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("- Tenancy start date", count: 3)
expect(page).to have_content("- Tenant code", count: 3)
expect(page).to have_content("- Lead tenant’s age", count: 3)
expect(page).to have_content("- Lead tenant’s gender identity", count: 3)
expect(page).to have_content("- Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 24)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
@ -81,12 +71,12 @@ RSpec.describe DuplicateLogsController, type: :request do
duplicate_logs[0].update!(uprn: "123", uprn_known: 1, uprn_confirmed: 1, manual_address_entry_selected: false)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("- Tenancy start date", count: 3)
expect(page).to have_content("- Tenant code", count: 3)
expect(page).to have_content("Postcode (from UPRN)", count: 2)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("- Lead tenant’s age", count: 3)
expect(page).to have_content("- Lead tenant’s gender identity", count: 3)
expect(page).to have_content("- Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 24)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
@ -110,11 +100,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("- Tenancy start date", count: 1)
expect(page).to have_content("- Tenant code", count: 1)
expect(page).to have_content("- Lead tenant’s age", count: 1)
expect(page).to have_content("- Lead tenant’s gender identity", count: 1)
expect(page).to have_content("- Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 8)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
@ -136,11 +126,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("- Tenancy start date", count: 1)
expect(page).to have_content("- Tenant code", count: 1)
expect(page).to have_content("- Lead tenant’s age", count: 1)
expect(page).to have_content("- Lead tenant’s gender identity", count: 1)
expect(page).to have_content("- Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 8)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
@ -173,12 +163,13 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3)
expect(page).to have_content("- Owning organisation", count: 3)
expect(page).to have_content("- Sale completion date", count: 3)
expect(page).to have_content("- Purchaser code", count: 3)
expect(page).to have_content("- Buyer 1’s age", count: 3)
expect(page).to have_content("- Buyer 1’s gender identity", count: 3)
expect(page).to have_content("- Buyer 1’s working situation", count: 3)
expect(page).to have_content("- Postcode", count: 3)
expect(page).to have_link("Change", count: 21)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
@ -191,11 +182,11 @@ RSpec.describe DuplicateLogsController, type: :request do
duplicate_logs[1].update!(uprn: "123", uprn_known: 1, manual_address_entry_selected: false)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3)
expect(page).to have_content("- Sale completion date", count: 3)
expect(page).to have_content("- Purchaser code", count: 3)
expect(page).to have_content("- Buyer 1’s age", count: 3)
expect(page).to have_content("- Buyer 1’s gender identity", count: 3)
expect(page).to have_content("- Buyer 1’s working situation", count: 3)
expect(page).to have_content("Postcode (from UPRN)", count: 3)
expect(page).to have_link("Change", count: 21)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
@ -219,12 +210,12 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_content("- Sale completion date", count: 1)
expect(page).to have_content("- Purchaser code", count: 1)
expect(page).to have_content("- Buyer 1’s age", count: 1)
expect(page).to have_content("- Buyer 1’s gender identity", count: 1)
expect(page).to have_content("- Buyer 1’s working situation", count: 1)
expect(page).to have_content("- Postcode", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
@ -245,12 +236,12 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_content("- Sale completion date", count: 1)
expect(page).to have_content("- Purchaser code", count: 1)
expect(page).to have_content("- Buyer 1’s age", count: 1)
expect(page).to have_content("- Buyer 1’s gender identity", count: 1)
expect(page).to have_content("- Buyer 1’s working situation", count: 1)
expect(page).to have_content("- Postcode", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
@ -289,11 +280,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("- Tenancy start date", count: 3)
expect(page).to have_content("- Tenant code", count: 3)
expect(page).to have_content("- Lead tenant’s age", count: 3)
expect(page).to have_content("- Lead tenant’s gender identity", count: 3)
expect(page).to have_content("- Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 21)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
@ -317,11 +308,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("- Tenancy start date", count: 1)
expect(page).to have_content("- Tenant code", count: 1)
expect(page).to have_content("- Lead tenant’s age", count: 1)
expect(page).to have_content("- Lead tenant’s gender identity", count: 1)
expect(page).to have_content("- Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
@ -343,11 +334,11 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("- Tenancy start date", count: 1)
expect(page).to have_content("- Tenant code", count: 1)
expect(page).to have_content("- Lead tenant’s age", count: 1)
expect(page).to have_content("- Lead tenant’s gender identity", count: 1)
expect(page).to have_content("- Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
@ -380,12 +371,12 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3)
expect(page).to have_content("- Sale completion date", count: 3)
expect(page).to have_content("- Purchaser code", count: 3)
expect(page).to have_content("- Buyer 1’s age", count: 3)
expect(page).to have_content("- Buyer 1’s gender identity", count: 3)
expect(page).to have_content("- Buyer 1’s working situation", count: 3)
expect(page).to have_content("- Postcode", count: 3)
expect(page).to have_link("Change", count: 18)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
@ -408,12 +399,12 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_content("- Sale completion date", count: 1)
expect(page).to have_content("- Purchaser code", count: 1)
expect(page).to have_content("- Buyer 1’s age", count: 1)
expect(page).to have_content("- Buyer 1’s gender identity", count: 1)
expect(page).to have_content("- Buyer 1’s working situation", count: 1)
expect(page).to have_content("- Postcode", count: 1)
expect(page).to have_link("Change", count: 6)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
@ -434,12 +425,12 @@ RSpec.describe DuplicateLogsController, type: :request do
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_content("- Sale completion date", count: 1)
expect(page).to have_content("- Purchaser code", count: 1)
expect(page).to have_content("- Buyer 1’s age", count: 1)
expect(page).to have_content("- Buyer 1’s gender identity", count: 1)
expect(page).to have_content("- Buyer 1’s working situation", count: 1)
expect(page).to have_content("- Postcode", count: 1)
expect(page).to have_link("Change", count: 6)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end

188
spec/services/csv/lettings_log_csv_service_spec.rb

@ -579,194 +579,6 @@ RSpec.describe Csv::LettingsLogCsvService do
end
end
end
context "when the requested log year is 2023" do
let(:year) { 2023 }
let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") }
let(:log) do
create(
:lettings_log,
:ignore_validation_errors,
created_by: user,
assigned_to: user,
created_at: Time.zone.local(2023, 11, 26),
updated_at: Time.zone.local(2023, 11, 26),
owning_organisation: organisation,
managing_organisation: organisation,
needstype: 1,
renewal: 0,
startdate: Time.zone.local(2023, 11, 26),
rent_type: 1,
tenancycode: "HIJKLMN",
propcode: "ABCDEFG",
declaration: 1,
address_line1: "Address line 1",
town_or_city: "London",
postcode_full: "NW9 5LL",
la: "E09000003",
is_la_inferred: false,
first_time_property_let_as_social_housing: 0,
unitletas: 2,
rsnvac: 6,
offered: 2,
unittype_gn: 7,
builtype: 1,
wchair: 1,
beds: 3,
voiddate: Time.zone.local(2023, 11, 24),
majorrepairs: 1,
mrcdate: Time.zone.local(2023, 11, 25),
joint: 3,
startertenancy: 1,
tenancy: 4,
tenancylength: 2,
hhmemb: 4,
age1_known: 0,
age1: 35,
sex1: "F",
ethnic_group: 0,
ethnic: 2,
national: 13,
ecstat1: 0,
details_known_2: 0,
relat2: "P",
age2_known: 0,
age2: 32,
sex2: "M",
ecstat2: 6,
details_known_3: 1,
details_known_4: 0,
relat4: "R",
age4_known: 1,
sex4: "R",
ecstat4: 10,
armedforces: 1,
leftreg: 4,
reservist: 1,
preg_occ: 2,
housingneeds: 1,
housingneeds_type: 0,
housingneeds_a: 1,
housingneeds_b: 0,
housingneeds_c: 0,
housingneeds_f: 0,
housingneeds_g: 0,
housingneeds_h: 0,
housingneeds_other: 0,
illness: 1,
illness_type_1: 0,
illness_type_2: 1,
illness_type_3: 0,
illness_type_4: 0,
illness_type_5: 0,
illness_type_6: 0,
illness_type_7: 0,
illness_type_8: 0,
illness_type_9: 0,
illness_type_10: 0,
layear: 2,
waityear: 7,
reason: 4,
prevten: 6,
homeless: 1,
ppcodenk: 1,
ppostcode_full: "TN23 6LZ",
previous_la_known: 1,
prevloc: "E07000105",
reasonpref: 1,
rp_homeless: 0,
rp_insan_unsat: 1,
rp_medwel: 0,
rp_hardship: 0,
rp_dontknow: 0,
cbl: 0,
chr: 1,
cap: 0,
accessible_register: 0,
referral: 2,
net_income_known: 0,
incref: 0,
incfreq: 1,
earnings: 268,
hb: 6,
has_benefits: 1,
benefits: 1,
period: 2,
brent: 200,
scharge: 50,
pscharge: 40,
supcharg: 35,
tcharge: 325,
hbrentshortfall: 1,
tshortfall_known: 1,
tshortfall: 12,
)
end
context "when exporting with human readable labels" do
let(:export_type) { "labels" }
context "when the current user is a support user" do
let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") }
it "exports the CSV with all values correct" do
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv")
values_to_delete = %w[id]
values_to_delete.each do |attribute|
index = attribute_line.index(attribute)
content_line[index] = nil
end
expect(csv).to eq expected_content
end
end
context "when the current user is not a support user" do
let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") }
it "exports the CSV with all values correct" do
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv")
values_to_delete = %w[id]
values_to_delete.each do |attribute|
index = attribute_line.index(attribute)
content_line[index] = nil
end
expect(csv).to eq expected_content
end
end
end
context "when exporting values as codes" do
let(:export_type) { "codes" }
context "when the current user is a support user" do
let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") }
it "exports the CSV with all values correct" do
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv")
values_to_delete = %w[id]
values_to_delete.each do |attribute|
index = attribute_line.index(attribute)
content_line[index] = nil
end
expect(csv).to eq expected_content
end
end
context "when the current user is not a support user" do
let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") }
it "exports the CSV with all values correct" do
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv")
values_to_delete = %w[id]
values_to_delete.each do |attribute|
index = attribute_line.index(attribute)
content_line[index] = nil
end
expect(csv).to eq expected_content
end
end
end
end
end
end
end

12
spec/services/documentation_generator_spec.rb

@ -155,8 +155,8 @@ describe DocumentationGenerator do
context "when the service is run for lettings" do
let(:log_type) { "lettings" }
let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "lettings")] }
let(:row_parser_class) { BulkUpload::Lettings::Year2023::RowParser }
let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2025, "lettings")] }
let(:row_parser_class) { BulkUpload::Lettings::Year2025::RowParser }
it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
@ -167,7 +167,7 @@ describe DocumentationGenerator do
expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode")
expect(any_validation.case).to eq("Previous postcode is known and current postcode is blank")
expect(any_validation.collection_year).to eq("2023/2024")
expect(any_validation.collection_year).to eq("2025/2026")
expect(any_validation.validation_type).to eq("format")
expect(any_validation.hard_soft).to eq("hard")
expect(any_validation.other_validated_models).to eq("User")
@ -207,8 +207,8 @@ describe DocumentationGenerator do
context "when the service is run for sales" do
let(:log_type) { "sales" }
let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "sales")] }
let(:row_parser_class) { BulkUpload::Sales::Year2023::RowParser }
let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2025, "sales")] }
let(:row_parser_class) { BulkUpload::Sales::Year2025::RowParser }
it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
@ -219,7 +219,7 @@ describe DocumentationGenerator do
expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode")
expect(any_validation.case).to eq("Previous postcode is known and current postcode is blank")
expect(any_validation.collection_year).to eq("2023/2024")
expect(any_validation.collection_year).to eq("2025/2026")
expect(any_validation.validation_type).to eq("format")
expect(any_validation.hard_soft).to eq("hard")
expect(any_validation.other_validated_models).to eq("User")

Loading…
Cancel
Save