Browse Source

CLDC-4203: Renumber source of referral fields

pull/3189/head
samyou-softwire 1 month ago
parent
commit
0529b84386
  1. 6
      app/helpers/bulk_upload/lettings_log_to_csv.rb
  2. 178
      app/services/bulk_upload/lettings/year2026/row_parser.rb
  3. 270
      spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb

6
app/helpers/bulk_upload/lettings_log_to_csv.rb

@ -240,6 +240,9 @@ class BulkUpload::LettingsLogToCsv
cap, cap,
accessible_register, accessible_register,
log.owning_organisation.la? ? log.referral_register : nil, log.owning_organisation.la? ? log.referral_register : nil,
log.owning_organisation.prp? ? log.referral_register : nil,
log.referral_noms,
log.referral_org, # 148
net_income_known, net_income_known,
log.incfreq, log.incfreq,
log.earnings, log.earnings,
@ -254,9 +257,6 @@ class BulkUpload::LettingsLogToCsv
log.supcharg, log.supcharg,
log.hbrentshortfall, log.hbrentshortfall,
log.tshortfall, log.tshortfall,
log.owning_organisation.prp? ? log.referral_register : nil,
log.referral_noms,
log.referral_org, # 148
] ]
end end

178
app/services/bulk_upload/lettings/year2026/row_parser.rb

@ -136,22 +136,22 @@ class BulkUpload::Lettings::Year2026::RowParser
field_129: "Was the letting made under the Common Housing Register (CHR)?", field_129: "Was the letting made under the Common Housing Register (CHR)?",
field_130: "Was the letting made under the Accessible Register?", field_130: "Was the letting made under the Accessible Register?",
field_131: "What was the source of referral for this letting? - LA properties", field_131: "What was the source of referral for this letting? - LA properties",
field_132: "Do you know the household’s combined total income after tax?", field_132: "What was the source of referral for this letting? - PRP properties part 1",
field_133: "How often does the household receive income?", field_133: "What was the source of referral for this letting? - PRP properties part 2",
field_134: "How much income does the household have in total?", field_134: "What was the source of referral for this letting? - PRP properties part 3",
field_135: "Is the tenant likely to be receiving any of these housing-related benefits?", field_135: "Do you know the household’s combined total income after tax?",
field_136: "How much of the household’s income is from Universal Credit, state pensions or benefits?", field_136: "How often does the household receive income?",
field_137: "Does the household pay rent or other charges for the accommodation?", field_137: "How much income does the household have in total?",
field_138: "How often does the household pay rent and other charges?", field_138: "Is the tenant likely to be receiving any of these housing-related benefits?",
field_139: "What is the basic rent?", field_139: "How much of the household’s income is from Universal Credit, state pensions or benefits?",
field_140: "What is the service charge?", field_140: "Does the household pay rent or other charges for the accommodation?",
field_141: "What is the personal service charge?", field_141: "How often does the household pay rent and other charges?",
field_142: "What is the support charge?", field_142: "What is the basic rent?",
field_143: "After the household has received any housing-related benefits, will they still need to pay for rent and charges?", field_143: "What is the service charge?",
field_144: "What do you expect the outstanding amount to be?", field_144: "What is the personal service charge?",
field_145: "What was the source of referral for this letting? - PRP properties part 1", field_145: "What is the support charge?",
field_146: "What was the source of referral for this letting? - PRP properties part 2", field_146: "After the household has received any housing-related benefits, will they still need to pay for rent and charges?",
field_147: "What was the source of referral for this letting? - PRP properties part 3", field_147: "What do you expect the outstanding amount to be?",
}.freeze }.freeze
RENT_TYPE_BU_MAPPING = { RENT_TYPE_BU_MAPPING = {
@ -287,19 +287,19 @@ class BulkUpload::Lettings::Year2026::RowParser
attribute :field_129, :integer attribute :field_129, :integer
attribute :field_130, :integer attribute :field_130, :integer
attribute :field_131, :integer attribute :field_131, :integer
attribute :field_132, :integer
attribute :field_133, :integer
attribute :field_134, :decimal
attribute :field_135, :integer attribute :field_135, :integer
attribute :field_136, :integer attribute :field_136, :integer
attribute :field_137, :integer attribute :field_137, :decimal
attribute :field_138, :integer attribute :field_138, :integer
attribute :field_139, :decimal attribute :field_139, :integer
attribute :field_140, :decimal attribute :field_140, :integer
attribute :field_141, :decimal attribute :field_141, :integer
attribute :field_142, :decimal attribute :field_142, :decimal
attribute :field_143, :integer attribute :field_143, :decimal
attribute :field_144, :decimal attribute :field_144, :decimal
attribute :field_145, :decimal
attribute :field_146, :integer
attribute :field_147, :decimal
attribute :field_43, :string attribute :field_43, :string
attribute :field_44, :string attribute :field_44, :string
@ -318,9 +318,9 @@ class BulkUpload::Lettings::Year2026::RowParser
attribute :field_87, :integer attribute :field_87, :integer
attribute :field_88, :string attribute :field_88, :string
attribute :field_145, :integer attribute :field_132, :integer
attribute :field_146, :integer attribute :field_133, :integer
attribute :field_147, :integer attribute :field_134, :integer
validate :validate_valid_radio_option, on: :before_log validate :validate_valid_radio_option, on: :before_log
@ -581,8 +581,8 @@ class BulkUpload::Lettings::Year2026::RowParser
"field_42", # sexrab1 "field_42", # sexrab1
"field_47", # ecstat1 "field_47", # ecstat1
) )
if [field_139, field_140, field_141, field_142].all?(&:present?) if [field_142, field_143, field_144, field_145].all?(&:present?)
hash.merge({ "tcharge" => [field_139, field_140, field_141, field_142].sum }) hash.merge({ "tcharge" => [field_142, field_143, field_144, field_145].sum })
else else
hash hash
end end
@ -591,7 +591,7 @@ class BulkUpload::Lettings::Year2026::RowParser
def add_duplicate_found_in_spreadsheet_errors def add_duplicate_found_in_spreadsheet_errors
spreadsheet_duplicate_hash.each_key do |field| spreadsheet_duplicate_hash.each_key do |field|
if field == "tcharge" if field == "tcharge"
%w[field_139 field_140 field_141 field_142].each do |sub_field| %w[field_142 field_143 field_144 field_145].each do |sub_field|
errors.add(sub_field, I18n.t("#{ERROR_BASE_KEY}.spreadsheet_dupe"), category: :setup) errors.add(sub_field, I18n.t("#{ERROR_BASE_KEY}.spreadsheet_dupe"), category: :setup)
end end
else else
@ -965,13 +965,13 @@ private
end end
def validate_all_charges_given def validate_all_charges_given
return if supported_housing? && field_139 == 1 return if supported_housing? && field_142 == 1
blank_charge_fields, other_charge_fields = { blank_charge_fields, other_charge_fields = {
field_139: "basic rent", field_142: "basic rent",
field_140: "service charge", field_143: "service charge",
field_141: "personal service charge", field_144: "personal service charge",
field_142: "support charge", field_145: "support charge",
}.partition { |field, _| public_send(field).blank? }.map(&:to_h) }.partition { |field, _| public_send(field).blank? }.map(&:to_h)
blank_charge_fields.each do |field, charge| blank_charge_fields.each do |field, charge|
@ -987,7 +987,7 @@ private
end end
def all_charges_given? def all_charges_given?
field_139.present? && field_140.present? && field_141.present? && field_142.present? field_142.present? && field_143.present? && field_144.present? && field_145.present?
end end
def setup_question?(question) def setup_question?(question)
@ -1011,11 +1011,11 @@ private
errors.add(:field_41, error_message) # age1 errors.add(:field_41, error_message) # age1
errors.add(:field_42, error_message) # sexrab1 errors.add(:field_42, error_message) # sexrab1
errors.add(:field_47, error_message) # ecstat1 errors.add(:field_47, error_message) # ecstat1
errors.add(:field_137, error_message) unless general_needs? # household_charge errors.add(:field_140, error_message) unless general_needs? # household_charge
errors.add(:field_139, error_message) # brent errors.add(:field_142, error_message) # brent
errors.add(:field_140, error_message) # scharge errors.add(:field_143, error_message) # scharge
errors.add(:field_141, error_message) # pscharge errors.add(:field_144, error_message) # pscharge
errors.add(:field_142, error_message) # chcharge errors.add(:field_145, error_message) # chcharge
end end
end end
@ -1029,31 +1029,31 @@ private
def field_referral_register_prp_valid? def field_referral_register_prp_valid?
if owning_organisation&.prp? if owning_organisation&.prp?
[5, 6, 7, 8, 9].include?(field_145) [5, 6, 7, 8, 9].include?(field_132)
else else
field_145.blank? field_132.blank?
end end
end end
def field_referral_noms_valid? def field_referral_noms_valid?
case field_145 case field_132
when 6 when 6
[1, 2, 3, 4].include?(field_146) [1, 2, 3, 4].include?(field_133)
when 7 when 7
[5, 6, 7, 8].include?(field_146) [5, 6, 7, 8].include?(field_133)
else else
field_146.blank? field_133.blank?
end end
end end
def field_referral_org_valid? def field_referral_org_valid?
case field_146 case field_133
when 1 when 1
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(field_147) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(field_134)
when 7 when 7
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20].include?(field_147) [11, 12, 13, 14, 15, 16, 17, 18, 19, 20].include?(field_134)
else else
field_147.blank? field_134.blank?
end end
end end
@ -1065,7 +1065,7 @@ private
return if renewal? return if renewal?
return if referral_fields_valid? return if referral_fields_valid?
%i[field_131 field_145 field_146 field_147].each do |field| %i[field_131 field_132 field_133 field_134].each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.referral.invalid_option")) errors.add(field, I18n.t("#{ERROR_BASE_KEY}.referral.invalid_option"))
end end
end end
@ -1181,25 +1181,25 @@ private
accessible_register: %i[field_130], accessible_register: %i[field_130],
letting_allocation: %i[field_127 field_128 field_129 field_130], letting_allocation: %i[field_127 field_128 field_129 field_130],
referral_register: %i[field_131 field_145], referral_register: %i[field_131 field_132],
referral_noms: %i[field_146], referral_noms: %i[field_133],
referral_org: %i[field_147], referral_org: %i[field_134],
net_income_known: %i[field_132], net_income_known: %i[field_135],
incfreq: %i[field_133], incfreq: %i[field_136],
earnings: %i[field_134], earnings: %i[field_137],
hb: %i[field_135], hb: %i[field_138],
benefits: %i[field_136], benefits: %i[field_139],
period: %i[field_138], period: %i[field_141],
brent: %i[field_139], brent: %i[field_142],
scharge: %i[field_140], scharge: %i[field_143],
pscharge: %i[field_141], pscharge: %i[field_144],
supcharg: %i[field_142], supcharg: %i[field_145],
tcharge: %i[field_139 field_140 field_141 field_142], tcharge: %i[field_142 field_143 field_144 field_145],
household_charge: %i[field_137], household_charge: %i[field_140],
hbrentshortfall: %i[field_143], hbrentshortfall: %i[field_146],
tshortfall: %i[field_144], tshortfall: %i[field_147],
unitletas: %i[field_17], unitletas: %i[field_17],
rsnvac: %i[field_16], rsnvac: %i[field_16],
@ -1390,19 +1390,19 @@ private
attributes["net_income_known"] = net_income_known attributes["net_income_known"] = net_income_known
attributes["earnings"] = earnings attributes["earnings"] = earnings
attributes["incfreq"] = field_133 attributes["incfreq"] = field_136
attributes["hb"] = field_135 attributes["hb"] = field_138
attributes["benefits"] = field_136 attributes["benefits"] = field_139
attributes["period"] = field_138 attributes["period"] = field_141
attributes["brent"] = field_139 if all_charges_given? attributes["brent"] = field_142 if all_charges_given?
attributes["scharge"] = field_140 if all_charges_given? attributes["scharge"] = field_143 if all_charges_given?
attributes["pscharge"] = field_141 if all_charges_given? attributes["pscharge"] = field_144 if all_charges_given?
attributes["supcharg"] = field_142 if all_charges_given? attributes["supcharg"] = field_145 if all_charges_given?
attributes["household_charge"] = supported_housing? ? field_137 : nil attributes["household_charge"] = supported_housing? ? field_140 : nil
attributes["hbrentshortfall"] = field_143 attributes["hbrentshortfall"] = field_146
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
attributes["tshortfall"] = field_144 attributes["tshortfall"] = field_147
attributes["hhmemb"] = hhmemb attributes["hhmemb"] = hhmemb
@ -1697,7 +1697,7 @@ private
end end
def net_income_known def net_income_known
case field_132 case field_135
when 1 when 1
0 0
when 2 when 2
@ -1708,11 +1708,11 @@ private
end end
def earnings def earnings
field_134.round if field_134.present? field_137.round if field_137.present?
end end
def tshortfall_known def tshortfall_known
field_143 == 1 ? 0 : 1 field_146 == 1 ? 0 : 1
end end
def hhmemb def hhmemb
@ -1807,7 +1807,7 @@ private
if owning_organisation.la? if owning_organisation.la?
field_131 field_131
else else
field_145 field_132
end end
end end
@ -1816,7 +1816,7 @@ private
return unless referral_fields_valid? return unless referral_fields_valid?
if owning_organisation.prp? if owning_organisation.prp?
field_146 field_133
end end
end end
@ -1825,7 +1825,7 @@ private
return unless referral_fields_valid? return unless referral_fields_valid?
if owning_organisation.prp? if owning_organisation.prp?
field_147 field_134
end end
end end
end end

270
spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb

@ -119,7 +119,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when calling the method multiple times" do context "when calling the method multiple times" do
let(:attributes) { { bulk_upload:, field_144: 2 } } let(:attributes) { { bulk_upload:, field_147: 2 } }
it "does not add keep adding errors to the pile" do it "does not add keep adding errors to the pile" do
parser.valid? parser.valid?
@ -225,19 +225,19 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
field_131: "1", field_131: "1",
field_132: "1",
field_133: "2",
field_134: "2300",
field_135: "1", field_135: "1",
field_136: "4", field_136: "2",
field_137: "2300",
field_138: "4", field_138: "1",
field_139: "1234.56", field_139: "4",
field_140: "43.32",
field_141: "13.14", field_141: "4",
field_142: "101.11", field_142: "1234.56",
field_143: "1", field_143: "43.32",
field_144: "34.56", field_144: "13.14",
field_145: "101.11",
field_146: "1",
field_147: "34.56",
field_16: "15", field_16: "15",
field_29: now.day.to_s, field_29: now.day.to_s,
@ -316,10 +316,10 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
:field_41, # age1 :field_41, # age1
:field_42, # sexrab1 :field_42, # sexrab1
:field_47, # ecstat1 :field_47, # ecstat1
:field_139, # brent :field_142, # brent
:field_140, # scharge :field_143, # scharge
:field_141, # pscharge :field_144, # pscharge
:field_142, # supcharg :field_145, # supcharg
].each do |field| ].each do |field|
expect(parser.errors[field]).to include(error_message) expect(parser.errors[field]).to include(error_message)
end end
@ -344,7 +344,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when a supported housing log already exists in the db" do # TODO: CLDC-4119: Beware! The `postcode_full` method in the `LettingsLog` class may cause issues with these supported housing log duplicate detection tests after postcode is added. See comment on the `postcode_full` method for details. context "when a supported housing log already exists in the db" do # TODO: CLDC-4119: Beware! The `postcode_full` method in the `LettingsLog` class may cause issues with these supported housing log duplicate detection tests after postcode is added. See comment on the `postcode_full` method for details.
let(:attributes) { valid_attributes.merge({ field_4: "2", field_5: "S#{scheme.id}", field_6: location.old_visible_id, field_35: 3, field_137: 0 }) } let(:attributes) { valid_attributes.merge({ field_4: "2", field_5: "S#{scheme.id}", field_6: location.old_visible_id, field_35: 3, field_140: 0 }) }
before do before do
parser.log.save! parser.log.save!
@ -370,10 +370,10 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
:field_41, # age1 :field_41, # age1
:field_42, # sexrab1 :field_42, # sexrab1
:field_47, # ecstat1 :field_47, # ecstat1
:field_139, # brent :field_142, # brent
:field_140, # scharge :field_143, # scharge
:field_141, # pscharge :field_144, # pscharge
:field_142, # supcharg :field_145, # supcharg
].each do |field| ].each do |field|
expect(parser.errors[field]).to include(error_message) expect(parser.errors[field]).to include(error_message)
end end
@ -412,10 +412,10 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
:field_41, # age1 :field_41, # age1
:field_42, # sexrab1 :field_42, # sexrab1
:field_47, # ecstat1 :field_47, # ecstat1
:field_139, # brent :field_142, # brent
:field_140, # scharge :field_143, # scharge
:field_141, # pscharge :field_144, # pscharge
:field_142, # supcharg :field_145, # supcharg
].each do |field| ].each do |field|
expect(parser.errors[field]).to include(error_message) expect(parser.errors[field]).to include(error_message)
end end
@ -473,7 +473,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
field_11: "2", field_11: "2",
field_6: location.id, field_6: location.id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_137: 0, field_140: 0,
field_35: 4 }) field_35: 4 })
end end
@ -501,7 +501,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
:field_41, # age1 :field_41, # age1
:field_42, # sexrab1 :field_42, # sexrab1
:field_47, # ecstat1 :field_47, # ecstat1
:field_137, # household_charge :field_140, # household_charge
].each do |field| ].each do |field|
expect(parser.errors[field]).to include(error_message) expect(parser.errors[field]).to include(error_message)
end end
@ -517,8 +517,8 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
let(:attributes) do let(:attributes) do
setup_section_params.merge({ field_5: nil, setup_section_params.merge({ field_5: nil,
field_6: nil, field_6: nil,
field_139: 300, field_142: 300,
field_138: 1, field_141: 1,
field_28: 1, field_28: 1,
field_4: 1, field_4: 1,
field_11: "2", field_11: "2",
@ -608,13 +608,13 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
context "when there is a :skip_bu_error error" do context "when there is a :skip_bu_error error" do
let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) } let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) }
let(:attributes) { valid_attributes.merge({ field_138: 3, field_142: 80 }) } let(:attributes) { valid_attributes.merge({ field_141: 3, field_145: 80 }) }
it "does not add that error" do it "does not add that error" do
parser.valid? parser.valid?
expect(parser.log.errors.map(&:attribute).sort).to eql(%i[managing_organisation_id period]) expect(parser.log.errors.map(&:attribute).sort).to eql(%i[managing_organisation_id period])
expect(parser.errors.map(&:attribute)).to eql(%i[field_138]) expect(parser.errors.map(&:attribute)).to eql(%i[field_141])
end end
end end
end end
@ -1151,7 +1151,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
end end
describe "#field_131, field_145, field_146, field_147" do # referral describe "#field_131, field_132, field_133, field_134" do # referral
context "when org is LA" do context "when org is LA" do
let(:owning_org) { create(:organisation, :la, :with_old_visible_id) } let(:owning_org) { create(:organisation, :la, :with_old_visible_id) }
@ -1166,9 +1166,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
it "does not add an error" do it "does not add an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
end end
@ -1178,9 +1178,9 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
@ -1190,34 +1190,34 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and other fields are given" do context "and other fields are given" do
let(:attributes) { renewal_attributes.merge({ field_131: 1, field_145: 5, field_146: 1, field_87: 1 }) } let(:attributes) { renewal_attributes.merge({ field_131: 1, field_132: 5, field_133: 1, field_87: 1 }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
end end
context "and is renewal" do context "and is renewal" do
let(:attributes) { org_attributes.merge({ field_7: 1, field_131: 1, field_145: 5, field_146: 1, field_147: 1 }) } let(:attributes) { org_attributes.merge({ field_7: 1, field_131: 1, field_132: 5, field_133: 1, field_134: 1 }) }
it "does not add an error for referral fields" do it "does not add an error for referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
end end
end end
@ -1230,141 +1230,141 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
context "and not renewal" do context "and not renewal" do
let(:renewal_attributes) { org_attributes.merge({ field_7: nil }) } let(:renewal_attributes) { org_attributes.merge({ field_7: nil }) }
context "and field_145 is valid and does not expect an answer for field_146" do context "and field_132 is valid and does not expect an answer for field_133" do
let(:attributes) { renewal_attributes.merge({ field_145: 5 }) } let(:attributes) { renewal_attributes.merge({ field_132: 5 }) }
it "does not add an error" do it "does not add an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
context "and later fields are given" do context "and later fields are given" do
let(:attributes) { renewal_attributes.merge({ field_145: 5, field_146: 1, field_147: 1 }) } let(:attributes) { renewal_attributes.merge({ field_132: 5, field_133: 1, field_134: 1 }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
end end
context "and field_145 is invalid" do context "and field_132 is invalid" do
let(:attributes) { renewal_attributes.merge({ field_145: 1 }) } # LA option let(:attributes) { renewal_attributes.merge({ field_132: 1 }) } # LA option
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and field_145 is blank" do context "and field_132 is blank" do
let(:attributes) { renewal_attributes.merge({ field_145: nil }) } let(:attributes) { renewal_attributes.merge({ field_132: nil }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and field_145 is valid and expects an answer for field_146" do context "and field_132 is valid and expects an answer for field_133" do
let(:field_146_attributes) { renewal_attributes.merge({ field_145: 6 }) } let(:field_146_attributes) { renewal_attributes.merge({ field_132: 6 }) }
context "and field_146 is valid and does not expect an answer for field_147" do context "and field_133 is valid and does not expect an answer for field_134" do
let(:attributes) { field_146_attributes.merge({ field_146: 2 }) } let(:attributes) { field_146_attributes.merge({ field_133: 2 }) }
it "does not add an error" do it "does not add an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
context "and later fields are given" do context "and later fields are given" do
let(:attributes) { field_146_attributes.merge({ field_146: 2, field_147: 1 }) } let(:attributes) { field_146_attributes.merge({ field_133: 2, field_134: 1 }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
end end
context "and field_146 is invalid" do context "and field_133 is invalid" do
let(:attributes) { field_146_attributes.merge({ field_146: 5 }) } # needs field_145 to be 7 let(:attributes) { field_146_attributes.merge({ field_133: 5 }) } # needs field_132 to be 7
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and field_146 is blank" do context "and field_133 is blank" do
let(:attributes) { field_146_attributes.merge({ field_146: nil }) } let(:attributes) { field_146_attributes.merge({ field_133: nil }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and field_146 is valid and expects an answer for field_147" do context "and field_133 is valid and expects an answer for field_134" do
let(:field_147_attributes) { field_146_attributes.merge({ field_146: 1 }) } let(:field_147_attributes) { field_146_attributes.merge({ field_133: 1 }) }
context "and field_147 is valid" do context "and field_134 is valid" do
let(:attributes) { field_147_attributes.merge({ field_147: 1 }) } let(:attributes) { field_147_attributes.merge({ field_134: 1 }) }
it "does not add an error" do it "does not add an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
end end
context "and field_147 is invalid" do context "and field_134 is invalid" do
let(:attributes) { field_147_attributes.merge({ field_147: 11 }) } # needs field_146 to be 7 let(:attributes) { field_147_attributes.merge({ field_134: 11 }) } # needs field_133 to be 7
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
context "and field_147 is blank" do context "and field_134 is blank" do
let(:attributes) { field_147_attributes.merge({ field_147: nil }) } let(:attributes) { field_147_attributes.merge({ field_134: nil }) }
it "adds errors to all referral fields" do it "adds errors to all referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_present expect(parser.errors[:field_131]).to be_present
expect(parser.errors[:field_145]).to be_present expect(parser.errors[:field_132]).to be_present
expect(parser.errors[:field_146]).to be_present expect(parser.errors[:field_133]).to be_present
expect(parser.errors[:field_147]).to be_present expect(parser.errors[:field_134]).to be_present
end end
end end
end end
@ -1372,14 +1372,14 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "and is renewal" do context "and is renewal" do
let(:attributes) { org_attributes.merge({ field_7: 1, field_131: 1, field_145: 5, field_146: 1, field_147: 1 }) } let(:attributes) { org_attributes.merge({ field_7: 1, field_131: 1, field_132: 5, field_133: 1, field_134: 1 }) }
it "does not add an error for referral fields" do it "does not add an error for referral fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_131]).to be_blank expect(parser.errors[:field_131]).to be_blank
expect(parser.errors[:field_145]).to be_blank expect(parser.errors[:field_132]).to be_blank
expect(parser.errors[:field_146]).to be_blank expect(parser.errors[:field_133]).to be_blank
expect(parser.errors[:field_147]).to be_blank expect(parser.errors[:field_134]).to be_blank
end end
end end
end end
@ -2095,22 +2095,22 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when soft validation is triggered and not required" do context "when soft validation is triggered and not required" do
let(:attributes) { setup_section_params.merge({ field_139: 120, field_140: 120, field_141: 120, field_142: 120, field_138: 1, field_28: 1, field_4: 1, field_11: "2", field_25: "E09000008" }) } let(:attributes) { setup_section_params.merge({ field_142: 120, field_143: 120, field_144: 120, field_145: 120, field_141: 1, field_28: 1, field_4: 1, field_11: "2", field_25: "E09000008" }) }
it "adds an error to the relevant fields" do it "adds an error to the relevant fields" do
parser.valid? parser.valid?
expect(parser.errors.where(:field_139, category: :soft_validation)).to be_present expect(parser.errors.where(:field_142, category: :soft_validation)).to be_present
end end
it "populates with correct error message" do it "populates with correct error message" do
parser.valid? parser.valid?
expect(parser.errors.where(:field_139, category: :soft_validation).count).to be(1) expect(parser.errors.where(:field_142, category: :soft_validation).count).to be(1)
expect(parser.errors.where(:field_139, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.") expect(parser.errors.where(:field_142, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.")
end end
end end
context "when an invalid ecstat1 is given" do context "when an invalid ecstat1 is given" do
let(:attributes) { setup_section_params.merge({ field_47: 11, field_134: 123, field_133: 1 }) } let(:attributes) { setup_section_params.merge({ field_47: 11, field_137: 123, field_136: 1 }) }
it "does not run net income soft validations validation" do it "does not run net income soft validations validation" do
parser.valid? parser.valid?
@ -2573,7 +2573,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
describe "#net_income_known" do describe "#net_income_known" do
context "when 1" do context "when 1" do
let(:attributes) { { bulk_upload:, field_132: "1" } } let(:attributes) { { bulk_upload:, field_135: "1" } }
it "sets value from correct mapping" do it "sets value from correct mapping" do
expect(parser.log.net_income_known).to eq(0) expect(parser.log.net_income_known).to eq(0)
@ -2581,7 +2581,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when 2" do context "when 2" do
let(:attributes) { { bulk_upload:, field_132: "2" } } let(:attributes) { { bulk_upload:, field_135: "2" } }
it "sets value from correct mapping" do it "sets value from correct mapping" do
expect(parser.log.net_income_known).to eq(1) expect(parser.log.net_income_known).to eq(1)
@ -2589,7 +2589,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when 3" do context "when 3" do
let(:attributes) { { bulk_upload:, field_132: "3" } } let(:attributes) { { bulk_upload:, field_135: "3" } }
it "sets value from correct mapping" do it "sets value from correct mapping" do
expect(parser.log.net_income_known).to eq(2) expect(parser.log.net_income_known).to eq(2)
@ -2681,7 +2681,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
describe "#earnings" do describe "#earnings" do
let(:attributes) { { bulk_upload:, field_134: "104.50" } } let(:attributes) { { bulk_upload:, field_137: "104.50" } }
it "rounds to the nearest whole pound" do it "rounds to the nearest whole pound" do
expect(parser.log.earnings).to eq(105) expect(parser.log.earnings).to eq(105)
@ -2716,7 +2716,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
describe "#household_charge" do describe "#household_charge" do
context "when log is general needs" do context "when log is general needs" do
let(:attributes) { { bulk_upload:, field_4: 1, field_137: "1" } } let(:attributes) { { bulk_upload:, field_4: 1, field_140: "1" } }
it "sets correct value from mapping" do it "sets correct value from mapping" do
expect(parser.log.household_charge).to eq(nil) expect(parser.log.household_charge).to eq(nil)
@ -2724,7 +2724,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
context "when log is supported housing" do context "when log is supported housing" do
let(:attributes) { { bulk_upload:, field_4: 2, field_137: "1" } } let(:attributes) { { bulk_upload:, field_4: 2, field_140: "1" } }
it "sets correct value from mapping" do it "sets correct value from mapping" do
expect(parser.log.household_charge).to eq(1) expect(parser.log.household_charge).to eq(1)
@ -2733,14 +2733,14 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
describe "#supcharg" do describe "#supcharg" do
let(:attributes) { setup_section_params.merge({ field_139: "330", field_140: "0", field_141: "0", field_142: "123.45" }) } let(:attributes) { setup_section_params.merge({ field_142: "330", field_143: "0", field_144: "0", field_145: "123.45" }) }
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do context "when other charges are not given" do
let(:attributes) { setup_section_params.merge({ field_142: "123.45", field_139: nil, field_140: nil, field_141: nil }) } let(:attributes) { setup_section_params.merge({ field_145: "123.45", field_142: nil, field_143: nil, field_144: nil }) }
it "does not set charges values" do it "does not set charges values" do
parser.log.save! parser.log.save!
@ -2753,15 +2753,15 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
it "adds an error to all missing charges" do it "adds an error to all missing charges" do
parser.valid? parser.valid?
expect(parser.errors[:field_139]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "basic rent")]) expect(parser.errors[:field_142]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "basic rent")])
expect(parser.errors[:field_140]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "service charge")]) expect(parser.errors[:field_143]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "service charge")])
expect(parser.errors[:field_141]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "personal service charge")]) expect(parser.errors[:field_144]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "personal service charge")])
expect(parser.errors[:field_142]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")]) expect(parser.errors[:field_145]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")])
end end
end end
context "when supscharg is not given" do context "when supscharg is not given" do
let(:attributes) { setup_section_params.merge({ field_138: 1, field_139: "350.45", field_140: "0", field_141: "0", field_142: nil }) } let(:attributes) { setup_section_params.merge({ field_141: 1, field_142: "350.45", field_143: "0", field_144: "0", field_145: nil }) }
it "does not set charges values" do it "does not set charges values" do
parser.log.save! parser.log.save!
@ -2775,16 +2775,16 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
it "adds an error to all charges" do it "adds an error to all charges" do
parser.valid? parser.valid?
expect(parser.errors[:field_139]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")]) expect(parser.errors[:field_142]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")])
expect(parser.errors[:field_140]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")]) expect(parser.errors[:field_143]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")])
expect(parser.errors[:field_141]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")]) expect(parser.errors[:field_144]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.related_to_missing_charge")])
expect(parser.errors[:field_142]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "support charge")]) expect(parser.errors[:field_145]).to eql([I18n.t("validations.lettings.2026.bulk_upload.charges.missing_charges", sentence_fragment: "support charge")])
end end
end end
end end
describe "#pscharge" do describe "#pscharge" do
let(:attributes) { { bulk_upload:, field_139: "111.45", field_140: "0", field_141: "123.45", field_142: "0" } } let(:attributes) { { bulk_upload:, field_142: "111.45", field_143: "0", field_144: "123.45", field_145: "0" } }
it "sets value given" do it "sets value given" do
expect(parser.log.pscharge).to eq(123.45) expect(parser.log.pscharge).to eq(123.45)
@ -2792,7 +2792,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end end
describe "#scharge" do describe "#scharge" do
let(:attributes) { { bulk_upload:, field_139: "111.45", field_140: "123.45", field_141: "0", field_142: "0" } } let(:attributes) { { bulk_upload:, field_142: "111.45", field_143: "123.45", field_144: "0", field_145: "0" } }
it "sets value given" do it "sets value given" do
expect(parser.log.scharge).to eq(123.45) expect(parser.log.scharge).to eq(123.45)

Loading…
Cancel
Save