Browse Source

CLDC-3218 Fix rent frequency soft validation bulk upload bug (#2249)

* feat: make charges soft validations check soft max range rather than just over soft max

* Update testst

* Allow soft max without a soft validation

* refactor tests

* Refactor test names

* feat: update unpend_and_confirm_soft_validations

* feat: refactor unpend_and_confirm_soft_validations and test the counts of value check fields to be confirmed are correct

* feat: further simplify unpend_and_confirm_soft_validations

* feat: further simplify unpend_and_confirm_soft_validations

---------

Co-authored-by: Kat <katrina@kosiak.co.uk>
pull/2270/head v0.4.20
natdeanlewissoftwire 10 months ago committed by GitHub
parent
commit
0b914af531
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 38
      app/helpers/charges_helper.rb
  2. 34
      app/models/bulk_upload.rb
  3. 2
      app/models/form/lettings/pages/pscharge_value_check.rb
  4. 2
      app/models/form/lettings/pages/scharge_value_check.rb
  5. 2
      app/models/form/lettings/pages/supcharg_value_check.rb
  6. 38
      app/models/validations/financial_validations.rb
  7. 41
      app/models/validations/soft_validations.rb
  8. 6
      config/forms/2022_2023.json
  9. 7
      spec/factories/lettings_log.rb
  10. 18
      spec/models/bulk_upload_spec.rb
  11. 318
      spec/models/validations/soft_validations_spec.rb

38
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

34
app/models/bulk_upload.rb

@ -78,37 +78,13 @@ class BulkUpload < ApplicationRecord
end end
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 def unpend_and_confirm_soft_validations
logs.find_each do |log| logs.find_each do |log|
log.retirement_value_check = 0 fields_to_confirm(log).each { |field| log[field] = 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
log.save! log.save!
end end
end end

2
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) def initialize(id, hsh, subsection)
super super
@id = "pscharge_value_check" @id = "pscharge_value_check"
@depends_on = [{ "pscharge_over_soft_max?" => true }] @depends_on = [{ "pscharge_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.pscharge.over_soft_max_title", "translation" => "soft_validations.pscharge.over_soft_max_title",
"arguments" => [{ "arguments" => [{

2
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) def initialize(id, hsh, subsection)
super super
@id = "scharge_value_check" @id = "scharge_value_check"
@depends_on = [{ "scharge_over_soft_max?" => true }] @depends_on = [{ "scharge_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.scharge.over_soft_max_title", "translation" => "soft_validations.scharge.over_soft_max_title",
"arguments" => [{ "arguments" => [{

2
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) def initialize(id, hsh, subsection)
super super
@id = "supcharg_value_check" @id = "supcharg_value_check"
@depends_on = [{ "supcharg_over_soft_max?" => true }] @depends_on = [{ "supcharg_in_soft_max_range?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.supcharg.over_soft_max_title", "translation" => "soft_validations.supcharg.over_soft_max_title",
"arguments" => [{ "arguments" => [{

38
app/models/validations/financial_validations.rb

@ -1,6 +1,7 @@
module Validations::FinancialValidations module Validations::FinancialValidations
include Validations::SharedValidations include Validations::SharedValidations
include MoneyFormattingHelper include MoneyFormattingHelper
include ChargesHelper
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record) def validate_outstanding_rent_amount(record)
@ -175,43 +176,6 @@ module Validations::FinancialValidations
private 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) def validate_charges(record)
return unless record.owning_organisation return unless record.owning_organisation

41
app/models/validations/soft_validations.rb

@ -1,4 +1,6 @@
module Validations::SoftValidations module Validations::SoftValidations
include ChargesHelper
ALLOWED_INCOME_RANGES = { ALLOWED_INCOME_RANGES = {
1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230), 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), 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" net_income_in_soft_max_range? ? "higher" : "lower"
end end
def scharge_over_soft_max? def scharge_in_soft_max_range?
return unless scharge && period && needstype return unless scharge && period && needstype && owning_organisation
return if weekly_value(scharge).blank? return if weekly_value(scharge).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 100 : 200 owning_organisation.provider_type == "LA" ? 100 : 200
end end
weekly_value(scharge) > max
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 end
def pscharge_over_soft_max? def pscharge_in_soft_max_range?
return unless pscharge && period && needstype return unless pscharge && period && needstype && owning_organisation
return if weekly_value(pscharge).blank? return if weekly_value(pscharge).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 75 : 100 owning_organisation.provider_type == "LA" ? 75 : 100
end end
weekly_value(pscharge) > max
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 end
def supcharg_over_soft_max? def supcharg_in_soft_max_range?
return unless supcharg && period && needstype return unless supcharg && period && needstype && owning_organisation
return if weekly_value(supcharg).blank? return if weekly_value(supcharg).blank?
max = if needstype == 1 soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35 owning_organisation.provider_type == "LA" ? 25 : 35
else else
owning_organisation.provider_type == "LA" ? 75 : 85 owning_organisation.provider_type == "LA" ? 75 : 85
end end
weekly_value(supcharg) > max
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 end
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [ PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [

6
config/forms/2022_2023.json

@ -8370,7 +8370,7 @@
"scharge_value_check": { "scharge_value_check": {
"depends_on": [ "depends_on": [
{ {
"scharge_over_soft_max?": true "scharge_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {
@ -8415,7 +8415,7 @@
"pscharge_value_check": { "pscharge_value_check": {
"depends_on": [ "depends_on": [
{ {
"pscharge_over_soft_max?": true "pscharge_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {
@ -8460,7 +8460,7 @@
"supcharg_value_check": { "supcharg_value_check": {
"depends_on": [ "depends_on": [
{ {
"supcharg_over_soft_max?": true "supcharg_in_soft_max_range?": true
} }
], ],
"title_text": { "title_text": {

7
spec/factories/lettings_log.rb

@ -24,13 +24,6 @@ FactoryBot.define do
rent_type { 1 } rent_type { 1 }
startdate { Time.zone.today } startdate { Time.zone.today }
end end
trait :soft_validations_triggered do
status { 1 }
hhmemb { 1 }
ecstat1 { 1 }
earnings { 750 }
incfreq { 1 }
end
trait :conditional_section_complete do trait :conditional_section_complete do
tenancycode { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 34 } age1 { 34 }

18
spec/models/bulk_upload_spec.rb

@ -18,4 +18,22 @@ RSpec.describe BulkUpload, type: :model do
end end
end 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 end

318
spec/models/validations/soft_validations_spec.rb

@ -376,7 +376,7 @@ RSpec.describe Validations::SoftValidations do
end end
end end
describe "scharge_over_soft_max?" do describe "scharge_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -387,7 +387,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -395,48 +395,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
scharge: 34, scharge: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 100, scharge: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 69, 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| }].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.scharge = test_case[:scharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 199, scharge: 199,
description: "under soft max (200)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 400, scharge: 400,
description: "under soft max (200)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 399, 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| }].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.scharge = test_case[:scharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -457,7 +493,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
@ -478,7 +514,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -493,7 +529,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_scharge_over_soft_max expect(record).not_to be_scharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -501,48 +537,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
scharge: 24, scharge: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 88, scharge: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 49, 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| }].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.scharge = test_case[:scharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
scharge: 99, scharge: 99,
description: "under soft max (100)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
scharge: 400, scharge: 400,
description: "under soft max (100)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
scharge: 199, 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| }].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.scharge = test_case[:scharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -563,7 +635,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
@ -584,13 +656,13 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
end end
describe "pscharge_over_soft_max?" do describe "pscharge_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -601,7 +673,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -609,48 +681,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
pscharge: 34, pscharge: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 100, pscharge: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 69, 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| }].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.pscharge = test_case[:pscharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 99, pscharge: 99,
description: "under soft max (100)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 400, pscharge: 400,
description: "under soft max (100)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 199, 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| }].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.pscharge = test_case[:pscharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -671,7 +779,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
@ -692,7 +800,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -707,7 +815,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_pscharge_over_soft_max expect(record).not_to be_pscharge_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -715,48 +823,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
pscharge: 24, pscharge: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 88, pscharge: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 49, 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| }].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.pscharge = test_case[:pscharge]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
pscharge: 74, pscharge: 74,
description: "under soft max (75)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
pscharge: 250, pscharge: 250,
description: "under soft max (75)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
pscharge: 149, 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| }].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.pscharge = test_case[:pscharge]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -777,7 +921,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
@ -798,13 +942,13 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
end end
describe "supcharg_over_soft_max?" do describe "supcharg_in_soft_max_range?" do
context "and organisation is PRP" do context "and organisation is PRP" do
before do before do
record.owning_organisation.update(provider_type: "PRP") record.owning_organisation.update(provider_type: "PRP")
@ -815,7 +959,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -823,48 +967,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
supcharg: 34, supcharg: 34,
description: "under soft max (35)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 100, supcharg: 100,
description: "under soft max (35)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 69, 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| }].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.supcharg = test_case[:supcharg]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 84, supcharg: 84,
description: "under soft max (85)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 320, supcharg: 320,
description: "under soft max (85)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 169, 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| }].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.supcharg = test_case[:supcharg]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -885,7 +1065,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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 end
@ -906,7 +1086,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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 end
end end
@ -921,7 +1101,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = 1 record.period = 1
expect(record).not_to be_supcharg_over_soft_max expect(record).not_to be_supcharg_in_soft_max_range
end end
it "returns false if period is not given" do it "returns false if period is not given" do
@ -929,48 +1109,84 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = nil record.period = nil
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 }, period: { label: "weekly", value: 1 },
supcharg: 24, supcharg: 24,
description: "under soft max (25)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 88, supcharg: 88,
description: "under soft max (25)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 49, 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| }].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.supcharg = test_case[:supcharg]
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly", value: 1 },
supcharg: 74, supcharg: 74,
description: "under soft max (75)",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "monthly", value: 4 },
supcharg: 250, supcharg: 250,
description: "under soft max (75)",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
supcharg: 149, 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| }].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.supcharg = test_case[:supcharg]
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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
end end
@ -991,7 +1207,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 1 record.needstype = 1
record.period = test_case[:period][:value] 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 end
@ -1012,7 +1228,7 @@ RSpec.describe Validations::SoftValidations do
record.needstype = 2 record.needstype = 2
record.period = test_case[:period][:value] 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 end
end end

Loading…
Cancel
Save