Browse Source

CLDC-1792 Update void date question (#1440)

* feat: add void date guidance partial

* feat: set guidance pos bottom for 22/23 log

* feat: add tests

* refactor: linting

* Update app/models/form/question.rb

Co-authored-by: Phil Lee <asmega@users.noreply.github.com>

* feat: smart quotes

* feat: respond to po comments

* feat: add voiddate/mrcdate validation to mrcdate too

* feat: add ten year validations to startdate too

* feat: fix tests

---------

Co-authored-by: Phil Lee <asmega@users.noreply.github.com>
review-app-for-23-24-mobbing
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
330c7b9595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/form/lettings/pages/new_build_handover_date.rb
  2. 7
      app/models/form/lettings/pages/void_date.rb
  3. 6
      app/models/form/lettings/questions/voiddate.rb
  4. 12
      app/models/form/lettings/questions/voiddate_new_build.rb
  5. 3
      app/models/form/lettings/subsections/property_information.rb
  6. 2
      app/models/form/question.rb
  7. 9
      app/models/validations/date_validations.rb
  8. 6
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  9. 9
      app/views/form/guidance/_void_date.html.erb
  10. 48
      config/forms/2022_2023.json
  11. 4
      config/locales/en.yml
  12. 33
      spec/models/form/lettings/pages/void_date_spec.rb
  13. 45
      spec/models/form/lettings/questions/voiddate_spec.rb
  14. 6
      spec/models/form/lettings/subsections/property_information_spec.rb
  15. 12
      spec/models/validations/date_validations_spec.rb

11
app/models/form/lettings/pages/new_build_handover_date.rb

@ -1,11 +0,0 @@
class Form::Lettings::Pages::NewBuildHandoverDate < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "new_build_handover_date"
@depends_on = [{ "is_renewal?" => false, "has_first_let_vacancy_reason?" => true }]
end
def questions
@questions ||= [Form::Lettings::Questions::VoiddateNewBuild.new(nil, nil, self)]
end
end

7
app/models/form/lettings/pages/void_or_renewal_date.rb → app/models/form/lettings/pages/void_date.rb

@ -1,8 +1,9 @@
class Form::Lettings::Pages::VoidOrRenewalDate < ::Form::Page class Form::Lettings::Pages::VoidDate < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "void_or_renewal_date" @id = "void_date"
@depends_on = [{ "is_renewal?" => false, "vacancy_reason_not_renewal_or_first_let?" => true }] @depends_on = [{ "is_renewal?" => false, "vacancy_reason_not_renewal_or_first_let?" => true },
{ "is_renewal?" => false, "has_first_let_vacancy_reason?" => true }]
end end
def questions def questions

6
app/models/form/lettings/questions/voiddate.rb

@ -2,10 +2,12 @@ class Form::Lettings::Questions::Voiddate < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "voiddate" @id = "voiddate"
@check_answer_label = "Void or renewal date" @check_answer_label = "Void date"
@header = "What is the void or renewal date?" @header = "What is the void date?"
@type = "date" @type = "date"
@check_answers_card_number = 0 @check_answers_card_number = 0
@question_number = 23 @question_number = 23
@guidance_partial = "void_date"
@guidance_position = GuidancePosition::BOTTOM
end end
end end

12
app/models/form/lettings/questions/voiddate_new_build.rb

@ -1,12 +0,0 @@
class Form::Lettings::Questions::VoiddateNewBuild < ::Form::Question
def initialize(id, hsh, page)
super
@id = "voiddate"
@check_answer_label = "New-build handover date"
@header = "What is the new-build handover date?"
@type = "date"
@check_answers_card_number = 0
@hint_text = ""
@question_number = 23
end
end

3
app/models/form/lettings/subsections/property_information.rb

@ -20,9 +20,8 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection
Form::Lettings::Pages::PropertyBuildingType.new(nil, nil, self), Form::Lettings::Pages::PropertyBuildingType.new(nil, nil, self),
Form::Lettings::Pages::PropertyWheelchairAccessible.new(nil, nil, self), Form::Lettings::Pages::PropertyWheelchairAccessible.new(nil, nil, self),
Form::Lettings::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), Form::Lettings::Pages::PropertyNumberOfBedrooms.new(nil, nil, self),
Form::Lettings::Pages::VoidOrRenewalDate.new(nil, nil, self), Form::Lettings::Pages::VoidDate.new(nil, nil, self),
Form::Lettings::Pages::VoidDateValueCheck.new(nil, nil, self), Form::Lettings::Pages::VoidDateValueCheck.new(nil, nil, self),
Form::Lettings::Pages::NewBuildHandoverDate.new(nil, nil, self),
Form::Lettings::Pages::PropertyMajorRepairs.new(nil, nil, self), Form::Lettings::Pages::PropertyMajorRepairs.new(nil, nil, self),
Form::Lettings::Pages::PropertyMajorRepairsValueCheck.new(nil, nil, self), Form::Lettings::Pages::PropertyMajorRepairsValueCheck.new(nil, nil, self),
].flatten.compact ].flatten.compact

2
app/models/form/question.rb

@ -14,11 +14,11 @@ class Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
@id = id @id = id
@page = page @page = page
@guidance_position = GuidancePosition::TOP
if hsh if hsh
@check_answer_label = hsh["check_answer_label"] @check_answer_label = hsh["check_answer_label"]
@header = hsh["header"] @header = hsh["header"]
@guidance_partial = hsh["guidance_partial"] @guidance_partial = hsh["guidance_partial"]
@guidance_position = hsh["guidance_position"] || GuidancePosition::TOP
@hint_text = hsh["hint_text"] @hint_text = hsh["hint_text"]
@type = hsh["type"] @type = hsh["type"]
@min = hsh["min"] @min = hsh["min"]

9
app/models/validations/date_validations.rb

@ -27,6 +27,7 @@ module Validations::DateValidations
if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
record.errors.add :voiddate, I18n.t("validations.property.void_date.after_mrcdate") record.errors.add :voiddate, I18n.t("validations.property.void_date.after_mrcdate")
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_void_date")
end end
end end
@ -45,6 +46,14 @@ module Validations::DateValidations
record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date") record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date")
end end
if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_void_date")
end
if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_mrc_date")
end
location_during_startdate_validation(record, :startdate) location_during_startdate_validation(record, :startdate)
scheme_during_startdate_validation(record, :startdate) scheme_during_startdate_validation(record, :startdate)
end end

6
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -91,9 +91,9 @@ class BulkUpload::Lettings::Year2022::RowParser
field_86: "Does the household pay rent or other charges for the accommodation?", field_86: "Does the household pay rent or other charges for the accommodation?",
field_87: "After the household has received any housing-related benefits, will they still need to pay basic rent and other charges?", field_87: "After the household has received any housing-related benefits, will they still need to pay basic rent and other charges?",
field_88: "What do you expect the outstanding amount to be?", field_88: "What do you expect the outstanding amount to be?",
field_89: "What is the void or renewal date?", field_89: "What is the void date?",
field_90: "What is the void or renewal date?", field_90: "What is the void date?",
field_91: "What is the void or renewal date?", field_91: "What is the void date?",
field_92: "What date were major repairs completed on?", field_92: "What date were major repairs completed on?",
field_93: "What date were major repairs completed on?", field_93: "What date were major repairs completed on?",
field_94: "What date were major repairs completed on?", field_94: "What date were major repairs completed on?",

9
app/views/form/guidance/_void_date.html.erb

@ -0,0 +1,9 @@
<%= govuk_details(summary_text: "What is a void date?") do %>
<p class="govuk-body">Date the property was (legally or contractually) available to let, or for:</p>
<ul class="govuk-list govuk-list--bullet">
<li>re-lets: the day after the previous tenant's contract ended</li>
<li>new builds: the day the landlord legally first owned the property (‘completion date’)</li>
<li>new conversions or acquisitions: completion date, or the day after rehabilitation work ended</li>
<li>new leases: the day the landlord got contractual property rights and could let it out to tenants</li>
</ul>
<% end %>

48
config/forms/2022_2023.json

@ -714,15 +714,17 @@
} }
] ]
}, },
"void_or_renewal_date": { "void_date": {
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"voiddate": { "voiddate": {
"check_answer_label": "Void or renewal date", "check_answer_label": "Void date",
"header": "What is the void or renewal date?", "header": "What is the void date?",
"hint_text": "For example, 27 3 2021.", "hint_text": "For example, 27 3 2021.",
"type": "date" "type": "date",
"guidance_partial": "void_date",
"guidance_position": 2
} }
}, },
"depends_on": [ "depends_on": [
@ -765,6 +767,18 @@
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 19 "rsnvac": 19
},
{
"renewal": 0,
"rsnvac": 15
},
{
"renewal": 0,
"rsnvac": 16
},
{
"renewal": 0,
"rsnvac": 17
} }
] ]
}, },
@ -804,32 +818,6 @@
} }
} }
}, },
"new_build_handover_date": {
"header": "",
"description": "",
"questions": {
"voiddate": {
"check_answer_label": "New-build handover date",
"header": "What is the new-build handover date?",
"hint_text": "",
"type": "date"
}
},
"depends_on": [
{
"renewal": 0,
"rsnvac": 15
},
{
"renewal": 0,
"rsnvac": 16
},
{
"renewal": 0,
"rsnvac": 17
}
]
},
"property_major_repairs": { "property_major_repairs": {
"header": "", "header": "",
"description": "", "description": "",

4
config/locales/en.yml

@ -173,6 +173,9 @@ en:
after_void_date: "Enter a tenancy start date that is after the void date" after_void_date: "Enter a tenancy start date that is after the void date"
after_major_repair_date: "Enter a tenancy start date that is after the major repair date" after_major_repair_date: "Enter a tenancy start date that is after the major repair date"
year_not_two_digits: Tenancy start year must be 2 digits year_not_two_digits: Tenancy start year must be 2 digits
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date"
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date"
location: location:
deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered." deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered."
reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date"
@ -200,6 +203,7 @@ en:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date" before_tenancy_start: "Enter a major repairs date that is before the tenancy start date"
not_first_let: "Major repairs date must not be completed if the tenancy is a first let" not_first_let: "Major repairs date must not be completed if the tenancy is a first let"
ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date" ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date"
before_void_date: "Major repairs date must be after the void date if provided"
void_date: void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date" ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date"
before_tenancy_start: "Enter a void date that is before the tenancy start date" before_tenancy_start: "Enter a void date that is before the tenancy start date"

33
spec/models/form/lettings/pages/void_date_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::VoidDate, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[voiddate])
end
it "has the correct id" do
expect(page.id).to eq("void_date")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([{ "is_renewal?" => false, "vacancy_reason_not_renewal_or_first_let?" => true }, { "has_first_let_vacancy_reason?" => true, "is_renewal?" => false }])
end
end

45
spec/models/form/lettings/questions/voiddate_spec.rb

@ -0,0 +1,45 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::Voiddate, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("voiddate")
end
it "has the correct header" do
expect(question.header).to eq("What is the void date?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Void date")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(0)
end
it "has the correct question_number" do
expect(question.question_number).to eq(23)
end
it "has the correct guidance_partial" do
expect(question.guidance_partial).to eq("void_date")
end
it "has the correct type" do
expect(question.type).to eq("date")
end
it "is not marked as derived" do
expect(question).not_to be_derived
end
end

6
spec/models/form/lettings/subsections/property_information_spec.rb

@ -30,9 +30,8 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do
property_building_type property_building_type
property_wheelchair_accessible property_wheelchair_accessible
property_number_of_bedrooms property_number_of_bedrooms
void_or_renewal_date void_date
void_date_value_check void_date_value_check
new_build_handover_date
property_major_repairs property_major_repairs
property_major_repairs_value_check property_major_repairs_value_check
], ],
@ -61,9 +60,8 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do
property_building_type property_building_type
property_wheelchair_accessible property_wheelchair_accessible
property_number_of_bedrooms property_number_of_bedrooms
void_or_renewal_date void_date
void_date_value_check void_date_value_check
new_build_handover_date
property_major_repairs property_major_repairs
property_major_repairs_value_check property_major_repairs_value_check
], ],

12
spec/models/validations/date_validations_spec.rb

@ -234,8 +234,11 @@ RSpec.describe Validations::DateValidations do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2012, 1, 1) record.mrcdate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
date_validator.validate_startdate(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start"))
expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_mrc_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -243,6 +246,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2012, 3, 1) record.mrcdate = Time.zone.local(2012, 3, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]).to be_empty expect(record.errors["mrcdate"]).to be_empty
expect(record.errors["startdate"]).to be_empty
end end
context "when reason for vacancy is first let of property" do context "when reason for vacancy is first let of property" do
@ -301,8 +305,11 @@ RSpec.describe Validations::DateValidations do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.voiddate = Time.zone.local(2012, 1, 1) record.voiddate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
date_validator.validate_startdate(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start"))
expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_void_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -310,15 +317,18 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2012, 3, 1) record.voiddate = Time.zone.local(2012, 3, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]).to be_empty expect(record.errors["voiddate"]).to be_empty
expect(record.errors["startdate"]).to be_empty
end end
context "when major repairs have been carried out" do context "when major repairs have been carried out" do
it "cannot be after major repairs date" do it "void_date cannot be after major repairs date" do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.after_mrcdate")) .to include(match I18n.t("validations.property.void_date.after_mrcdate"))
expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.before_void_date"))
end end
it "must be before major repairs date" do it "must be before major repairs date" do

Loading…
Cancel
Save