Browse Source

Merge remote-tracking branch 'origin/CLDC-3758-Add-shared-ownership-staircasing-transaction' into CLDC-3758-Add-shared-ownership-staircasing-transaction

pull/2788/head
Manny Dinssa 7 months ago
parent
commit
a0a02dcc27
  1. 5
      app/models/form/lettings/pages/no_address_found.rb
  2. 12
      app/models/form/sales/pages/handover_date_check.rb
  3. 15
      app/models/form/sales/subsections/household_situation.rb
  4. 15
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 15
      app/models/form/sales/subsections/other_household_information.rb
  6. 4
      app/models/form/section.rb
  7. 27
      app/models/validations/property_validations.rb
  8. 16
      app/models/validations/sales/property_validations.rb
  9. 5
      app/models/validations/sales/sale_information_validations.rb
  10. 6
      app/models/validations/sales/soft_validations.rb
  11. 5
      app/views/logs/_tasklist.html.erb
  12. 8
      config/locales/forms/2024/lettings/soft_validations.en.yml
  13. 17
      config/locales/validations/lettings/property_information.en.yml
  14. 11
      config/locales/validations/sales/property_information.en.yml
  15. 2
      config/locales/validations/sales/sale_information.en.yml
  16. 7
      spec/models/form/lettings/pages/no_address_found_spec.rb
  17. 82
      spec/models/form/sales/pages/handover_date_check_spec.rb
  18. 22
      spec/models/form/sales/subsections/household_situation_spec.rb
  19. 29
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  20. 62
      spec/models/form/sales/subsections/other_household_information_spec.rb
  21. 74
      spec/models/validations/property_validations_spec.rb
  22. 56
      spec/models/validations/sales/property_validations_spec.rb
  23. 5
      spec/models/validations/sales/sale_information_validations_spec.rb

5
app/models/form/lettings/pages/no_address_found.rb

@ -3,12 +3,13 @@ class Form::Lettings::Pages::NoAddressFound < ::Form::Page
super
@id = "no_address_found"
@type = "interruption_screen"
@copy_key = "lettings.soft_validations.no_address_found"
@title_text = {
"translation" => "soft_validations.no_address_found.title_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [],
}
@informative_text = {
"translation" => "soft_validations.no_address_found.informative_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
@depends_on = [

12
app/models/form/sales/pages/handover_date_check.rb

@ -3,8 +3,6 @@ class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
super
@id = "handover_date_check"
@copy_key = "sales.soft_validations.hodate_check"
@depends_on = [{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
@informative_text = {}
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
@ -12,6 +10,16 @@ class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
}
end
def depends_on
if form.start_year_2025_or_later?
[{ "saledate_check" => nil, "hodate_5_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_5_years_or_more_saledate?" => true }]
else
[{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
end
end
def questions
@questions ||= [
Form::Sales::Questions::HandoverDateCheck.new(nil, nil, self),

15
app/models/form/sales/subsections/household_situation.rb

@ -3,7 +3,14 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
super
@id = "household_situation"
@label = "Household situation"
@depends_on = [{ "setup_completed?" => true }]
end
def depends_on
if form.start_year_2025_or_later?
[{ "setup_completed?" => true, "is_staircase?" => false }]
else
[{ "setup_completed?" => true }]
end
end
def pages
@ -16,4 +23,10 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
Form::Sales::Pages::Buyer2PreviousHousingSituation.new(nil, nil, self),
].flatten.compact
end
def displayed_in_tasklist?(log)
return true unless form.start_year_2025_or_later?
log.staircase != 1
end
end

15
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -3,7 +3,14 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
super
@id = "income_benefits_and_savings"
@label = "Income, benefits and savings"
@depends_on = [{ "setup_completed?" => true }]
end
def depends_on
if form.start_year_2025_or_later?
[{ "setup_completed?" => true, "is_staircase?" => false }]
else
[{ "setup_completed?" => true }]
end
end
def pages
@ -36,6 +43,12 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
].compact
end
def displayed_in_tasklist?(log)
return true unless form.start_year_2025_or_later?
log.staircase != 1
end
private
def previous_shared_page

15
app/models/form/sales/subsections/other_household_information.rb

@ -3,7 +3,14 @@ class Form::Sales::Subsections::OtherHouseholdInformation < ::Form::Subsection
super
@id = "other_household_information"
@label = "Other household information"
@depends_on = [{ "setup_completed?" => true }]
end
def depends_on
if form.start_year_2025_or_later?
[{ "setup_completed?" => true, "is_staircase?" => false }]
else
[{ "setup_completed?" => true }]
end
end
def pages
@ -17,4 +24,10 @@ class Form::Sales::Subsections::OtherHouseholdInformation < ::Form::Subsection
Form::Sales::Pages::HouseholdWheelchairCheck.new("wheelchair_check", nil, self),
]
end
def displayed_in_tasklist?(log)
return true unless form.start_year_2025_or_later?
log.staircase != 1
end
end

4
app/models/form/section.rb

@ -10,4 +10,8 @@ class Form::Section
@subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) }
end
end
def displayed_in_tasklist?(log)
subsections.any? { |subsection| subsection.displayed_in_tasklist?(log) }
end
end

27
app/models/validations/property_validations.rb

@ -46,4 +46,31 @@ module Validations::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message
end
end
def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later?
if record.is_general_needs?
return unless record.la
return if record.la.in?(LocalAuthority.england.pluck(:code))
record.errors.add :la, I18n.t("validations.lettings.property.la.not_in_england")
record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.not_in_england")
record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.not_in_england")
record.errors.add :uprn_confirmation, I18n.t("validations.lettings.property.uprn_confirmation.not_in_england")
record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.not_in_england")
if record.uprn.present?
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.address_not_in_england")
else
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.postcode_not_in_england")
end
elsif record.is_supported_housing?
return unless record.location
return if record.location.location_code.in?(LocalAuthority.england.pluck(:code))
record.errors.add :location_id, I18n.t("validations.lettings.property.location_id.not_in_england")
record.errors.add :scheme_id, I18n.t("validations.lettings.property.scheme_id.not_in_england")
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.location_not_in_england")
end
end
end

16
app/models/validations/sales/property_validations.rb

@ -36,4 +36,20 @@ module Validations::Sales::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message
end
end
def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later? && record.la.present?
return if record.la.in?(LocalAuthority.england.pluck(:code))
record.errors.add :la, I18n.t("validations.sales.property_information.la.not_in_england")
record.errors.add :postcode_full, I18n.t("validations.sales.property_information.postcode_full.not_in_england")
record.errors.add :uprn, I18n.t("validations.sales.property_information.uprn.not_in_england")
record.errors.add :uprn_confirmation, I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england")
record.errors.add :uprn_selection, I18n.t("validations.sales.property_information.uprn_selection.not_in_england")
if record.uprn.present?
record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.address_not_in_england")
else
record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.postcode_not_in_england")
end
end
end

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

@ -12,7 +12,10 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_after_hodate")
end
if record.saledate - record.hodate >= 3.years && record.form.start_year_2024_or_later?
if (record.saledate - 5.years) >= record.hodate && record.form.start_year_2025_or_later?
record.errors.add :hodate, I18n.t("validations.sales.sale_information.hodate.must_be_less_than_5_years_from_saledate")
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_less_than_5_years_from_hodate")
elsif (record.saledate - 3.years) >= record.hodate && record.startdate.year <= 2024
record.errors.add :hodate, I18n.t("validations.sales.sale_information.hodate.must_be_less_than_3_years_from_saledate")
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_less_than_3_years_from_hodate")
end

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

@ -110,6 +110,12 @@ module Validations::Sales::SoftValidations
saledate - hodate >= 3.years
end
def hodate_5_years_or_more_saledate?
return unless hodate && saledate
saledate - hodate >= 5.years
end
def purchase_price_higher_or_lower_text
value < sale_range.soft_min ? "lower" : "higher"
end

5
app/views/logs/_tasklist.html.erb

@ -1,5 +1,6 @@
<ol class="app-task-list govuk-!-margin-top-8">
<% @log.form.sections.map do |section| %>
<% @log.form.sections.each do |section| %>
<% next unless section.displayed_in_tasklist?(@log) %>
<li>
<h2 class="app-task-list__section-heading">
<%= section.label %>
@ -8,7 +9,7 @@
<p class="govuk-body"><%= section.description.html_safe %></p>
<% end %>
<ul class="app-task-list__items">
<% section.subsections.map do |subsection| %>
<% section.subsections.each do |subsection| %>
<% if subsection.displayed_in_tasklist?(@log) && (subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log)) %>
<% subsection_status = subsection.status(@log) %>
<li class="app-task-list__item">

8
config/locales/forms/2024/lettings/soft_validations.en.yml

@ -130,3 +130,11 @@ en:
question_text: "Are you sure the property has been vacant for this long?"
title_text: "You told us the property has been vacant for 2 years."
informative_text: "This is longer than we would expect."
no_address_found:
page_header: ""
check_answer_label: "No address found"
hint_text: ""
question_text: "We could not find an address that matches your search. You can search again or continue to enter the address manually."
title_text: "No address found"
informative_text: "We could not find an address that matches your search. You can search again or continue to enter the address manually."

17
config/locales/validations/lettings/property_information.en.yml

@ -4,6 +4,7 @@ en:
property:
postcode_full:
invalid: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
rsnvac:
non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary."
referral_invalid: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as a different source of referral for this letting."
@ -18,4 +19,18 @@ en:
one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms."
uprn:
invalid: "UPRN must be 12 digits or less."
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_confirmation:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_selection:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
la:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
scheme_id:
not_in_england: "This scheme’s only location is outside of England. Only create logs for lettings in England."
location_id:
not_in_england: "It looks like you have selected a location outside of England. Only create logs for lettings in England."
startdate:
postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
location_not_in_england: "It looks like you have selected a location outside of England. Only create logs for lettings in England."

11
config/locales/validations/sales/property_information.en.yml

@ -7,6 +7,7 @@ en:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match."
invalid: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have entered a postcode outside of England - only submit Lettings forms for Lettings that occur in England"
ppostcode_full:
postcode_must_match_previous:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
@ -20,9 +21,19 @@ en:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match."
invalid: "UPRN must be 12 digits or less."
not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
beds:
bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit."
proptype:
bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms."
uprn_known:
invalid: "You must answer UPRN known?"
la:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_confirmation:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_selection:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
saledate:
postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."

2
config/locales/validations/sales/sale_information.en.yml

@ -8,9 +8,11 @@ en:
hodate:
must_be_before_saledate: "Practical completion or handover date must be before sale completion date."
must_be_less_than_3_years_from_saledate: "Practical completion or handover date must be less than 3 years before sale completion date."
must_be_less_than_5_years_from_saledate: "Practical completion or handover date must be less than 5 years before sale completion date."
saledate:
must_be_after_hodate: "Sale completion date must be after practical completion or handover date."
must_be_less_than_3_years_from_hodate: "Sale completion date must be less than 3 years after practical completion or handover date."
must_be_less_than_5_years_from_hodate: "Sale completion date must be less than 5 years after practical completion or handover date."
must_be_after_exdate: "Sale completion date must be after contract exchange date."
must_be_less_than_1_year_from_exdate: "Sale completion date must be less than 1 year after contract exchange date."
mortgage_used_year: "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for the selected year."

7
spec/models/form/lettings/pages/no_address_found_spec.rb

@ -5,7 +5,8 @@ RSpec.describe Form::Lettings::Pages::NoAddressFound, type: :model do
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
let(:log) { create(:lettings_log) }
it "has correct subsection" do
@ -37,11 +38,11 @@ RSpec.describe Form::Lettings::Pages::NoAddressFound, type: :model do
end
it "has the correct title_text" do
expect(page.title_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.title_text" })
expect(page.title_text).to eq({ "arguments" => [], "translation" => "forms.2024.lettings.soft_validations.no_address_found.title_text" })
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.informative_text" })
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "forms.2024.lettings.soft_validations.no_address_found.informative_text" })
end
it "has the correct interruption_screen_question_ids" do

82
spec/models/form/sales/pages/handover_date_check_spec.rb

@ -5,44 +5,66 @@ RSpec.describe Form::Sales::Pages::HandoverDateCheck, type: :model do
let(:page_id) { "" }
let(:page_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
context "when form start year is <= 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hodate_check])
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has the correct id" do
expect(page.id).to eq("handover_date_check")
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hodate_check])
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2024.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has the correct id" do
expect(page.id).to eq("handover_date_check")
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2024.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
it "is has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[hodate saledate])
end
end
it "is has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[hodate saledate])
context "when form start year is 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2025.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_5_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_5_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
end
end

22
spec/models/form/sales/subsections/household_situation_spec.rb

@ -25,6 +25,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
],
)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_situation")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household situation")
end
end
context "when the start year is 2025" do
@ -41,17 +49,9 @@ RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
],
)
end
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_situation")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household situation")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
end
end
end

29
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -11,8 +11,16 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.section).to eq(section)
end
it "has the correct id" do
expect(subsection.id).to eq("income_benefits_and_savings")
end
it "has the correct label" do
expect(subsection.label).to eq("Income, benefits and savings")
end
describe "pages" do
let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:)) }
let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:, start_year_2025_or_later?: false)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
@ -83,18 +91,19 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
],
)
end
end
end
it "has the correct id" do
expect(subsection.id).to eq("income_benefits_and_savings")
it "has correct depends on" do
expect(subsection.depends_on).to eq([{ "setup_completed?" => true }])
end
end
end
it "has the correct label" do
expect(subsection.label).to eq("Income, benefits and savings")
end
context "when 2025" do
let(:start_date) { Time.utc(2025, 2, 8) }
let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:, start_year_2025_or_later?: true)) }
it "has correct depends on" do
expect(subsection.depends_on).to eq([{ "setup_completed?" => true }])
it "has correct depends on" do
expect(subsection.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
end
end
end

62
spec/models/form/sales/subsections/other_household_information_spec.rb

@ -5,36 +5,48 @@ RSpec.describe Form::Sales::Subsections::OtherHouseholdInformation, type: :model
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
context "when 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) }
let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
armed_forces
buyer_still_serving
armed_forces_spouse
household_disability
disability_wheelchair_check
household_wheelchair
wheelchair_check
],
)
end
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("other_household_information")
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
armed_forces
buyer_still_serving
armed_forces_spouse
household_disability
disability_wheelchair_check
household_wheelchair
wheelchair_check
],
)
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Other household information")
it "has the correct id" do
expect(household_characteristics.id).to eq("other_household_information")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Other household information")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
context "when 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true, "is_staircase?" => false }])
end
end
end

74
spec/models/validations/property_validations_spec.rb

@ -204,4 +204,78 @@ RSpec.describe Validations::PropertyValidations do
end
end
end
describe "#validate_la_in_england" do
context "with a log on or after 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return true
end
context "and the local authority is not in England for general needs log" do
let(:log) { build(:lettings_log, la: "S12000019", needstype: 1) }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.not_in_england"))
expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.not_in_england"))
expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.not_in_england"))
expect(log.errors["uprn_confirmation"]).to include(I18n.t("validations.lettings.property.uprn_confirmation.not_in_england"))
expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.not_in_england"))
expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.postcode_not_in_england"))
expect(log.errors["scheme_id"]).to be_empty
expect(log.errors["location_id"]).to be_empty
end
end
context "and the local authority is not in England for supported housing log" do
let(:location) { create(:location, location_code: "S12000019") }
let(:log) { build(:lettings_log, la: "S12000019", needstype: 2, location:) }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.not_in_england"))
expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.not_in_england"))
expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.location_not_in_england"))
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
context "and the local authority is in England" do
let(:log) { build(:lettings_log, la: "E06000002") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
expect(log.errors["startdate"]).to be_empty
end
end
end
context "with a log before 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return false
end
context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
end
end
end

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

@ -142,4 +142,60 @@ RSpec.describe Validations::Sales::PropertyValidations do
end
end
end
describe "#validate_la_in_england" do
context "with a log on or after 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return true
end
context "and the local authority is not in England" do
let(:log) { build(:sales_log, la: "S12000019") }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to include(I18n.t("validations.sales.property_information.la.not_in_england"))
expect(log.errors["postcode_full"]).to include(I18n.t("validations.sales.property_information.postcode_full.not_in_england"))
expect(log.errors["uprn"]).to include(I18n.t("validations.sales.property_information.uprn.not_in_england"))
expect(log.errors["uprn_confirmation"]).to include(I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england"))
expect(log.errors["uprn_selection"]).to include(I18n.t("validations.sales.property_information.uprn_selection.not_in_england"))
expect(log.errors["saledate"]).to include(I18n.t("validations.sales.property_information.saledate.postcode_not_in_england"))
end
end
context "and the local authority is in England" do
let(:log) { build(:sales_log, la: "E06000002") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
expect(log.errors["saledate"]).to be_empty
end
end
end
context "with a log before 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return false
end
context "and the local authority is not in England" do
let(:log) { build(:sales_log, la: "S12000019") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
expect(log.errors["saledate"]).to be_empty
end
end
end
end
end

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

@ -60,10 +60,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
context "and form year is 2023 or earlier" do
let(:record) { build(:sales_log, hodate: Date.new(2020, 12, 1), saledate: Date.new(2023, 12, 1)) }
it "does not add an error" do
it "does add an error" do
sale_information_validator.validate_practical_completion_date(record)
expect(record.errors).not_to be_present
expect(record.errors[:hodate]).to be_present
expect(record.errors[:saledate]).to be_present
end
end

Loading…
Cancel
Save