diff --git a/app/helpers/charges_helper.rb b/app/helpers/charges_helper.rb new file mode 100644 index 000000000..44e20b6e3 --- /dev/null +++ b/app/helpers/charges_helper.rb @@ -0,0 +1,38 @@ +module ChargesHelper + CHARGE_MAXIMA_PER_WEEK = { + scharge: { + private_registered_provider: { + general_needs: 800, + supported_housing: 800, + }, + local_authority: { + general_needs: 500, + supported_housing: 500, + }, + }, + pscharge: { + private_registered_provider: { + general_needs: 700, + supported_housing: 700, + }, + local_authority: { + general_needs: 200, + supported_housing: 200, + }, + }, + supcharg: { + private_registered_provider: { + general_needs: 800, + supported_housing: 800, + }, + local_authority: { + general_needs: 200, + supported_housing: 200, + }, + }, + }.freeze + + PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze + NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze + CHARGE_NAMES = { scharge: "service charge", pscharge: "personal service charge", supcharg: "support charge" }.freeze +end diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index d7cd5f948..a1b656f49 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -78,37 +78,13 @@ class BulkUpload < ApplicationRecord end end + def fields_to_confirm(log) + log.form.questions.select { |q| q.type == "interruption_screen" }.uniq(&:id).map(&:id) + end + def unpend_and_confirm_soft_validations logs.find_each do |log| - log.retirement_value_check = 0 - - if log.lettings? - log.pregnancy_value_check = 0 - log.major_repairs_date_value_check = 0 - log.void_date_value_check = 0 - log.rent_value_check = 0 - log.net_income_value_check = 0 - log.carehome_charges_value_check = 0 - elsif log.sales? - log.mortgage_value_check = 0 - log.shared_ownership_deposit_value_check = 0 - log.value_value_check = 0 - log.savings_value_check = 0 - log.income1_value_check = 0 - log.deposit_value_check = 0 - log.wheel_value_check = 0 - log.extrabor_value_check = 0 - log.grant_value_check = 0 - log.staircase_bought_value_check = 0 - log.deposit_and_mortgage_value_check = 0 - log.old_persons_shared_ownership_value_check = 0 - log.income2_value_check = 0 - log.monthly_charges_value_check = 0 - log.student_not_child_value_check = 0 - log.discounted_sale_value_check = 0 - log.buyer_livein_value_check = 0 - log.percentage_discount_value_check = 0 - end + fields_to_confirm(log).each { |field| log[field] = 0 } log.save! end end diff --git a/app/models/form/lettings/pages/pscharge_value_check.rb b/app/models/form/lettings/pages/pscharge_value_check.rb index 89cca160e..6c8ada196 100644 --- a/app/models/form/lettings/pages/pscharge_value_check.rb +++ b/app/models/form/lettings/pages/pscharge_value_check.rb @@ -2,7 +2,7 @@ class Form::Lettings::Pages::PschargeValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @id = "pscharge_value_check" - @depends_on = [{ "pscharge_over_soft_max?" => true }] + @depends_on = [{ "pscharge_in_soft_max_range?" => true }] @title_text = { "translation" => "soft_validations.pscharge.over_soft_max_title", "arguments" => [{ diff --git a/app/models/form/lettings/pages/scharge_value_check.rb b/app/models/form/lettings/pages/scharge_value_check.rb index 72ad8039e..73ee41920 100644 --- a/app/models/form/lettings/pages/scharge_value_check.rb +++ b/app/models/form/lettings/pages/scharge_value_check.rb @@ -2,7 +2,7 @@ class Form::Lettings::Pages::SchargeValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @id = "scharge_value_check" - @depends_on = [{ "scharge_over_soft_max?" => true }] + @depends_on = [{ "scharge_in_soft_max_range?" => true }] @title_text = { "translation" => "soft_validations.scharge.over_soft_max_title", "arguments" => [{ diff --git a/app/models/form/lettings/pages/supcharg_value_check.rb b/app/models/form/lettings/pages/supcharg_value_check.rb index 8155a28bb..a974a8f89 100644 --- a/app/models/form/lettings/pages/supcharg_value_check.rb +++ b/app/models/form/lettings/pages/supcharg_value_check.rb @@ -2,7 +2,7 @@ class Form::Lettings::Pages::SupchargValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @id = "supcharg_value_check" - @depends_on = [{ "supcharg_over_soft_max?" => true }] + @depends_on = [{ "supcharg_in_soft_max_range?" => true }] @title_text = { "translation" => "soft_validations.supcharg.over_soft_max_title", "arguments" => [{ diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 890c28284..0b9209281 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -1,6 +1,7 @@ module Validations::FinancialValidations include Validations::SharedValidations include MoneyFormattingHelper + include ChargesHelper # Validations methods need to be called 'validate_' to run on model save # or 'validate_' to run on submit as well def validate_outstanding_rent_amount(record) @@ -175,43 +176,6 @@ module Validations::FinancialValidations private - CHARGE_MAXIMA_PER_WEEK = { - scharge: { - private_registered_provider: { - general_needs: 800, - supported_housing: 800, - }, - local_authority: { - general_needs: 500, - supported_housing: 500, - }, - }, - pscharge: { - private_registered_provider: { - general_needs: 700, - supported_housing: 700, - }, - local_authority: { - general_needs: 200, - supported_housing: 200, - }, - }, - supcharg: { - private_registered_provider: { - general_needs: 800, - supported_housing: 800, - }, - local_authority: { - general_needs: 200, - supported_housing: 200, - }, - }, - }.freeze - - PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze - NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze - CHARGE_NAMES = { scharge: "service charge", pscharge: "personal service charge", supcharg: "support charge" }.freeze - def validate_charges(record) return unless record.owning_organisation diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 74afef27d..da3e050c5 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -1,4 +1,6 @@ module Validations::SoftValidations + include ChargesHelper + ALLOWED_INCOME_RANGES = { 1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230), 2 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950), @@ -97,40 +99,55 @@ module Validations::SoftValidations net_income_in_soft_max_range? ? "higher" : "lower" end - def scharge_over_soft_max? - return unless scharge && period && needstype + def scharge_in_soft_max_range? + return unless scharge && period && needstype && owning_organisation return if weekly_value(scharge).blank? - max = if needstype == 1 - owning_organisation.provider_type == "LA" ? 25 : 35 - else - owning_organisation.provider_type == "LA" ? 100 : 200 - end - weekly_value(scharge) > max + soft_max = if needstype == 1 + owning_organisation.provider_type == "LA" ? 25 : 35 + else + owning_organisation.provider_type == "LA" ? 100 : 200 + end + + provider_type = owning_organisation.provider_type_before_type_cast + hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:scharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype]) + + weekly_scharge = weekly_value(scharge) + weekly_scharge > soft_max && weekly_scharge <= hard_max end - def pscharge_over_soft_max? - return unless pscharge && period && needstype + def pscharge_in_soft_max_range? + return unless pscharge && period && needstype && owning_organisation return if weekly_value(pscharge).blank? - max = if needstype == 1 - owning_organisation.provider_type == "LA" ? 25 : 35 - else - owning_organisation.provider_type == "LA" ? 75 : 100 - end - weekly_value(pscharge) > max + soft_max = if needstype == 1 + owning_organisation.provider_type == "LA" ? 25 : 35 + else + owning_organisation.provider_type == "LA" ? 75 : 100 + end + + provider_type = owning_organisation.provider_type_before_type_cast + hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:pscharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype]) + + weekly_pscharge = weekly_value(pscharge) + weekly_pscharge > soft_max && weekly_pscharge <= hard_max end - def supcharg_over_soft_max? - return unless supcharg && period && needstype + def supcharg_in_soft_max_range? + return unless supcharg && period && needstype && owning_organisation return if weekly_value(supcharg).blank? - max = if needstype == 1 - owning_organisation.provider_type == "LA" ? 25 : 35 - else - owning_organisation.provider_type == "LA" ? 75 : 85 - end - weekly_value(supcharg) > max + soft_max = if needstype == 1 + owning_organisation.provider_type == "LA" ? 25 : 35 + else + owning_organisation.provider_type == "LA" ? 75 : 85 + end + + provider_type = owning_organisation.provider_type_before_type_cast + hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:supcharg, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype]) + + weekly_supcharg = weekly_value(supcharg) + weekly_supcharg > soft_max && weekly_supcharg <= hard_max end PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [ diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index affc18971..7de00a07b 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -8370,7 +8370,7 @@ "scharge_value_check": { "depends_on": [ { - "scharge_over_soft_max?": true + "scharge_in_soft_max_range?": true } ], "title_text": { @@ -8415,7 +8415,7 @@ "pscharge_value_check": { "depends_on": [ { - "pscharge_over_soft_max?": true + "pscharge_in_soft_max_range?": true } ], "title_text": { @@ -8460,7 +8460,7 @@ "supcharg_value_check": { "depends_on": [ { - "supcharg_over_soft_max?": true + "supcharg_in_soft_max_range?": true } ], "title_text": { diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index 6f4cf951c..503808fa4 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -24,13 +24,6 @@ FactoryBot.define do rent_type { 1 } startdate { Time.zone.today } end - trait :soft_validations_triggered do - status { 1 } - hhmemb { 1 } - ecstat1 { 1 } - earnings { 750 } - incfreq { 1 } - end trait :conditional_section_complete do tenancycode { Faker::Name.initials(number: 10) } age1 { 34 } diff --git a/spec/models/bulk_upload_spec.rb b/spec/models/bulk_upload_spec.rb index 8af5f63ea..130909eb8 100644 --- a/spec/models/bulk_upload_spec.rb +++ b/spec/models/bulk_upload_spec.rb @@ -18,4 +18,22 @@ RSpec.describe BulkUpload, type: :model do end end end + + describe "value check clearing" do + context "with a lettings log bulk upload" do + let(:log) { create(:lettings_log, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check carehome_charges_value_check scharge_value_check pscharge_value_check supcharg_value_check].sort) + end + end + + context "with a sales log bulk upload" do + let(:log) { create(:sales_log, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log).sort).to eq(%w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check student_not_child_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check].sort) + end + end + end end diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index ad87b3c5b..5c3d76f6f 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -376,7 +376,7 @@ RSpec.describe Validations::SoftValidations do end end - describe "scharge_over_soft_max?" do + describe "scharge_in_soft_max_range?" do context "and organisation is PRP" do before do record.owning_organisation.update(provider_type: "PRP") @@ -387,7 +387,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end it "returns false if period is not given" do @@ -395,48 +395,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, scharge: 34, + description: "under soft max (35)", }, { period: { label: "monthly", value: 4 }, scharge: 100, + description: "under soft max (35)", }, { period: { label: "every 2 weeks", value: 2 }, scharge: 69, + description: "under soft max (35)", + }, + { + period: { label: "weekly", value: 1 }, + scharge: 801, + description: "over hard max (800)", + }, + { + period: { label: "monthly", value: 4 }, + scharge: 3471, + description: "over hard max (800)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 1601, + description: "over hard max (800)", }].each do |test_case| - it "returns false if scharge is under soft max for general needs #{test_case[:period][:label]}(35)" do + it "returns false if scharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.scharge = test_case[:scharge] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, scharge: 199, + description: "under soft max (200)", }, { period: { label: "monthly", value: 4 }, scharge: 400, + description: "under soft max (200)", }, { period: { label: "every 2 weeks", value: 2 }, scharge: 399, + description: "under soft max (200)", + }, + { + period: { label: "weekly", value: 1 }, + scharge: 801, + description: "over hard max (800)", + }, + { + period: { label: "monthly", value: 4 }, + scharge: 3471, + description: "over hard max (800)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 1601, + description: "over hard max (800)", }].each do |test_case| - it "returns false if scharge is under soft max for supported housing #{test_case[:period][:label]} (200)" do + it "returns false if scharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.scharge = test_case[:scharge] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end end @@ -457,7 +493,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_scharge_over_soft_max + expect(record).to be_scharge_in_soft_max_range end end @@ -478,7 +514,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_scharge_over_soft_max + expect(record).to be_scharge_in_soft_max_range end end end @@ -493,7 +529,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end it "returns false if period is not given" do @@ -501,48 +537,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, scharge: 24, + description: "under soft max (25)", }, { period: { label: "monthly", value: 4 }, scharge: 88, + description: "under soft max (25)", }, { period: { label: "every 2 weeks", value: 2 }, scharge: 49, + description: "under soft max (25)", + }, + { + period: { label: "weekly", value: 1 }, + scharge: 501, + description: "over hard max (500)", + }, + { + period: { label: "monthly", value: 4 }, + scharge: 2167, + description: "over hard max (500)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 1001, + description: "over hard max (500)", }].each do |test_case| - it "returns false if scharge is under soft max for general needs #{test_case[:period][:label]}(25)" do + it "returns false if scharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.scharge = test_case[:scharge] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, scharge: 99, + description: "under soft max (100)", }, { period: { label: "monthly", value: 4 }, scharge: 400, + description: "under soft max (100)", }, { period: { label: "every 2 weeks", value: 2 }, scharge: 199, + description: "under soft max (100)", + }, + { + period: { label: "weekly", value: 1 }, + scharge: 501, + description: "over hard max (500)", + }, + { + period: { label: "monthly", value: 4 }, + scharge: 2167, + description: "over hard max (500)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 1001, + description: "over hard max (500)", }].each do |test_case| - it "returns false if scharge is under soft max for supported housing #{test_case[:period][:label]} (100)" do + it "returns false if scharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.scharge = test_case[:scharge] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_scharge_over_soft_max + expect(record).not_to be_scharge_in_soft_max_range end end @@ -563,7 +635,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_scharge_over_soft_max + expect(record).to be_scharge_in_soft_max_range end end @@ -584,13 +656,13 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_scharge_over_soft_max + expect(record).to be_scharge_in_soft_max_range end end end end - describe "pscharge_over_soft_max?" do + describe "pscharge_in_soft_max_range?" do context "and organisation is PRP" do before do record.owning_organisation.update(provider_type: "PRP") @@ -601,7 +673,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end it "returns false if period is not given" do @@ -609,48 +681,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, pscharge: 34, + description: "under soft max (35)", }, { period: { label: "monthly", value: 4 }, pscharge: 100, + description: "under soft max (35)", }, { period: { label: "every 2 weeks", value: 2 }, pscharge: 69, + description: "under soft max (35)", + }, + { + period: { label: "weekly", value: 1 }, + pscharge: 701, + description: "over hard max (700)", + }, + { + period: { label: "monthly", value: 4 }, + pscharge: 3034, + description: "over hard max (700)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + pscharge: 1401, + description: "over hard max (700)", }].each do |test_case| - it "returns false if pscharge is under soft max for general needs #{test_case[:period][:label]}(35)" do + it "returns false if pscharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.pscharge = test_case[:pscharge] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, pscharge: 99, + description: "under soft max (100)", }, { period: { label: "monthly", value: 4 }, pscharge: 400, + description: "under soft max (100)", }, { period: { label: "every 2 weeks", value: 2 }, pscharge: 199, + description: "under soft max (100)", + }, + { + period: { label: "weekly", value: 1 }, + pscharge: 701, + description: "over hard max (700)", + }, + { + period: { label: "monthly", value: 4 }, + pscharge: 3034, + description: "over hard max (700)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + pscharge: 1401, + description: "over hard max (700)", }].each do |test_case| - it "returns false if pscharge is under soft max for supported housing #{test_case[:period][:label]} (100)" do + it "returns false if pscharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.pscharge = test_case[:pscharge] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end end @@ -671,7 +779,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_pscharge_over_soft_max + expect(record).to be_pscharge_in_soft_max_range end end @@ -692,7 +800,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_pscharge_over_soft_max + expect(record).to be_pscharge_in_soft_max_range end end end @@ -707,7 +815,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end it "returns false if period is not given" do @@ -715,48 +823,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, pscharge: 24, + description: "under soft max (25)", }, { period: { label: "monthly", value: 4 }, pscharge: 88, + description: "under soft max (25)", }, { period: { label: "every 2 weeks", value: 2 }, pscharge: 49, + description: "under soft max (25)", + }, + { + period: { label: "weekly", value: 1 }, + pscharge: 201, + description: "over hard max (200)", + }, + { + period: { label: "monthly", value: 4 }, + pscharge: 867, + description: "over hard max (200)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + pscharge: 401, + description: "over hard max (200)", }].each do |test_case| - it "returns false if pscharge is under soft max for general needs #{test_case[:period][:label]}(25)" do + it "returns false if pscharge is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.pscharge = test_case[:pscharge] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, pscharge: 74, + description: "under soft max (75)", }, { period: { label: "monthly", value: 4 }, pscharge: 250, + description: "under soft max (75)", }, { period: { label: "every 2 weeks", value: 2 }, pscharge: 149, + description: "under soft max (75)", + }, + { + period: { label: "weekly", value: 1 }, + pscharge: 201, + description: "over hard max (200)", + }, + { + period: { label: "monthly", value: 4 }, + pscharge: 867, + description: "over hard max (200)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + pscharge: 401, + description: "over hard max (200)", }].each do |test_case| - it "returns false if pscharge is under soft max for supported housing #{test_case[:period][:label]} (75)" do + it "returns false if pscharge is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.pscharge = test_case[:pscharge] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_pscharge_over_soft_max + expect(record).not_to be_pscharge_in_soft_max_range end end @@ -777,7 +921,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_pscharge_over_soft_max + expect(record).to be_pscharge_in_soft_max_range end end @@ -798,13 +942,13 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_pscharge_over_soft_max + expect(record).to be_pscharge_in_soft_max_range end end end end - describe "supcharg_over_soft_max?" do + describe "supcharg_in_soft_max_range?" do context "and organisation is PRP" do before do record.owning_organisation.update(provider_type: "PRP") @@ -815,7 +959,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end it "returns false if period is not given" do @@ -823,48 +967,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, supcharg: 34, + description: "under soft max (35)", }, { period: { label: "monthly", value: 4 }, supcharg: 100, + description: "under soft max (35)", }, { period: { label: "every 2 weeks", value: 2 }, supcharg: 69, + description: "under soft max (35)", + }, + { + period: { label: "weekly", value: 1 }, + supcharg: 801, + description: "over hard max (800)", + }, + { + period: { label: "monthly", value: 4 }, + supcharg: 3467, + description: "over hard max (800)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + supcharg: 1601, + description: "over hard max (800)", }].each do |test_case| - it "returns false if supcharg is under soft max for general needs #{test_case[:period][:label]}(35)" do + it "returns false if supcharg is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.supcharg = test_case[:supcharg] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, supcharg: 84, + description: "under soft max (85)", }, { period: { label: "monthly", value: 4 }, supcharg: 320, + description: "under soft max (85)", }, { period: { label: "every 2 weeks", value: 2 }, supcharg: 169, + description: "under soft max (85)", + }, + { + period: { label: "weekly", value: 1 }, + supcharg: 801, + description: "over hard max (800)", + }, + { + period: { label: "monthly", value: 4 }, + supcharg: 3467, + description: "over hard max (800)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + supcharg: 1601, + description: "over hard max (800)", }].each do |test_case| - it "returns false if supcharg is under soft max for supported housing #{test_case[:period][:label]} (85)" do + it "returns false if supcharg is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.supcharg = test_case[:supcharg] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end end @@ -885,7 +1065,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_supcharg_over_soft_max + expect(record).to be_supcharg_in_soft_max_range end end @@ -906,7 +1086,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_supcharg_over_soft_max + expect(record).to be_supcharg_in_soft_max_range end end end @@ -921,7 +1101,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = 1 - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end it "returns false if period is not given" do @@ -929,48 +1109,84 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = nil - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end [{ period: { label: "weekly", value: 1 }, supcharg: 24, + description: "under soft max (25)", }, { period: { label: "monthly", value: 4 }, supcharg: 88, + description: "under soft max (25)", }, { period: { label: "every 2 weeks", value: 2 }, supcharg: 49, + description: "under soft max (25)", + }, + { + period: { label: "weekly", value: 1 }, + supcharg: 201, + description: "over hard max (200)", + }, + { + period: { label: "monthly", value: 4 }, + supcharg: 867, + description: "over hard max (200)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + supcharg: 401, + description: "over hard max (200)", }].each do |test_case| - it "returns false if supcharg is under soft max for general needs #{test_case[:period][:label]}(25)" do + it "returns false if supcharg is #{test_case[:description]} for general needs #{test_case[:period][:label]}" do record.supcharg = test_case[:supcharg] record.needstype = 1 record.period = test_case[:period][:value] - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end end [{ period: { label: "weekly", value: 1 }, supcharg: 74, + description: "under soft max (75)", }, { period: { label: "monthly", value: 4 }, supcharg: 250, + description: "under soft max (75)", }, { period: { label: "every 2 weeks", value: 2 }, supcharg: 149, + description: "under soft max (75)", + }, + { + period: { label: "weekly", value: 1 }, + supcharg: 201, + description: "over hard max (200)", + }, + { + period: { label: "monthly", value: 4 }, + supcharg: 867, + description: "over hard max (200)", + }, + { + period: { label: "every 2 weeks", value: 2 }, + supcharg: 401, + description: "over hard max (200)", }].each do |test_case| - it "returns false if supcharg is under soft max for supported housing #{test_case[:period][:label]} (75)" do + it "returns false if supcharg is #{test_case[:description]} for supported housing #{test_case[:period][:label]}" do record.supcharg = test_case[:supcharg] record.needstype = 2 record.period = test_case[:period][:value] - expect(record).not_to be_supcharg_over_soft_max + expect(record).not_to be_supcharg_in_soft_max_range end end @@ -991,7 +1207,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 1 record.period = test_case[:period][:value] - expect(record).to be_supcharg_over_soft_max + expect(record).to be_supcharg_in_soft_max_range end end @@ -1012,7 +1228,7 @@ RSpec.describe Validations::SoftValidations do record.needstype = 2 record.period = test_case[:period][:value] - expect(record).to be_supcharg_over_soft_max + expect(record).to be_supcharg_in_soft_max_range end end end