diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index c8aa65546..a28ec6116 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -53,7 +53,7 @@ class LettingsLog < Log scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze - OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze + OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode chcharge].freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze @@ -502,7 +502,7 @@ class LettingsLog < Log end def care_home_charge_expected_not_provided? - true + is_carehome == 1 && chcharge.blank? end private diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 3ce2b4527..b71d91a62 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -327,4 +327,38 @@ RSpec.describe Validations::SoftValidations do end end end + + describe "#care_home_charge_expected_not_provided?" do + it "returns false if is_carehome is 'No'" do + record.period = 3 + record.is_carehome = 0 + record.chcharge = nil + + expect(record).not_to be_care_home_charge_expected_not_provided + end + + it "returns false if is_carehome is not given" do + record.period = 3 + record.is_carehome = nil + record.chcharge = nil + + expect(record).not_to be_care_home_charge_expected_not_provided + end + + it "returns false if chcharge is given" do + record.period = 3 + record.is_carehome = 1 + record.chcharge = 40 + + expect(record).not_to be_care_home_charge_expected_not_provided + end + + it "returns true if is_carehome is 'Yes' and chcharge is not given" do + record.period = 3 + record.is_carehome = 1 + record.chcharge = nil + + expect(record).to be_care_home_charge_expected_not_provided + end + end end