@ -102,7 +102,7 @@ RSpec.describe Validations::FinancialValidations do
. to include ( match I18n . t (
. to include ( match I18n . t (
" validations.financial.rent_period.invalid_for_org " ,
" validations.financial.rent_period.invalid_for_org " ,
org_name : organisation . name ,
org_name : organisation . name ,
rent_period : " every 2 weeks " ,
rent_period : " every 4 weeks " ,
) )
) )
end
end
end
end
@ -835,5 +835,97 @@ RSpec.describe Validations::FinancialValidations do
end
end
end
end
end
end
context " when the accommodation is care home " do
before do
record . is_carehome = 1
end
context " and charges are over the valid limit (£1000 per week) " do
it " validates charge when period is weekly for 52 weeks " do
record . period = 1
record . chcharge = 1001
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " weekly for 52 weeks " , max_chcharge : 1000 ) )
expect ( record . errors [ " period " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " weekly for 52 weeks " , max_chcharge : 1000 ) )
end
it " validates charge when period is monthly " do
record . period = 4
record . chcharge = 4334
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " 4 " , max_chcharge : 4333 ) )
expect ( record . errors [ " period " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " 4 " , max_chcharge : 4333 ) )
end
it " validates charge when period is every 2 weeks " do
record . period = 2
record . chcharge = 2001
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " 2 " , max_chcharge : 2000 ) )
expect ( record . errors [ " period " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " 2 " , max_chcharge : 2000 ) )
end
it " validates charge when period is every 4 weeks " do
record . period = 3
record . chcharge = 4001
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " every 4 weeks " , max_chcharge : 4000 ) )
expect ( record . errors [ " period " ] )
. to include ( match I18n . t ( " validations.financial.carehome.over_1000 " , min_chcharge : " £0 " , period : " every 4 weeks " , max_chcharge : 4000 ) )
end
end
context " and charges are within the valid limit (£1000 per week) " do
it " does not throw error when period is weekly for 52 weeks " do
record . period = 1
record . chcharge = 999
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] ) . to be_empty
expect ( record . errors [ " period " ] ) . to be_empty
end
it " does not throw error when period is monthly " do
record . period = 4
record . chcharge = 4333
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] ) . to be_empty
expect ( record . errors [ " period " ] ) . to be_empty
end
it " does not throw error when period is every 2 weeks " do
record . period = 2
record . chcharge = 1999 . 99
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] ) . to be_empty
expect ( record . errors [ " period " ] ) . to be_empty
end
it " does not throw error when period is every 4 weeks " do
record . period = 3
record . chcharge = 3999
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] ) . to be_empty
expect ( record . errors [ " period " ] ) . to be_empty
end
end
context " and charges are not provided " do
it " throws and error " do
record . period = 3
record . chcharge = nil
financial_validator . validate_care_home_charges ( record )
expect ( record . errors [ " chcharge " ] )
. to include ( match I18n . t ( " validations.financial.carehome.not_provided " , period : " every 4 weeks " ) )
end
end
end
end
end
end
end