Browse Source

feat: tech review updates

pull/1739/head
natdeanlewissoftwire 3 years ago
parent
commit
8e78915891
  1. 4
      app/models/validations/shared_validations.rb
  2. 4
      config/locales/en.yml
  3. 12
      spec/models/validations/date_validations_spec.rb

4
app/models/validations/shared_validations.rb

@ -71,6 +71,7 @@ module Validations::SharedValidations
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 :startdate, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.startdate", 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:) record.errors.add :location_id, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.location_id", postcode: record.location.postcode, date:, deactivation_date:)
record.errors.add :scheme_id, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.location_id", postcode: record.location.postcode, date:, deactivation_date:)
end end
end end
@ -98,8 +99,7 @@ module Validations::SharedValidations
when :deactivated then open_deactivation.deactivation_date when :deactivated then open_deactivation.deactivation_date
end end
scope = status { scope: status, 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
def shared_validate_partner_count(record, max_people) def shared_validate_partner_count(record, max_people)

4
config/locales/en.yml

@ -249,7 +249,7 @@ en:
location: location:
deactivated: 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}" startdate: "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"
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" 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:
startdate: "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}"
@ -259,7 +259,7 @@ en:
location_id: "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: scheme:
deactivated: 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}" startdate: "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"
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" 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"
reactivating_soon: reactivating_soon:
startdate: "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}"

12
spec/models/validations/date_validations_spec.rb

@ -81,6 +81,8 @@ RSpec.describe Validations::DateValidations do
.to include(match I18n.t("validations.setup.startdate.location.deactivated.startdate", postcode: location.postcode, date: "4 June 2022")) .to include(match I18n.t("validations.setup.startdate.location.deactivated.startdate", postcode: location.postcode, date: "4 June 2022"))
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.deactivated.location_id", postcode: location.postcode, date: "4 June 2022")) .to include(match I18n.t("validations.setup.startdate.location.deactivated.location_id", postcode: location.postcode, date: "4 June 2022"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.deactivated.location_id", postcode: location.postcode, date: "4 June 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -89,6 +91,7 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
expect(record.errors["location_id"]).to be_empty expect(record.errors["location_id"]).to be_empty
expect(record.errors["scheme_id"]).to be_empty
end end
end end
@ -109,6 +112,8 @@ RSpec.describe Validations::DateValidations do
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.startdate", postcode: location.postcode, date: "4 August 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.startdate", postcode: location.postcode, date: "4 August 2022"))
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 August 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 August 2022"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 August 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -117,6 +122,7 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
expect(record.errors["location_id"]).to be_empty expect(record.errors["location_id"]).to be_empty
expect(record.errors["scheme_id"]).to be_empty
end end
end end
@ -139,6 +145,8 @@ RSpec.describe Validations::DateValidations do
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.startdate", postcode: location.postcode, date: "4 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.startdate", postcode: location.postcode, date: "4 September 2022"))
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 September 2022"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon.location_id", postcode: location.postcode, date: "4 September 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -147,6 +155,7 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
expect(record.errors["location_id"]).to be_empty expect(record.errors["location_id"]).to be_empty
expect(record.errors["scheme_id"]).to be_empty
end end
end end
@ -160,6 +169,7 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
expect(record.errors["location_id"]).to be_empty expect(record.errors["location_id"]).to be_empty
expect(record.errors["scheme_id"]).to be_empty
end end
it "produces an error when the date is before available_from date" do it "produces an error when the date is before available_from date" do
@ -170,6 +180,8 @@ RSpec.describe Validations::DateValidations do
.to include(match I18n.t("validations.setup.startdate.location.activating_soon.startdate", postcode: location.postcode, date: "15 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.activating_soon.startdate", postcode: location.postcode, date: "15 September 2022"))
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022"))
expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022"))
end end
end end

Loading…
Cancel
Save