Browse Source

feat: update validation messages

pull/1739/head
natdeanlewissoftwire 3 years ago
parent
commit
2421dfba0b
  1. 4
      app/models/validations/date_validations.rb
  2. 6
      app/models/validations/setup_validations.rb
  3. 28
      app/models/validations/shared_validations.rb
  4. 26
      config/locales/en.yml

4
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") record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_mrc_date")
end end
location_during_startdate_validation(record, :startdate) location_during_startdate_validation(record)
scheme_during_startdate_validation(record, :startdate) scheme_during_startdate_validation(record)
end end
private private

6
app/models/validations/setup_validations.rb

@ -23,7 +23,7 @@ module Validations::SetupValidations
end end
def validate_location(record) def validate_location(record)
location_during_startdate_validation(record, :location_id) location_during_startdate_validation(record)
end end
def validate_scheme_has_confirmed_locations_validation(record) def validate_scheme_has_confirmed_locations_validation(record)
@ -35,8 +35,8 @@ module Validations::SetupValidations
end end
def validate_scheme(record) def validate_scheme(record)
location_during_startdate_validation(record, :scheme_id) location_during_startdate_validation(record)
scheme_during_startdate_validation(record, :scheme_id) scheme_during_startdate_validation(record)
end end
def validate_organisation(record) def validate_organisation(record)

28
app/models/validations/shared_validations.rb

@ -64,24 +64,26 @@ module Validations::SharedValidations
end end
end end
def location_during_startdate_validation(record, field) def location_during_startdate_validation(record)
location_inactive_status = inactive_status(record.startdate, record.location, field) location_inactive_status = inactive_status(record.startdate, record.location)
if location_inactive_status.present? if location_inactive_status.present?
date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date) 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
end end
def scheme_during_startdate_validation(record, field) def scheme_during_startdate_validation(record)
scheme_inactive_status = inactive_status(record.startdate, record.scheme, field) scheme_inactive_status = inactive_status(record.startdate, record.scheme)
if scheme_inactive_status.present? if scheme_inactive_status.present?
date, scope, deactivation_date = scheme_inactive_status.values_at(:date, :scope, :deactivation_date) 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
end end
def inactive_status(date, resource, field) def inactive_status(date, resource)
return if date.blank? || resource.blank? return if date.blank? || resource.blank?
status = resource.status_at(date) status = resource.status_at(date)
@ -96,7 +98,7 @@ module Validations::SharedValidations
when :deactivated then open_deactivation.deactivation_date when :deactivated then open_deactivation.deactivation_date
end 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) } { scope:, date: date&.to_formatted_s(:govuk_date), deactivation_date: closest_reactivation&.deactivation_date&.to_formatted_s(:govuk_date) }
end end
@ -128,16 +130,6 @@ module Validations::SharedValidations
private 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) def person_is_partner?(relationship)
relationship == "P" relationship == "P"
end end

26
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" 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:
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: activating_soon:
date_page: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" startdate: "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" location_id: "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"
reactivating_soon: reactivating_soon:
date_page: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" startdate: "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" location_id: "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"
scheme: 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: activating_soon:
date_page: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" startdate: "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" scheme_id: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date"
reactivating_soon: reactivating_soon:
date_page: "The scheme %{name} is not available until %{date}. Enter a tenancy start date after %{date}" startdate: "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" scheme_id: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date"
owning_organisation: owning_organisation:
invalid: "Please select the owning organisation or managing organisation that you belong to" 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." data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."

Loading…
Cancel
Save