From cd2938c1f91c7a41f8d91d19dbdab9735b1e4b2f Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 13 Sep 2023 11:24:53 +0100 Subject: [PATCH] add LA cases --- app/models/validations/soft_validations.rb | 14 ++- .../validations/soft_validations_spec.rb | 106 ++++++++++++++++++ 2 files changed, 114 insertions(+), 6 deletions(-) diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index f408b0ee8..eaef04381 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -99,12 +99,14 @@ module Validations::SoftValidations def scharge_over_soft_max? return unless scharge && period && needstype - - if needstype == 1 - weekly_value(scharge).present? && weekly_value(scharge) > 35 - else - weekly_value(scharge).present? && weekly_value(scharge) > 200 - end + 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 end private diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 472ed72cd..ee4519f50 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -482,5 +482,111 @@ RSpec.describe Validations::SoftValidations do end end end + + context "and organisation is LA" do + before do + record.owning_organisation.update(provider_type: "LA") + end + + it "returns false if scharge is not given" do + record.scharge = nil + record.needstype = 1 + record.period = 1 + + expect(record).not_to be_scharge_over_soft_max + end + + it "returns false if period is not given" do + record.scharge = 201 + record.needstype = 1 + record.period = nil + + expect(record).not_to be_scharge_over_soft_max + end + + [{ + period: { label: "weekly", value: 1 }, + scharge: 24, + }, + { + period: { label: "monthly", value: 4 }, + scharge: 88, + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 49, + }].each do |test_case| + it "returns false if scharge is under soft max for general needs #{test_case[:period][:label]}(25)" do + record.scharge = test_case[:scharge] + record.needstype = 1 + record.period = test_case[:period][:value] + + expect(record).not_to be_scharge_over_soft_max + end + end + + [{ + period: { label: "weekly", value: 1 }, + scharge: 99, + }, + { + period: { label: "monthly", value: 4 }, + scharge: 400, + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 199, + }].each do |test_case| + it "returns false if scharge is under soft max for supported housing #{test_case[:period][:label]} (100)" do + record.scharge = test_case[:scharge] + record.needstype = 2 + record.period = test_case[:period][:value] + + expect(record).not_to be_scharge_over_soft_max + end + end + + [{ + period: { label: "weekly", value: 1 }, + scharge: 26, + }, + { + period: { label: "monthly", value: 4 }, + scharge: 120, + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 51, + }].each do |test_case| + it "returns true if scharge is over soft max for general needs #{test_case[:period][:label]} (25)" do + record.scharge = test_case[:scharge] + record.needstype = 1 + record.period = test_case[:period][:value] + + expect(record).to be_scharge_over_soft_max + end + end + + [{ + period: { label: "weekly", value: 1 }, + scharge: 101, + }, + { + period: { label: "monthly", value: 4 }, + scharge: 450, + }, + { + period: { label: "every 2 weeks", value: 2 }, + scharge: 201, + }].each do |test_case| + it "returns true if scharge is over soft max for supported housing #{test_case[:period][:label]} (100)" do + record.scharge = test_case[:scharge] + record.needstype = 2 + record.period = test_case[:period][:value] + + expect(record).to be_scharge_over_soft_max + end + end + end end end