Browse Source

Update validation message (#2783)

pull/2800/head
kosiakkatrina 1 month ago committed by GitHub
parent
commit
a3ce7e9f95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      app/models/validations/sales/financial_validations.rb
  2. 4
      config/locales/validations/sales/financial.en.yml
  3. 10
      spec/models/validations/sales/financial_validations_spec.rb

5
app/models/validations/sales/financial_validations.rb

@ -73,8 +73,9 @@ module Validations::Sales::FinancialValidations
end
if threshold && record.stairbought < threshold
record.errors.add :stairbought, I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold:)
record.errors.add :type, I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold:)
shared_ownership_type = record.form.get_question("type", record).label_from_value(record.type).downcase
record.errors.add :stairbought, I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold:, shared_ownership_type:)
record.errors.add :type, I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold:, shared_ownership_type:)
end
end

4
config/locales/validations/sales/financial.en.yml

@ -55,7 +55,7 @@ en:
type:
equity_under_min: "The minimum initial equity stake for this type of shared ownership sale is %{min_equity}%."
equity_over_max: "The maximum initial equity stake is %{max_equity}%."
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type."
percentage_bought_must_be_at_least_threshold: "The minimum percentage share that can be bought in a staircasing transaction for %{shared_ownership_type} is %{threshold}%. Please change your answer or check that you have selected the correct shared ownership type."
equity:
equity_under_min: "The minimum initial equity stake for this type of shared ownership sale is %{min_equity}%."
@ -77,7 +77,7 @@ en:
equity_over_stairowned_minus_stairbought:
joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought."
not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought."
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%."
percentage_bought_must_be_at_least_threshold: "The minimum percentage share that can be bought in a staircasing transaction for %{shared_ownership_type} is %{threshold}%. Please change your answer or check that you have selected the correct shared ownership type."
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
uprn_selection:

10
spec/models/validations/sales/financial_validations_spec.rb

@ -275,18 +275,20 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.stairbought = 9
[2, 16, 18, 24].each do |type|
record.type = type
shared_ownership_type = record.form.get_question("type", record).label_from_value(record.type).downcase
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold: 10)])
expect(record.errors["type"]).to eq([I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold: 10)])
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold: 10, shared_ownership_type:)])
expect(record.errors["type"]).to eq([I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold: 10, shared_ownership_type:)])
record.errors.clear
end
record.stairbought = 0
[28, 30, 31, 32].each do |type|
record.type = type
shared_ownership_type = record.form.get_question("type", record).label_from_value(record.type).downcase
financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold: 1)])
expect(record.errors["type"]).to eq([I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold: 1)])
expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_must_be_at_least_threshold", threshold: 1, shared_ownership_type:)])
expect(record.errors["type"]).to eq([I18n.t("validations.sales.financial.type.percentage_bought_must_be_at_least_threshold", threshold: 1, shared_ownership_type:)])
record.errors.clear
end
end

Loading…
Cancel
Save