From 2421dfba0bd71da3e8fc92ff3edb681a1e837d12 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 3 Jul 2023 17:36:40 +0100 Subject: [PATCH] feat: update validation messages --- app/models/validations/date_validations.rb | 4 +-- app/models/validations/setup_validations.rb | 6 ++--- app/models/validations/shared_validations.rb | 28 +++++++------------- config/locales/en.yml | 26 +++++++++--------- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index b83b143cc..3757f1cfb 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -54,8 +54,8 @@ module Validations::DateValidations record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_mrc_date") end - location_during_startdate_validation(record, :startdate) - scheme_during_startdate_validation(record, :startdate) + location_during_startdate_validation(record) + scheme_during_startdate_validation(record) end private diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index bb76a7668..e0efdc082 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -23,7 +23,7 @@ module Validations::SetupValidations end def validate_location(record) - location_during_startdate_validation(record, :location_id) + location_during_startdate_validation(record) end def validate_scheme_has_confirmed_locations_validation(record) @@ -35,8 +35,8 @@ module Validations::SetupValidations end def validate_scheme(record) - location_during_startdate_validation(record, :scheme_id) - scheme_during_startdate_validation(record, :scheme_id) + location_during_startdate_validation(record) + scheme_during_startdate_validation(record) end def validate_organisation(record) diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index 743954701..9d9fe9a12 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -64,24 +64,26 @@ module Validations::SharedValidations end end - def location_during_startdate_validation(record, field) - location_inactive_status = inactive_status(record.startdate, record.location, field) + def location_during_startdate_validation(record) + location_inactive_status = inactive_status(record.startdate, record.location) if location_inactive_status.present? date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date) - record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}", postcode: record.location.postcode, date:, deactivation_date:) + record.errors.add :startdate, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.startdate", postcode: record.location.postcode, date:, deactivation_date:) + record.errors.add :location_id, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.location_id", postcode: record.location.postcode, date:, deactivation_date:) end end - def scheme_during_startdate_validation(record, field) - scheme_inactive_status = inactive_status(record.startdate, record.scheme, field) + def scheme_during_startdate_validation(record) + scheme_inactive_status = inactive_status(record.startdate, record.scheme) if scheme_inactive_status.present? date, scope, deactivation_date = scheme_inactive_status.values_at(:date, :scope, :deactivation_date) - record.errors.add field, I18n.t("validations.setup.startdate.scheme.#{scope}", name: record.scheme.service_name, date:, deactivation_date:) + record.errors.add :startdate, I18n.t("validations.setup.startdate.scheme.#{scope}.startdate", name: record.scheme.service_name, date:, deactivation_date:) + record.errors.add :scheme_id, I18n.t("validations.setup.startdate.scheme.#{scope}.scheme_id", name: record.scheme.service_name, date:, deactivation_date:) end end - def inactive_status(date, resource, field) + def inactive_status(date, resource) return if date.blank? || resource.blank? status = resource.status_at(date) @@ -96,7 +98,7 @@ module Validations::SharedValidations when :deactivated then open_deactivation.deactivation_date end - scope = %i[activating_soon reactivating_soon].include?(status) ? "#{status}.#{scheme_location_validation_page(field)}" : status + scope = status { scope:, date: date&.to_formatted_s(:govuk_date), deactivation_date: closest_reactivation&.deactivation_date&.to_formatted_s(:govuk_date) } end @@ -128,16 +130,6 @@ module Validations::SharedValidations private - def scheme_location_validation_page(field) - field_mappings = { - startdate: "date_page", - location_id: "location_page", - scheme_id: "scheme_page", - } - - field_mappings[field] - end - def person_is_partner?(relationship) relationship == "P" end diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b8d719f6..645ddf84e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -248,23 +248,25 @@ en: ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date" location: - deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered." + deactivated: + startdate: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered. Enter a tenancy start date after %{date}" + location_id: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered. Select another location or edit the tenancy start date" activating_soon: - date_page: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" - location_page: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" - scheme_page: "This scheme's only location %{postcode} is not available until %{date}. Select another scheme or edit the tenancy start date" + startdate: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" + location_id: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" reactivating_soon: - date_page: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" - location_page: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" - scheme_page: "This scheme's only location %{postcode} is not available until %{date}. Select another scheme or edit the tenancy start date" + startdate: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" + location_id: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" scheme: - deactivated: "The scheme %{name} was deactivated on %{date} and was not available on the day you entered" + deactivated: + startdate: "The scheme %{name} was deactivated on %{date} and was not available on the day you entered. Enter a tenancy start date after %{date}" + scheme_id: "The scheme %{name} was deactivated on %{date} and was not available on the day you entered. Select another scheme or edit the tenancy start date" activating_soon: - date_page: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" - scheme_page: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date" + startdate: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" + scheme_id: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date" reactivating_soon: - date_page: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" - scheme_page: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date" + startdate: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" + scheme_id: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date" owning_organisation: invalid: "Please select the owning organisation or managing organisation that you belong to" data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."