From 491ff7634726b109217723abbd03c41ebc4609f7 Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:06:39 +0100 Subject: [PATCH] Extract discounted ownership validations --- .../pages/deposit_and_mortgage_value_check.rb | 5 ++- .../pages/discounted_sale_value_check.rb | 5 ++- .../pages/extra_borrowing_value_check.rb | 5 ++- .../form/sales/pages/grant_value_check.rb | 5 ++- .../pages/percentage_discount_value_check.rb | 5 ++- .../deposit_and_mortgage_value_check.rb | 3 +- .../questions/discounted_sale_value_check.rb | 3 +- .../questions/extra_borrowing_value_check.rb | 3 +- .../form/sales/questions/grant_value_check.rb | 3 +- .../percentage_discount_value_check.rb | 3 +- config/locales/en.yml | 15 ------- .../forms/2023/sales/soft_validations.en.yml | 38 ++++++++++++++++++ .../forms/2024/sales/soft_validations.en.yml | 39 +++++++++++++++++++ .../pages/discounted_sale_value_check_spec.rb | 7 ++-- .../percentage_discount_value_check_spec.rb | 7 ++-- 15 files changed, 105 insertions(+), 41 deletions(-) diff --git a/app/models/form/sales/pages/deposit_and_mortgage_value_check.rb b/app/models/form/sales/pages/deposit_and_mortgage_value_check.rb index fe5ad4acb..99f78e0b1 100644 --- a/app/models/form/sales/pages/deposit_and_mortgage_value_check.rb +++ b/app/models/form/sales/pages/deposit_and_mortgage_value_check.rb @@ -6,8 +6,9 @@ class Form::Sales::Pages::DepositAndMortgageValueCheck < ::Form::Page "mortgage_plus_deposit_less_than_discounted_value?" => true, }, ] + @copy_key = "sales.sale_information.deposit_and_mortgage_value_check" @title_text = { - "translation" => "soft_validations.deposit_and_mortgage.title_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", "arguments" => [ { "key" => "mortgage", @@ -27,7 +28,7 @@ class Form::Sales::Pages::DepositAndMortgageValueCheck < ::Form::Page ], } @informative_text = { - "translation" => "soft_validations.deposit_and_mortgage.hint_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", "arguments" => [], } end diff --git a/app/models/form/sales/pages/discounted_sale_value_check.rb b/app/models/form/sales/pages/discounted_sale_value_check.rb index dcb820e49..bdee82fb3 100644 --- a/app/models/form/sales/pages/discounted_sale_value_check.rb +++ b/app/models/form/sales/pages/discounted_sale_value_check.rb @@ -2,8 +2,9 @@ class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page def initialize(id, hsh, subsection, person_index = nil) super(id, hsh, subsection) @depends_on = depends_on + @copy_key = "sales.sale_information.discounted_sale_value_check" @title_text = { - "translation" => "soft_validations.discounted_sale_value.title_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", "arguments" => [ { "key" => "field_formatted_as_currency", @@ -13,7 +14,7 @@ class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page ], } @informative_text = { - "translation" => "soft_validations.discounted_sale_value.informative_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", "arguments" => [ { "key" => "field_formatted_as_currency", diff --git a/app/models/form/sales/pages/extra_borrowing_value_check.rb b/app/models/form/sales/pages/extra_borrowing_value_check.rb index b3cf0b2db..6f184d852 100644 --- a/app/models/form/sales/pages/extra_borrowing_value_check.rb +++ b/app/models/form/sales/pages/extra_borrowing_value_check.rb @@ -6,8 +6,9 @@ class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page "extra_borrowing_expected_but_not_reported?" => true, }, ] + @copy_key = "sales.sale_information.extra_borrowing_value_check" @title_text = { - "translation" => "soft_validations.extra_borrowing.title_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", "arguments" => [ { "key" => "field_formatted_as_currency", @@ -17,7 +18,7 @@ class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page ], } @informative_text = { - "translation" => "soft_validations.extra_borrowing.hint_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", "arguments" => [], } end diff --git a/app/models/form/sales/pages/grant_value_check.rb b/app/models/form/sales/pages/grant_value_check.rb index 6b53d74ee..6c37645b9 100644 --- a/app/models/form/sales/pages/grant_value_check.rb +++ b/app/models/form/sales/pages/grant_value_check.rb @@ -2,13 +2,14 @@ class Form::Sales::Pages::GrantValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @id = "grant_value_check" + @copy_key = "sales.sale_information.grant_value_check" @depends_on = [ { "grant_outside_common_range?" => true, }, ] @title_text = { - "translation" => "soft_validations.grant.title_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", "arguments" => [ { "key" => "field_formatted_as_currency", @@ -18,7 +19,7 @@ class Form::Sales::Pages::GrantValueCheck < ::Form::Page ], } @informative_text = { - "translation" => "soft_validations.grant.hint_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", "arguments" => [], } end diff --git a/app/models/form/sales/pages/percentage_discount_value_check.rb b/app/models/form/sales/pages/percentage_discount_value_check.rb index 37ff4eea4..fcf9719ba 100644 --- a/app/models/form/sales/pages/percentage_discount_value_check.rb +++ b/app/models/form/sales/pages/percentage_discount_value_check.rb @@ -1,12 +1,13 @@ class Form::Sales::Pages::PercentageDiscountValueCheck < ::Form::Page def initialize(id, hsh, subsection) super + @copy_key = "sales.sale_information.percentage_discount_value_check" @title_text = { - "translation" => "soft_validations.percentage_discount_value.title_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", "arguments" => [{ "key" => "discount", "label" => true, "i18n_template" => "discount" }], } @informative_text = { - "translation" => "soft_validations.percentage_discount_value.hint_text", + "translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", "arguments" => [], } @depends_on = [{ "percentage_discount_invalid?" => true }] diff --git a/app/models/form/sales/questions/deposit_and_mortgage_value_check.rb b/app/models/form/sales/questions/deposit_and_mortgage_value_check.rb index 263cf4342..de15715e8 100644 --- a/app/models/form/sales/questions/deposit_and_mortgage_value_check.rb +++ b/app/models/form/sales/questions/deposit_and_mortgage_value_check.rb @@ -2,8 +2,7 @@ class Form::Sales::Questions::DepositAndMortgageValueCheck < ::Form::Question def initialize(id, hsh, page) super @id = "deposit_and_mortgage_value_check" - @check_answer_label = "Deposit and mortgage against discount confirmation" - @header = "Are you sure? Mortgage and deposit usually equal or are more than (value - discount)" + @copy_key = "sales.sale_information.deposit_and_mortgage_value_check" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/app/models/form/sales/questions/discounted_sale_value_check.rb b/app/models/form/sales/questions/discounted_sale_value_check.rb index 1d86b2f32..af0d441f2 100644 --- a/app/models/form/sales/questions/discounted_sale_value_check.rb +++ b/app/models/form/sales/questions/discounted_sale_value_check.rb @@ -2,8 +2,7 @@ class Form::Sales::Questions::DiscountedSaleValueCheck < ::Form::Question def initialize(id, hsh, page) super @id = "discounted_sale_value_check" - @check_answer_label = "Discounted sale value confirmation" - @header = "Are you sure this is correct?" + @copy_key = "sales.sale_information.discounted_sale_value_check" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/app/models/form/sales/questions/extra_borrowing_value_check.rb b/app/models/form/sales/questions/extra_borrowing_value_check.rb index 0f12ce110..a5f713128 100644 --- a/app/models/form/sales/questions/extra_borrowing_value_check.rb +++ b/app/models/form/sales/questions/extra_borrowing_value_check.rb @@ -2,7 +2,7 @@ class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question def initialize(id, hsh, page) super(id, hsh, page) @id = "extrabor_value_check" - @check_answer_label = "Extra borrowing confirmation" + @copy_key = "sales.sale_information.extra_borrowing_value_check" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, @@ -18,6 +18,5 @@ class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question }, ], } - @header = "Are you sure there is no extra borrowing?" end end diff --git a/app/models/form/sales/questions/grant_value_check.rb b/app/models/form/sales/questions/grant_value_check.rb index a7efdbaee..788f9cfb9 100644 --- a/app/models/form/sales/questions/grant_value_check.rb +++ b/app/models/form/sales/questions/grant_value_check.rb @@ -2,8 +2,7 @@ class Form::Sales::Questions::GrantValueCheck < ::Form::Question def initialize(id, hsh, page) super @id = "grant_value_check" - @check_answer_label = "Grant value confirmation" - @header = "Are you sure? Grants are usually £9,000 - £16,000" + @copy_key = "sales.sale_information.grant_value_check" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/app/models/form/sales/questions/percentage_discount_value_check.rb b/app/models/form/sales/questions/percentage_discount_value_check.rb index 9ac5547b4..e1e015c75 100644 --- a/app/models/form/sales/questions/percentage_discount_value_check.rb +++ b/app/models/form/sales/questions/percentage_discount_value_check.rb @@ -2,8 +2,7 @@ class Form::Sales::Questions::PercentageDiscountValueCheck < ::Form::Question def initialize(id, hsh, page) super @id = "percentage_discount_value_check" - @check_answer_label = "Percentage discount confirmation" - @header = "Are you sure this is correct?" + @copy_key = "sales.sale_information.percentage_discount_value_check" @type = "interruption_screen" @answer_options = { "0" => { "value" => "Yes" }, diff --git a/config/locales/en.yml b/config/locales/en.yml index af9da2598..4276a26ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -657,9 +657,6 @@ en: max: title: "You told us this person is over 66 and not retired." hint_text: "The minimum expected retirement age in England is 66." - extra_borrowing: - title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}." - hint_text: "This is higher than the purchase price minus the discount." pregnancy: title: "You told us somebody in the household is pregnant." all_male_tenants: "You also told us that all the tenants living at the property are male." @@ -670,17 +667,8 @@ en: void_date: title_text: "You told us that the property has been vacant for more than 2 years." hint_text: "This is higher than we would expect." - discounted_sale_value: - title_text: "Mortgage, deposit, and grant total must equal %{value_with_discount}." - informative_text: "Your given mortgage, deposit and grant total is %{mortgage_deposit_and_grant_total}." care_home_charges: title_text: "Care home charges should be provided if this is a care home accommodation." - percentage_discount_value: - title_text: "You told us that the percentage discount is %{discount}." - hint_text: "This is higher than we would expect." - grant: - title_text: "You told us that the grant amount is %{grant}." - hint_text: "Loans, grants and subsidies are usually between £9,000 and £16,000." referral: title_text: "Are you sure?" hint_text: "This is a general needs log, and this referral type is for supported housing." @@ -693,9 +681,6 @@ en: charges: informative_text: "This is higher than we would expect." hint_text: "Check the following:" - deposit_and_mortgage: - title_text: "You told us the mortgage amount was %{mortgage}, the cash deposit was %{deposit} and the discount was %{discount}." - hint_text: "We would expect the mortgage amount and the deposit added together to be the same as the purchase price minus the discount." reasonother: title_text: "You told us that the tenant’s main reason for leaving their last settled home was %{reasonother}." informative_text: "The reason you have entered looks very similar to one of the existing response categories. diff --git a/config/locales/forms/2023/sales/soft_validations.en.yml b/config/locales/forms/2023/sales/soft_validations.en.yml index 104d6e2b5..abc7d91e2 100644 --- a/config/locales/forms/2023/sales/soft_validations.en.yml +++ b/config/locales/forms/2023/sales/soft_validations.en.yml @@ -194,5 +194,43 @@ en: question_text: "Are you sure this is correct?" title_text: "You told us that the monthly charges were %{mscharge}." informative_text: "This is higher than we would expect." + + extra_borrowing_value_check: + page_header: "" + check_answer_label: "Extra borrowing confirmation" + hint_text: "" + question_text: "Are you sure there is no extra borrowing?" + title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}." + informative_text: "This is higher than the purchase price minus the discount." + percentage_discount_value_check: + page_header: "" + check_answer_label: "Percentage discount confirmation" + hint_text: "" + question_text: "Are you sure this is correct?" + title_text: "You told us that the percentage discount is %{discount}." + informative_text: "This is higher than we would expect." + grant_value_check: + page_header: "" + check_answer_label: "Grant value confirmation" + hint_text: "" + question_text: "Are you sure? Grants are usually £9,000 - £16,000" + title_text: "You told us that the grant amount is %{grant}." + informative_text: "Loans, grants and subsidies are usually between £9,000 and £16,000." + + discounted_sale_value_check: + page_header: "" + check_answer_label: "Discounted sale value confirmation" + hint_text: "" + question_text: "Are you sure this is correct?" + title_text: "Mortgage, deposit, and grant total must equal %{value_with_discount}." + informative_text: "Your given mortgage, deposit and grant total is %{mortgage_deposit_and_grant_total}." + + deposit_and_mortgage_value_check: + page_header: "" + check_answer_label: "Deposit and mortgage against discount confirmation" + hint_text: "" + question_text: "Are you sure? Mortgage and deposit usually equal or are more than (value - discount)" + title_text: "You told us the mortgage amount was %{mortgage}, the cash deposit was %{deposit} and the discount was %{discount}." + informative_text: "We would expect the mortgage amount and the deposit added together to be the same as the purchase price minus the discount." diff --git a/config/locales/forms/2024/sales/soft_validations.en.yml b/config/locales/forms/2024/sales/soft_validations.en.yml index 1a10dcd79..471cf62be 100644 --- a/config/locales/forms/2024/sales/soft_validations.en.yml +++ b/config/locales/forms/2024/sales/soft_validations.en.yml @@ -194,4 +194,43 @@ en: question_text: "Are you sure this is correct?" title_text: "You told us that the monthly charges were %{mscharge}." informative_text: "This is higher than we would expect." + + extra_borrowing_value_check: + page_header: "" + check_answer_label: "Extra borrowing confirmation" + hint_text: "" + question_text: "Are you sure there is no extra borrowing?" + title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}." + informative_text: "This is higher than the purchase price minus the discount." + percentage_discount_value_check: + page_header: "" + check_answer_label: "Percentage discount confirmation" + hint_text: "" + question_text: "Are you sure this is correct?" + title_text: "You told us that the percentage discount is %{discount}." + informative_text: "This is higher than we would expect." + + grant_value_check: + page_header: "" + check_answer_label: "Grant value confirmation" + hint_text: "" + question_text: "Are you sure? Grants are usually £9,000 - £16,000" + title_text: "You told us that the grant amount is %{grant}." + informative_text: "Loans, grants and subsidies are usually between £9,000 and £16,000." + + discounted_sale_value_check: + page_header: "" + check_answer_label: "Discounted sale value confirmation" + hint_text: "" + question_text: "Are you sure this is correct?" + title_text: "Mortgage, deposit, and grant total must equal %{value_with_discount}." + informative_text: "Your given mortgage, deposit and grant total is %{mortgage_deposit_and_grant_total}." + + deposit_and_mortgage_value_check: + page_header: "" + check_answer_label: "Deposit and mortgage against discount confirmation" + hint_text: "" + question_text: "Are you sure? Mortgage and deposit usually equal or are more than (value - discount)" + title_text: "You told us the mortgage amount was %{mortgage}, the cash deposit was %{deposit} and the discount was %{discount}." + informative_text: "We would expect the mortgage amount and the deposit added together to be the same as the purchase price minus the discount." diff --git a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb index 38a5f69ae..8f9673981 100644 --- a/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb +++ b/spec/models/form/sales/pages/discounted_sale_value_check_spec.rb @@ -6,7 +6,8 @@ RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do let(:page_id) { "discounted_sale_value_check" } let(:page_definition) { nil } let(:index) { 1 } - let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + let(:subsection) { instance_double(Form::Subsection, form:) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -22,14 +23,14 @@ RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do it "has the correct title_text" do expect(page.title_text).to eq({ - "translation" => "soft_validations.discounted_sale_value.title_text", + "translation" => "forms.2024.sales.sale_information.discounted_sale_value_check.title_text", "arguments" => [{ "arguments_for_key" => "value_with_discount", "i18n_template" => "value_with_discount", "key" => "field_formatted_as_currency" }], }) end it "has the correct informative_text" do expect(page.informative_text).to eq({ - "translation" => "soft_validations.discounted_sale_value.informative_text", + "translation" => "forms.2024.sales.sale_information.discounted_sale_value_check.informative_text", "arguments" => [{ "arguments_for_key" => "mortgage_deposit_and_grant_total", "i18n_template" => "mortgage_deposit_and_grant_total", "key" => "field_formatted_as_currency" }], }) end diff --git a/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb b/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb index 5fc3e05ad..78ae976b1 100644 --- a/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb +++ b/spec/models/form/sales/pages/percentage_discount_value_check_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::PercentageDiscountValueCheck, type: :model do let(:page_id) { "percentage_discount_value_check" } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + let(:subsection) { instance_double(Form::Subsection, form:) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -21,14 +22,14 @@ RSpec.describe Form::Sales::Pages::PercentageDiscountValueCheck, type: :model do it "has the correct title_text" do expect(page.title_text).to eq({ - "translation" => "soft_validations.percentage_discount_value.title_text", + "translation" => "forms.2024.sales.sale_information.percentage_discount_value_check.title_text", "arguments" => [{ "key" => "discount", "label" => true, "i18n_template" => "discount" }], }) end it "has the correct informative_text" do expect(page.informative_text).to eq({ - "translation" => "soft_validations.percentage_discount_value.hint_text", + "translation" => "forms.2024.sales.sale_information.percentage_discount_value_check.informative_text", "arguments" => [], }) end