From f9ed29804effd435d96233c33a4e5f34de7674d4 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Thu, 8 Jun 2023 09:16:13 +0100 Subject: [PATCH 1/2] push back end date of forms to allow them to continue to be edited for now. Adjust the copy about the date until when logs can be edited to keep it consistent with how things have been up until now (#1688) --- app/helpers/tasklist_helper.rb | 4 ++-- app/models/form.rb | 5 +++-- app/views/form/review.html.erb | 2 +- config/forms/2022_2023.json | 2 +- spec/helpers/tasklist_helper_spec.rb | 2 +- spec/models/form_spec.rb | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 678ef044f..6250f0489 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -31,9 +31,9 @@ module TasklistHelper def review_log_text(log) if log.collection_period_open? - link = log.sales? ? review_sales_log_path(id: log, sales_log: true) : review_lettings_log_path(log) + path = log.sales? ? review_sales_log_path(id: log, sales_log: true) : review_lettings_log_path(log) - "You can #{govuk_link_to 'review and make changes to this log', link} until #{log.form.end_date.to_formatted_s(:govuk_date)}.".html_safe + "You can #{govuk_link_to 'review and make changes to this log', path} until #{log.form.display_end_date.to_formatted_s(:govuk_date)}.".html_safe else start_year = log.startdate ? collection_start_year_for_date(log.startdate) : log.form.start_date.year diff --git a/app/models/form.rb b/app/models/form.rb index cc73d2ca6..16c896e4c 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -1,6 +1,6 @@ class Form attr_reader :form_definition, :sections, :subsections, :pages, :questions, - :start_date, :end_date, :type, :name, :setup_definition, + :start_date, :end_date, :display_end_date, :type, :name, :setup_definition, :setup_sections, :form_sections, :unresolved_log_redirect_page_id def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") @@ -9,7 +9,7 @@ class Form @end_date = if start_year && start_year.to_i > 2022 Time.zone.local(start_year + 1, 6, 9) else - Time.zone.local(start_year + 1, 6, 7) + Time.zone.local(start_year + 1, 8, 7) end @setup_sections = type == "sales" ? [Form::Sales::Sections::Setup.new(nil, nil, self)] : [Form::Lettings::Sections::Setup.new(nil, nil, self)] @form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) } @@ -40,6 +40,7 @@ class Form @end_date = Time.iso8601(form_definition["end_date"]) @unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"] end + @display_end_date = start_year == 2022 ? Time.zone.local(2023, 6, 9) : @end_date @name = "#{start_date.year}_#{end_date.year}_#{type}" end diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb index c7af8972b..1e303b027 100644 --- a/app/views/form/review.html.erb +++ b/app/views/form/review.html.erb @@ -12,7 +12,7 @@ <%= content_for(:title) %>

- You can review and make changes to this log until <%= @log.form.end_date.to_formatted_s(:govuk_date) %>. + You can review and make changes to this log until <%= @log.form.display_end_date.to_formatted_s(:govuk_date) %>.

<% @log.form.sections.map do |section| %>

<%= section.label %>

diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index e49f125ed..a76e8f6ad 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -1,7 +1,7 @@ { "form_type": "lettings", "start_date": "2022-04-01T00:00:00.000+01:00", - "end_date": "2023-06-09T00:00:00.000+01:00", + "end_date": "2023-08-09T00:00:00.000+01:00", "unresolved_log_redirect_page_id": "tenancy_start_date", "sections": { "tenancy_and_property": { diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index ac6075fd2..e9b681d13 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -120,7 +120,7 @@ RSpec.describe TasklistHelper do it "returns relevant text" do expect(review_log_text(sales_log)).to eq( - "You can #{govuk_link_to 'review and make changes to this log', review_sales_log_path(id: sales_log, sales_log: true)} until 7 June 2023.".html_safe, + "You can #{govuk_link_to 'review and make changes to this log', review_sales_log_path(id: sales_log, sales_log: true)} until 9 June 2023.".html_safe, ) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index b9b49104e..b63d05f62 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -359,7 +359,7 @@ RSpec.describe Form, type: :model do expect(form.questions.count).to eq(13) expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) - expect(form.end_date).to eq(Time.zone.parse("2023-06-07")) + expect(form.end_date).to eq(Time.zone.parse("2023-08-07")) expect(form.unresolved_log_redirect_page_id).to eq(nil) end From 258e7cc81eec6a4f780b57bf377c930b5aa17263 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Fri, 9 Jun 2023 12:21:26 +0100 Subject: [PATCH 2/2] CLDC-1908 Update lettings compound validation (#1682) * feat: add second half of age/relat/ecstat validation to lettings logs * feat: add tests * feat: add ecstat refused option * feat: update tests * refactor: typo * feat: add extra test, typos --- .../validations/household_validations.rb | 19 +++++++-- .../sales/household_validations.rb | 13 +++++-- .../validations/financial_validations_spec.rb | 2 +- .../validations/household_validations_spec.rb | 39 +++++++++++++++++-- .../sales/household_validations_spec.rb | 12 +++++- 5 files changed, 72 insertions(+), 13 deletions(-) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index cd0ebd9ac..5609f1e1c 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -187,10 +187,21 @@ private relationship = record.public_send("relat#{person_num}") return unless age && economic_status && relationship - if age >= 16 && age <= 19 && tenant_is_child?(relationship) && (!tenant_is_fulltime_student?(economic_status) && !tenant_economic_status_refused?(economic_status)) - record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.not_student_16_19", person_num:) - record.errors.add "age#{person_num}", I18n.t("validations.household.age.not_student_16_19", person_num:) - record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.not_student_16_19", person_num:) + age_between_16_19 = age.between?(16, 19) + student = tenant_is_fulltime_student?(economic_status) + economic_status_refused = tenant_economic_status_refused?(economic_status) + child = tenant_is_child?(relationship) + + if age_between_16_19 && !(student || economic_status_refused) && child + record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student") + record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") + record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student") + end + + if !age_between_16_19 && student && child + record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19") + record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19") + record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19") end end diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index a0202ce89..f25effce6 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -54,9 +54,10 @@ private age_between_16_19 = age.between?(16, 19) student = person_is_fulltime_student?(economic_status) + economic_status_refused = person_economic_status_refused?(economic_status) child = person_is_child?(relationship) - if age_between_16_19 && !student && child + if age_between_16_19 && !(student || economic_status_refused) && child record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student") record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student") @@ -74,11 +75,11 @@ private economic_status = record.public_send("ecstat#{person_num}") return unless age && economic_status - if age < 16 && !tenant_is_economic_child?(economic_status) + if age < 16 && !person_is_economic_child?(economic_status) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) end - if tenant_is_economic_child?(economic_status) && age > 16 + if person_is_economic_child?(economic_status) && age > 16 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_16", person_num:) end @@ -109,7 +110,11 @@ private relationship == "C" end - def tenant_is_economic_child?(economic_status) + def person_is_economic_child?(economic_status) economic_status == 9 end + + def person_economic_status_refused?(economic_status) + economic_status == 10 + end end diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index a325f24d9..ab3924d90 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -990,7 +990,7 @@ RSpec.describe Validations::FinancialValidations do end context "and charges are not provided" do - xit "throws and error" do + xit "throws an error" do record.period = 3 record.chcharge = nil financial_validator.validate_care_home_charges(record) diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index b1c01b7a5..caf53695e 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -335,11 +335,11 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 1 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.household.ecstat.not_student_16_19", person_num: 2)) + .to include(match I18n.t("validations.household.ecstat.student_16_19.must_be_student", person_num: 2)) expect(record.errors["age2"]) - .to include(match I18n.t("validations.household.age.not_student_16_19", person_num: 2)) + .to include(match I18n.t("validations.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.household.relat.not_student_16_19", person_num: 2)) + .to include(match I18n.t("validations.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 @@ -363,6 +363,39 @@ RSpec.describe Validations::HouseholdValidations do 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_household_number_of_other_members(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_household_number_of_other_members(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_household_number_of_other_members(record) + expect(record.errors["relat2"]) + .to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19")) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.student_16_19.must_be_16_19")) + expect(record.errors["ecstat2"]) + .to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")) + end + context "when the household contains a person over 70" do it "expects that person under 70 does not need to be retired" do record.age2 = 50 diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index 925ac1814..e4ca5ae7f 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -107,7 +107,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do .to include(match I18n.t("validations.household.age.child_over_20")) end - it "does not add and error for a person aged 16-19 who is a student but not a child of the buyer" do + 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" @@ -117,6 +117,16 @@ RSpec.describe Validations::Sales::HouseholdValidations do 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_household_number_of_other_members(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 record.age2 = 17 record.ecstat2 = "1"