From a85fed42b18832319bb94bd6f86bdaa8b65f1acc Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:33:30 +0100 Subject: [PATCH] CLDC-3504 Update period question options and error message (#2463) * Update displayed_answer_options for period * Update invalid rent period error message --- app/models/form/lettings/questions/period.rb | 8 +++++ config/locales/en.yml | 2 +- .../form/lettings/questions/period_spec.rb | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/models/form/lettings/questions/period.rb b/app/models/form/lettings/questions/period.rb index 35b8a85dc..aefe8be84 100644 --- a/app/models/form/lettings/questions/period.rb +++ b/app/models/form/lettings/questions/period.rb @@ -26,4 +26,12 @@ class Form::Lettings::Questions::Period < ::Form::Question }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 92, 2024 => 91 }.freeze + + def displayed_answer_options(log, _user) + return ANSWER_OPTIONS if log.managing_organisation.nil? + + available_rent_periods = log.managing_organisation.rent_periods + + ANSWER_OPTIONS.select { |key, _| available_rent_periods.include?(key.to_i) } + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 63b159b32..23c0bb489 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -429,7 +429,7 @@ en: under_10: "Enter a total charge that is at least £10.00 per week" less_than_shortfall: "The total charge must be more than the outstanding amount" rent_period: - invalid_for_org: "%{org_name} does not charge rent %{rent_period}" + invalid_for_org: "%{org_name} does not use %{rent_period} as a rent period. Choose another rent period, or a data coordinator can add rent periods to your organisation" carehome: out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}" not_provided: "Enter how much rent and other charges the household pays %{period}" diff --git a/spec/models/form/lettings/questions/period_spec.rb b/spec/models/form/lettings/questions/period_spec.rb index 629be7f28..4798903c8 100644 --- a/spec/models/form/lettings/questions/period_spec.rb +++ b/spec/models/form/lettings/questions/period_spec.rb @@ -8,4 +8,39 @@ RSpec.describe Form::Lettings::Questions::Period, type: :model do it "has the correct hint" do expect(question.hint_text).to eq("Select how often the household is charged. This may be different to how often they pay.") end + + it "has correct answer options" do + expect(question.answer_options).to eq( + { + "2" => { "value" => "Every 2 weeks" }, + "3" => { "value" => "Every 4 weeks" }, + "4" => { "value" => "Every calendar month" }, + "9" => { "value" => "Weekly for 46 weeks" }, + "8" => { "value" => "Weekly for 47 weeks" }, + "7" => { "value" => "Weekly for 48 weeks" }, + "6" => { "value" => "Weekly for 49 weeks" }, + "5" => { "value" => "Weekly for 50 weeks" }, + "11" => { "value" => "Weekly for 51 weeks" }, + "1" => { "value" => "Weekly for 52 weeks" }, + "10" => { "value" => "Weekly for 53 weeks" }, + }, + ) + end + + context "when managing organisation has rent periods" do + let(:managing_organisation) { create(:organisation, skip_rent_period_creation: true) } + let(:log) { create(:lettings_log, managing_organisation:) } + + before do + create(:organisation_rent_period, organisation: managing_organisation, rent_period: 3) + end + + it "has correct displayed answer options" do + expect(question.displayed_answer_options(log, nil)).to eq( + { + "3" => { "value" => "Every 4 weeks" }, + }, + ) + end + end end