From 849fb48c6ec8d39e823bb64909bb049eafb5da53 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 24 Jan 2024 10:27:38 +0000 Subject: [PATCH] Update field mapping --- .../lettings/year2024/csv_parser.rb | 4 +- .../lettings/year2024/row_parser.rb | 1154 ++++++-------- .../lettings/year2024/csv_parser_spec.rb | 16 +- .../lettings/year2024/row_parser_spec.rb | 1396 +++++++---------- .../bulk_upload/lettings_log_to_csv.rb | 168 ++ 5 files changed, 1225 insertions(+), 1513 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2024/csv_parser.rb b/app/services/bulk_upload/lettings/year2024/csv_parser.rb index 85bd6e699..800bb257f 100644 --- a/app/services/bulk_upload/lettings/year2024/csv_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/csv_parser.rb @@ -3,7 +3,7 @@ require "csv" class BulkUpload::Lettings::Year2024::CsvParser include CollectionTimeHelper - FIELDS = 134 + FIELDS = 130 MAX_COLUMNS = 142 FORM_YEAR = 2024 @@ -73,7 +73,7 @@ class BulkUpload::Lettings::Year2024::CsvParser private def default_field_numbers - [5, nil, nil, 15, 16, nil, 13, 40, 41, 42, 43, 46, 52, 56, 60, 64, 68, 72, 76, 47, 53, 57, 61, 65, 69, 73, 77, 51, 55, 59, 63, 67, 71, 75, 50, 54, 58, 62, 66, 70, 74, 78, 48, 49, 79, 81, 82, 123, 124, 122, 120, 102, 103, nil, 83, 84, 85, 86, 87, 88, 104, 109, 107, 108, 106, 100, 101, 105, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 126, 128, 129, 130, 131, 132, 127, 125, 133, 134, 33, 34, 35, 36, 37, 38, nil, 7, 8, 9, 28, 14, 32, 29, 30, 31, 26, 27, 25, 23, 24, nil, 1, 3, 2, 80, nil, 121, 44, 89, 98, 92, 95, 90, 91, 93, 94, 97, 96, 99, 10, 11, 12, 45, 39, 6, 4, 17, 18, 19, 20, 21, 22].map { |h| h.present? && h.to_s.match?(/^[0-9]+$/) ? "field_#{h}" : "field_blank" } + (1..130).map { |h| h.present? && h.to_s.match?(/^[0-9]+$/) ? "field_#{h}" : "field_blank" } end def field_numbers diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index bd1996adb..a620cdab7 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -8,136 +8,132 @@ class BulkUpload::Lettings::Year2024::RowParser field_2: "Which organisation manages this letting?", field_3: "What is the CORE username of the account this letting log should be assigned to?", field_4: "What is the needs type?", - field_5: "What is the letting type?", - field_6: "Is this letting a renewal?", - field_7: "What is the tenancy start date?", + field_7: "Is this letting a renewal?", field_8: "What is the tenancy start date?", field_9: "What is the tenancy start date?", - field_10: "Is this a London Affordable Rent letting?", - field_11: "Which type of Intermediate Rent is this letting?", + field_10: "What is the tenancy start date?", + field_11: "Is this a London Affordable Rent letting?", field_12: "Which 'Other' type of Intermediate Rent is this letting?", field_13: "What is the tenant code?", field_14: "What is the property reference?", - field_15: "What management group does this letting belong to?", - field_16: "What scheme does this letting belong to?", - field_17: "Which location is this letting for?", - field_18: "If known, provide this property’s UPRN", - field_19: "Address line 1", - field_20: "Address line 2", - field_21: "Town or city", - field_22: "County", - field_23: "Part 1 of the property's postcode", - field_24: "Part 2 of the property's postcode", - field_25: "What is the property's local authority?", - field_26: "What type was the property most recently let as?", - field_27: "What is the reason for the property being vacant?", - field_28: "How many times was the property offered between becoming vacant and this letting?", - field_29: "What type of unit is the property?", - field_30: "Which type of building is the property?", - field_31: "Is the property built or adapted to wheelchair-user standards?", - field_32: "How many bedrooms does the property have?", - field_33: "What is the void date?", - field_34: "What is the void date?", - field_35: "What is the void date?", - field_36: "What date were any major repairs completed on?", - field_37: "What date were any major repairs completed on?", - field_38: "What date were any major repairs completed on?", - field_39: "Is this a joint tenancy?", - field_40: "Is this a starter tenancy?", - field_41: "What is the type of tenancy?", - field_42: "If 'Other', what is the type of tenancy?", - field_43: "What is the length of the fixed-term tenancy to the nearest year?", - field_44: "Is this letting sheltered accommodation?", - field_45: "Has tenant seen the DLUHC privacy notice?", - field_46: "What is the lead tenant's age?", - field_47: "Which of these best describes the lead tenant's gender identity?", - field_48: "Which of these best describes the lead tenant's ethnic background?", - field_49: "What is the lead tenant's nationality?", - field_50: "Which of these best describes the lead tenant's working situation?", - field_51: "What is person 2's relationship to the lead tenant?", - field_52: "What is person 2's age?", - field_53: "Which of these best describes person 2's gender identity?", - field_54: "Which of these best describes person 2's working situation?", - field_55: "What is person 3's relationship to the lead tenant?", - field_56: "What is person 3's age?", - field_57: "Which of these best describes person 3's gender identity?", - field_58: "Which of these best describes person 3's working situation?", - field_59: "What is person 4's relationship to the lead tenant?", - field_60: "What is person 4's age?", - field_61: "Which of these best describes person 4's gender identity?", - field_62: "Which of these best describes person 4's working situation?", - field_63: "What is person 5's relationship to the lead tenant?", - field_64: "What is person 5's age?", - field_65: "Which of these best describes person 5's gender identity?", - field_66: "Which of these best describes person 5's working situation?", - field_67: "What is person 6's relationship to the lead tenant?", - field_68: "What is person 6's age?", - field_69: "Which of these best describes person 6's gender identity?", - field_70: "Which of these best describes person 6's working situation?", - field_71: "What is person 7's relationship to the lead tenant?", - field_72: "What is person 7's age?", - field_73: "Which of these best describes person 7's gender identity?", - field_74: "Which of these best describes person 7's working situation?", - field_75: "What is person 8's relationship to the lead tenant?", - field_76: "What is person 8's age?", - field_77: "Which of these best describes person 8's gender identity?", - field_78: "Which of these best describes person 8's working situation?", - field_79: "Does anybody in the household have links to the UK armed forces?", - field_80: "Is this person still serving in the UK armed forces?", - field_81: "Was this person seriously injured or ill as a result of serving in the UK armed forces?", - field_82: "Is anybody in the household pregnant?", + field_5: "What scheme does this letting belong to?", + field_6: "Which location is this letting for?", + field_16: "If known, provide this property’s UPRN", + field_17: "Address line 1", + field_18: "Address line 2", + field_19: "Town or city", + field_20: "County", + field_21: "Part 1 of the property's postcode", + field_22: "Part 2 of the property's postcode", + field_23: "What is the property's local authority?", + field_25: "What type was the property most recently let as?", + field_24: "What is the reason for the property being vacant?", + field_26: "What type of unit is the property?", + field_27: "Which type of building is the property?", + field_28: "Is the property built or adapted to wheelchair-user standards?", + field_29: "How many bedrooms does the property have?", + field_30: "What is the void date?", + field_31: "What is the void date?", + field_32: "What is the void date?", + field_33: "What date were any major repairs completed on?", + field_34: "What date were any major repairs completed on?", + field_35: "What date were any major repairs completed on?", + field_36: "Is this a joint tenancy?", + field_37: "Is this a starter tenancy?", + field_38: "What is the type of tenancy?", + field_39: "If 'Other', what is the type of tenancy?", + field_40: "What is the length of the fixed-term tenancy to the nearest year?", + field_41: "Is this letting sheltered accommodation?", + field_15: "Has tenant seen the DLUHC privacy notice?", + field_42: "What is the lead tenant's age?", + field_43: "Which of these best describes the lead tenant's gender identity?", + field_44: "Which of these best describes the lead tenant's ethnic background?", + field_45: "What is the lead tenant's nationality?", + field_46: "Which of these best describes the lead tenant's working situation?", + field_47: "What is person 2's relationship to the lead tenant?", + field_48: "What is person 2's age?", + field_49: "Which of these best describes person 2's gender identity?", + field_50: "Which of these best describes person 2's working situation?", + field_51: "What is person 3's relationship to the lead tenant?", + field_52: "What is person 3's age?", + field_53: "Which of these best describes person 3's gender identity?", + field_54: "Which of these best describes person 3's working situation?", + field_55: "What is person 4's relationship to the lead tenant?", + field_56: "What is person 4's age?", + field_57: "Which of these best describes person 4's gender identity?", + field_58: "Which of these best describes person 4's working situation?", + field_59: "What is person 5's relationship to the lead tenant?", + field_60: "What is person 5's age?", + field_61: "Which of these best describes person 5's gender identity?", + field_62: "Which of these best describes person 5's working situation?", + field_63: "What is person 6's relationship to the lead tenant?", + field_64: "What is person 6's age?", + field_65: "Which of these best describes person 6's gender identity?", + field_66: "Which of these best describes person 6's working situation?", + field_67: "What is person 7's relationship to the lead tenant?", + field_68: "What is person 7's age?", + field_69: "Which of these best describes person 7's gender identity?", + field_70: "Which of these best describes person 7's working situation?", + field_71: "What is person 8's relationship to the lead tenant?", + field_72: "What is person 8's age?", + field_73: "Which of these best describes person 8's gender identity?", + field_74: "Which of these best describes person 8's working situation?", + field_75: "Does anybody in the household have links to the UK armed forces?", + field_76: "Is this person still serving in the UK armed forces?", + field_77: "Was this person seriously injured or ill as a result of serving in the UK armed forces?", + field_78: "Is anybody in the household pregnant?", + field_79: "Does anybody in the household have any disabled access needs?", + field_80: "Does anybody in the household have any disabled access needs?", + field_81: "Does anybody in the household have any disabled access needs?", + field_82: "Does anybody in the household have any disabled access needs?", field_83: "Does anybody in the household have any disabled access needs?", field_84: "Does anybody in the household have any disabled access needs?", - field_85: "Does anybody in the household have any disabled access needs?", - field_86: "Does anybody in the household have any disabled access needs?", - field_87: "Does anybody in the household have any disabled access needs?", - field_88: "Does anybody in the household have any disabled access needs?", - field_89: "Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?", - field_90: "Does this person's condition affect their dexterity?", - field_91: "Does this person's condition affect their learning or understanding or concentrating?", - field_92: "Does this person's condition affect their hearing?", - field_93: "Does this person's condition affect their memory?", - field_94: "Does this person's condition affect their mental health?", - field_95: "Does this person's condition affect their mobility?", - field_96: "Does this person's condition affect them socially or behaviourally?", - field_97: "Does this person's condition affect their stamina or breathing or fatigue?", - field_98: "Does this person's condition affect their vision?", - field_99: "Does this person's condition affect them in another way?", - field_100: "How long has the household continuously lived in the local authority area of the new letting?", - field_101: "How long has the household been on the local authority waiting list for the new letting?", - field_102: "What is the tenant’s main reason for the household leaving their last settled home?", - field_103: "If 'Other', what was the main reason for leaving their last settled home?", - field_104: "Where was the household immediately before this letting?", - field_105: "Did the household experience homelessness immediately before this letting?", - field_106: "Do you know the postcode of the household's last settled home?", - field_107: "What is the postcode of the household's last settled home?", - field_108: "What is the postcode of the household's last settled home?", - field_109: "What is the local authority of the household's last settled home?", - field_110: "Was the household given 'reasonable preference' by the local authority?", - field_111: "Reasonable preference reason They were homeless or about to lose their home (within 56 days)", - field_112: "Reasonable preference reason They were living in insanitary, overcrowded or unsatisfactory housing", - field_113: "Reasonable preference reason They needed to move on medical and welfare reasons (including disability)", - field_114: "Reasonable preference reason They needed to move to avoid hardship to themselves or others", - field_115: "Reasonable preference reason Don't know", - field_116: "Was the letting made under the Choice-Based Lettings (CBL)?", - field_117: "Was the letting made under the Common Allocation Policy (CAP)?", - field_118: "Was the letting made under the Common Housing Register (CHR)?", - field_119: "What was the source of referral for this letting?", - field_120: "Do you know the household's combined total income after tax?", - field_121: "How often does the household receive income?", - field_122: "How much income does the household have in total?", - field_123: "Is the tenant likely to be receiving any of these housing-related benefits?", - field_124: "How much of the household's income is from Universal Credit, state pensions or benefits?", - field_125: "Does the household pay rent or other charges for the accommodation?", - field_126: "How often does the household pay rent and other charges?", - field_127: "If this is a care home, how much does the household pay every [time period]?", - field_128: "What is the basic rent?", - field_129: "What is the service charge?", - field_130: "What is the personal service charge?", - field_131: "What is the support charge?", - field_132: "Total charge", - field_133: "After the household has received any housing-related benefits, will they still need to pay for rent and charges?", - field_134: "What do you expect the outstanding amount to be?", + field_85: "Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?", + field_86: "Does this person's condition affect their dexterity?", + field_87: "Does this person's condition affect their learning or understanding or concentrating?", + field_88: "Does this person's condition affect their hearing?", + field_89: "Does this person's condition affect their memory?", + field_90: "Does this person's condition affect their mental health?", + field_91: "Does this person's condition affect their mobility?", + field_92: "Does this person's condition affect them socially or behaviourally?", + field_93: "Does this person's condition affect their stamina or breathing or fatigue?", + field_94: "Does this person's condition affect their vision?", + field_95: "Does this person's condition affect them in another way?", + field_96: "How long has the household continuously lived in the local authority area of the new letting?", + field_97: "How long has the household been on the local authority waiting list for the new letting?", + field_98: "What is the tenant’s main reason for the household leaving their last settled home?", + field_99: "If 'Other', what was the main reason for leaving their last settled home?", + field_100: "Where was the household immediately before this letting?", + field_101: "Did the household experience homelessness immediately before this letting?", + field_102: "Do you know the postcode of the household's last settled home?", + field_103: "What is the postcode of the household's last settled home?", + field_104: "What is the postcode of the household's last settled home?", + field_105: "What is the local authority of the household's last settled home?", + field_106: "Was the household given 'reasonable preference' by the local authority?", + field_107: "Reasonable preference reason They were homeless or about to lose their home (within 56 days)", + field_108: "Reasonable preference reason They were living in insanitary, overcrowded or unsatisfactory housing", + field_109: "Reasonable preference reason They needed to move on medical and welfare reasons (including disability)", + field_110: "Reasonable preference reason They needed to move to avoid hardship to themselves or others", + field_111: "Reasonable preference reason Don't know", + field_112: "Was the letting made under the Choice-Based Lettings (CBL)?", + field_113: "Was the letting made under the Common Allocation Policy (CAP)?", + field_114: "Was the letting made under the Common Housing Register (CHR)?", + field_115: "Was the letting made under the Accessible Register?", + field_116: "What was the source of referral for this letting?", + field_117: "Do you know the household's combined total income after tax?", + field_119: "How often does the household receive income?", + field_118: "How much income does the household have in total?", + field_120: "Is the tenant likely to be receiving any of these housing-related benefits?", + field_121: "How much of the household's income is from Universal Credit, state pensions or benefits?", + field_122: "Does the household pay rent or other charges for the accommodation?", + field_123: "How often does the household pay rent and other charges?", + field_124: "If this is a care home, how much does the household pay every [time period]?", + field_125: "What is the basic rent?", + field_126: "What is the service charge?", + field_127: "What is the personal service charge?", + field_128: "What is the support charge?", + field_129: "After the household has received any housing-related benefits, will they still need to pay for rent and charges?", + field_130: "What do you expect the outstanding amount to be?", }.freeze attribute :bulk_upload @@ -149,8 +145,6 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_2, :string attribute :field_3, :string attribute :field_4, :integer - attribute :field_5, :integer - attribute :field_6, :integer attribute :field_7, :integer attribute :field_8, :integer attribute :field_9, :integer @@ -159,7 +153,8 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_12, :string attribute :field_13, :string attribute :field_14, :string - attribute :field_15, :string + attribute :field_5, :string + attribute :field_6, :string attribute :field_16, :string attribute :field_17, :string attribute :field_18, :string @@ -168,8 +163,8 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_21, :string attribute :field_22, :string attribute :field_23, :string - attribute :field_24, :string - attribute :field_25, :string + attribute :field_25, :integer + attribute :field_24, :integer attribute :field_26, :integer attribute :field_27, :integer attribute :field_28, :integer @@ -183,17 +178,18 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_36, :integer attribute :field_37, :integer attribute :field_38, :integer - attribute :field_39, :integer + attribute :field_39, :string attribute :field_40, :integer attribute :field_41, :integer + attribute :field_15, :integer attribute :field_42, :string - attribute :field_43, :integer + attribute :field_43, :string attribute :field_44, :integer attribute :field_45, :integer - attribute :field_46, :string + attribute :field_46, :integer attribute :field_47, :string - attribute :field_48, :integer - attribute :field_49, :integer + attribute :field_48, :string + attribute :field_49, :string attribute :field_50, :integer attribute :field_51, :string attribute :field_52, :string @@ -219,9 +215,9 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_72, :string attribute :field_73, :string attribute :field_74, :integer - attribute :field_75, :string - attribute :field_76, :string - attribute :field_77, :string + attribute :field_75, :integer + attribute :field_76, :integer + attribute :field_77, :integer attribute :field_78, :integer attribute :field_79, :integer attribute :field_80, :integer @@ -243,17 +239,17 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_96, :integer attribute :field_97, :integer attribute :field_98, :integer - attribute :field_99, :integer + attribute :field_99, :string attribute :field_100, :integer attribute :field_101, :integer attribute :field_102, :integer attribute :field_103, :string - attribute :field_104, :integer - attribute :field_105, :integer + attribute :field_104, :string + attribute :field_105, :string attribute :field_106, :integer - attribute :field_107, :string - attribute :field_108, :string - attribute :field_109, :string + attribute :field_107, :integer + attribute :field_108, :integer + attribute :field_109, :integer attribute :field_110, :integer attribute :field_111, :integer attribute :field_112, :integer @@ -262,61 +258,57 @@ class BulkUpload::Lettings::Year2024::RowParser attribute :field_115, :integer attribute :field_116, :integer attribute :field_117, :integer - attribute :field_118, :integer attribute :field_119, :integer + attribute :field_118, :decimal attribute :field_120, :integer attribute :field_121, :integer - attribute :field_122, :decimal + attribute :field_122, :integer attribute :field_123, :integer - attribute :field_124, :integer - attribute :field_125, :integer - attribute :field_126, :integer + attribute :field_124, :decimal + attribute :field_125, :decimal + attribute :field_126, :decimal attribute :field_127, :decimal attribute :field_128, :decimal - attribute :field_129, :decimal + attribute :field_129, :integer attribute :field_130, :decimal - attribute :field_131, :decimal - attribute :field_132, :decimal - attribute :field_133, :integer - attribute :field_134, :decimal validate :validate_valid_radio_option, on: :before_log - validates :field_5, + validates :field_11, presence: { - message: I18n.t("validations.not_answered", question: "letting type"), + message: I18n.t("validations.not_answered", question: "rent type"), category: :setup, }, inclusion: { - in: (1..12).to_a, - message: I18n.t("validations.invalid_option", question: "letting type"), - unless: -> { field_5.blank? }, + in: (0..5).to_a, + message: I18n.t("validations.invalid_option", question: "rent type"), + unless: -> { field_11.blank? }, category: :setup, }, on: :after_log - validates :field_6, + validates :field_7, presence: { message: I18n.t("validations.not_answered", question: "property renewal"), category: :setup, }, on: :after_log - validates :field_7, + validates :field_8, presence: { message: I18n.t("validations.not_answered", question: "tenancy start date (day)"), category: :setup, }, on: :after_log - validates :field_8, + validates :field_9, presence: { message: I18n.t("validations.not_answered", question: "tenancy start date (month)"), category: :setup, }, on: :after_log - validates :field_9, + validates :field_10, presence: { message: I18n.t("validations.not_answered", question: "tenancy start date (year)"), category: :setup, @@ -325,11 +317,11 @@ class BulkUpload::Lettings::Year2024::RowParser with: /\A\d{2}\z/, message: I18n.t("validations.setup.startdate.year_not_two_digits"), category: :setup, - unless: -> { field_9.blank? }, + unless: -> { field_10.blank? }, }, on: :after_log - validates :field_16, + validates :field_5, presence: { if: proc { supported_housing? }, message: I18n.t("validations.not_answered", question: "scheme code"), @@ -337,14 +329,22 @@ class BulkUpload::Lettings::Year2024::RowParser }, on: :after_log - validates :field_46, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log - validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? } - validates :field_56, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? } - validates :field_60, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 4 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(4).zero? } - validates :field_64, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 5 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(5).zero? } - validates :field_68, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 6 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(6).zero? } - validates :field_72, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 7 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(7).zero? } - validates :field_76, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 8 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(8).zero? } + validates :field_6, + presence: { + if: proc { supported_housing? }, + message: I18n.t("validations.not_answered", question: "location code"), + category: :setup, + }, + on: :after_log + + validates :field_42, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log + validates :field_48, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? } + validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? } + validates :field_56, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 4 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(4).zero? } + validates :field_60, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 5 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(5).zero? } + validates :field_64, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 6 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(6).zero? } + validates :field_68, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 7 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(7).zero? } + validates :field_72, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 8 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(8).zero? } validate :validate_needs_type_present, on: :after_log validate :validate_data_types, on: :after_log @@ -352,7 +352,6 @@ class BulkUpload::Lettings::Year2024::RowParser validate :validate_la_with_local_housing_referral, on: :after_log validate :validate_cannot_be_la_referral_if_general_needs_and_la, on: :after_log validate :validate_leaving_reason_for_renewal, on: :after_log - validate :validate_lettings_type_matches_bulk_upload, on: :after_log validate :validate_only_one_housing_needs_type, on: :after_log validate :validate_no_disabled_needs_conjunction, on: :after_log validate :validate_dont_know_disabled_needs_conjunction, on: :after_log @@ -373,10 +372,7 @@ class BulkUpload::Lettings::Year2024::RowParser validate :validate_managing_org_related, on: :after_log validate :validate_related_scheme_exists, on: :after_log - validate :validate_scheme_data_given, on: :after_log - validate :validate_related_location_exists, on: :after_log - validate :validate_location_data_given, on: :after_log validate :validate_created_by_exists, on: :after_log validate :validate_created_by_related, on: :after_log @@ -389,9 +385,6 @@ class BulkUpload::Lettings::Year2024::RowParser validate :validate_incomplete_soft_validations, on: :after_log - validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate } - validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable } - def self.question_for_field(field) QUESTIONS[field] end @@ -469,17 +462,16 @@ class BulkUpload::Lettings::Year2024::RowParser def spreadsheet_duplicate_hash attributes.slice( "field_1", # owning org - "field_7", # startdate "field_8", # startdate "field_9", # startdate - "field_13", # tenancycode - !general_needs? ? location_field.to_s : nil, # location - !supported_housing? ? "field_23" : nil, # postcode - !supported_housing? ? "field_24" : nil, # postcode - "field_46", # age1 - "field_47", # sex1 - "field_50", # ecstat1 - "field_132", # tcharge + "field_10", # startdate + "field_13", # tenancycode + !general_needs? ? :field_6.to_s : nil, # location + !supported_housing? ? "field_21" : nil, # postcode + !supported_housing? ? "field_22" : nil, # postcode + "field_42", # age1 + "field_43", # sex1 + "field_46", # ecstat1 ) end @@ -492,8 +484,8 @@ class BulkUpload::Lettings::Year2024::RowParser private def validate_declaration_acceptance - unless field_45 == 1 - errors.add(:field_45, I18n.t("validations.declaration.missing"), category: :setup) + unless field_15 == 1 + errors.add(:field_15, I18n.t("validations.declaration.missing"), category: :setup) end end @@ -538,8 +530,8 @@ private end def validate_uprn_exists_if_any_key_address_fields_are_blank - if field_18.blank? && (field_19.blank? || field_21.blank?) - errors.add(:field_18, I18n.t("validations.not_answered", question: "UPRN")) + if field_16.blank? && (field_17.blank? || field_19.blank?) + errors.add(:field_16, I18n.t("validations.not_answered", question: "UPRN")) end end @@ -583,57 +575,57 @@ private end def start_date - return if field_7.blank? || field_8.blank? || field_9.blank? + return if field_8.blank? || field_9.blank? || field_10.blank? - Date.parse("20#{field_9.to_s.rjust(2, '0')}-#{field_8}-#{field_7}") + Date.parse("20#{field_10.to_s.rjust(2, '0')}-#{field_9}-#{field_8}") rescue StandardError nil end def validate_no_and_dont_know_disabled_needs_conjunction - if field_87 == 1 && field_88 == 1 - errors.add(:field_87, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) - errors.add(:field_88, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) + if field_83 == 1 && field_84 == 1 + errors.add(:field_83, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) + errors.add(:field_84, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) end end def validate_dont_know_disabled_needs_conjunction - if field_88 == 1 && [field_83, field_84, field_85, field_86].count(1).positive? - %i[field_88 field_83 field_84 field_85 field_86].each do |field| + if field_84 == 1 && [field_79, field_80, field_81, field_82].count(1).positive? + %i[field_84 field_79 field_80 field_81 field_82].each do |field| errors.add(field, I18n.t("validations.household.housingneeds.dont_know_disabled_needs_conjunction")) if send(field) == 1 end end end def validate_no_disabled_needs_conjunction - if field_87 == 1 && [field_83, field_84, field_85, field_86].count(1).positive? - %i[field_87 field_83 field_84 field_85 field_86].each do |field| + if field_83 == 1 && [field_79, field_80, field_81, field_82].count(1).positive? + %i[field_83 field_79 field_80 field_81 field_82].each do |field| errors.add(field, I18n.t("validations.household.housingneeds.no_disabled_needs_conjunction")) if send(field) == 1 end end end def validate_only_one_housing_needs_type - if [field_83, field_84, field_85].count(1) > 1 - %i[field_83 field_84 field_85].each do |field| + if [field_79, field_80, field_81].count(1) > 1 + %i[field_79 field_80 field_81].each do |field| errors.add(field, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if send(field) == 1 end end end def validate_no_housing_needs_questions_answered - if [field_83, field_84, field_85, field_86, field_87, field_88].all?(&:blank?) - errors.add(:field_87, I18n.t("validations.not_answered", question: "anybody with disabled access needs")) - errors.add(:field_86, I18n.t("validations.not_answered", question: "other access needs")) - %i[field_83 field_84 field_85].each do |field| + if [field_79, field_80, field_81, field_82, field_83, field_84].all?(&:blank?) + errors.add(:field_83, I18n.t("validations.not_answered", question: "anybody with disabled access needs")) + errors.add(:field_82, I18n.t("validations.not_answered", question: "other access needs")) + %i[field_79 field_80 field_81].each do |field| errors.add(field, I18n.t("validations.not_answered", question: "disabled access needs type")) end end end def validate_reasonable_preference_homeless - reason_fields = %i[field_111 field_112 field_113 field_114 field_115] - if field_110 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? } + reason_fields = %i[field_107 field_108 field_109 field_110 field_111] + if field_106 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? } reason_fields.each do |field| errors.add(field, I18n.t("validations.not_answered", question: "reason for reasonable preference")) end @@ -641,7 +633,7 @@ private end def validate_condition_effects - illness_option_fields = %i[field_98 field_92 field_95 field_90 field_91 field_93 field_94 field_97 field_96 field_99] + illness_option_fields = %i[field_94 field_88 field_91 field_86 field_87 field_89 field_90 field_93 field_92 field_95] if household_no_illness? illness_option_fields.each do |field| if attributes[field.to_s] == 1 @@ -657,33 +649,19 @@ private def validate_lettings_allocation if cbl.blank? && cap.blank? && chr.blank? - errors.add(:field_116, I18n.t("validations.not_answered", question: "was the letting made under the Choice-Based Lettings (CBL)?")) - errors.add(:field_117, I18n.t("validations.not_answered", question: "was the letting made under the Common Allocation Policy (CAP)?")) - errors.add(:field_118, I18n.t("validations.not_answered", question: "was the letting made under the Common Housing Register (CHR)?")) + errors.add(:field_112, I18n.t("validations.not_answered", question: "was the letting made under the Choice-Based Lettings (CBL)?")) + errors.add(:field_113, I18n.t("validations.not_answered", question: "was the letting made under the Common Allocation Policy (CAP)?")) + errors.add(:field_114, I18n.t("validations.not_answered", question: "was the letting made under the Common Housing Register (CHR)?")) end end def household_no_illness? - field_89 != 1 - end - - def validate_lettings_type_matches_bulk_upload - if [1, 3, 5, 7, 9, 11].include?(field_5) && !general_needs? - block_log_creation! - errors.add(:field_4, I18n.t("validations.setup.needstype.lettype_not_supported_housing"), category: :setup) - errors.add(:field_5, I18n.t("validations.setup.lettype.needstype_supported_housing"), category: :setup) - end - - if [2, 4, 6, 8, 10, 12].include?(field_5) && !supported_housing? - block_log_creation! - errors.add(:field_4, I18n.t("validations.setup.needstype.lettype_not_general_needs"), category: :setup) - errors.add(:field_5, I18n.t("validations.setup.lettype.needstype_general_needs"), category: :setup) - end + field_85 != 1 end def validate_leaving_reason_for_renewal - if field_6 == 1 && ![40, 42].include?(field_102) - errors.add(:field_102, I18n.t("validations.household.reason.renewal_reason_needed")) + if field_7 == 1 && ![40, 42].include?(field_98) + errors.add(:field_98, I18n.t("validations.household.reason.renewal_reason_needed")) end end @@ -696,14 +674,14 @@ private end def validate_cannot_be_la_referral_if_general_needs_and_la - if field_119 == 4 && general_needs? && owning_organisation && owning_organisation.la? - errors.add :field_119, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la") + if field_116 == 4 && general_needs? && owning_organisation && owning_organisation.la? + errors.add :field_116, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la") end end def validate_la_with_local_housing_referral - if field_119 == 3 && owning_organisation && owning_organisation.la? - errors.add(:field_119, I18n.t("validations.household.referral.nominated_by_local_ha_but_la")) + if field_116 == 3 && owning_organisation && owning_organisation.la? + errors.add(:field_116, I18n.t("validations.household.referral.nominated_by_local_ha_but_la")) end end @@ -711,15 +689,15 @@ private return if start_date.blank? || bulk_upload.form.blank? unless bulk_upload.form.valid_start_date_for_form?(start_date) - errors.add(:field_7, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_8, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_9, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) + errors.add(:field_10, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) end end def validate_data_types - unless attribute_set["field_5"].value_before_type_cast&.match?(/^\d+\.?0*$/) - errors.add(:field_5, I18n.t("validations.invalid_number", question: "letting type")) + unless attribute_set["field_11"].value_before_type_cast&.match?(/^\d+\.?0*$/) + errors.add(:field_11, I18n.t("validations.invalid_number", question: "rent type")) end end @@ -751,30 +729,16 @@ private end def validate_related_location_exists - if scheme && location_id.present? && location.nil? && location_field.present? + if scheme && field_6.present? && location.nil? && :field_6.present? block_log_creation! - errors.add(location_field, "#{location_or_scheme.capitalize} code must relate to a #{location_or_scheme} that is owned by the owning organisation or managing organisation", category: :setup) - end - end - - def validate_location_data_given - if supported_housing? && location_id.blank? && location_field.present? - block_log_creation! - errors.add(location_field, I18n.t("validations.not_answered", question: "#{location_or_scheme} code"), category: :setup) + errors.add(:field_6, "Location code must relate to a location that is owned by the owning organisation or managing organisation", category: :setup) end end def validate_related_scheme_exists - if scheme_id.present? && scheme_field.present? && owning_organisation.present? && managing_organisation.present? && scheme.nil? + if field_5.present? && :field_5.present? && owning_organisation.present? && managing_organisation.present? && scheme.nil? block_log_creation! - errors.add(scheme_field, "This #{scheme_or_management_group} code does not belong to the owning organisation or managing organisation", category: :setup) - end - end - - def validate_scheme_data_given - if supported_housing? && scheme_field.present? && scheme_id.blank? - block_log_creation! - errors.add(scheme_field, I18n.t("validations.not_answered", question: "#{scheme_or_management_group} code"), category: :setup) + errors.add(:field_5, "This scheme code does not belong to the owning organisation or managing organisation", category: :setup) end end @@ -842,18 +806,6 @@ private end end - def validate_correct_intermediate_rent_type - if field_11.blank? || ![1, 2, 3].include?(field_11.to_i) - errors.add(:field_11, I18n.t("validations.not_answered", question: "intermediate rent type"), category: :setup) - end - end - - def validate_correct_affordable_rent_type - if field_10.blank? || ![1, 2, 3].include?(field_10.to_i) - errors.add(:field_10, I18n.t("validations.not_answered", question: "is this a London Affordable Rent letting"), category: :setup) - end - end - def setup_question?(question) log.form.setup_sections[0].subsections[0].questions.include?(question) end @@ -863,183 +815,180 @@ private error_message = "This is a duplicate log" errors.add(:field_1, error_message) # owning_organisation - errors.add(:field_7, error_message) # startdate errors.add(:field_8, error_message) # startdate errors.add(:field_9, error_message) # startdate + errors.add(:field_10, error_message) # startdate errors.add(:field_13, error_message) # tenancycode - errors.add(location_field, error_message) if !general_needs? && location_field.present? # location - errors.add(:field_16, error_message) if !general_needs? && location_field.blank? # add to Scheme field as unclear whether log uses New or Old CORE ids - errors.add(:field_23, error_message) unless supported_housing? # postcode_full - errors.add(:field_24, error_message) unless supported_housing? # postcode_full - errors.add(:field_25, error_message) unless supported_housing? # la - errors.add(:field_46, error_message) # age1 - errors.add(:field_47, error_message) # sex1 - errors.add(:field_50, error_message) # ecstat1 - errors.add(:field_132, error_message) # tcharge - errors.add(:field_127, error_message) if log.chcharge.present? # chcharge - errors.add(:field_125, error_message) unless general_needs? # household_charge + errors.add(:field_6, error_message) if !general_needs? && :field_6.present? # location + errors.add(:field_5, error_message) if !general_needs? && :field_6.blank? # add to Scheme field as unclear whether log uses New or Old CORE ids + errors.add(:field_21, error_message) unless supported_housing? # postcode_full + errors.add(:field_22, error_message) unless supported_housing? # postcode_full + errors.add(:field_23, error_message) unless supported_housing? # la + errors.add(:field_42, error_message) # age1 + errors.add(:field_43, error_message) # sex1 + errors.add(:field_46, error_message) # ecstat1 + errors.add(:field_124, error_message) if log.chcharge.present? # chcharge + errors.add(:field_122, error_message) unless general_needs? # household_charge end end def field_mapping_for_errors { - lettype: [:field_5], + lettype: [:field_11], tenancycode: [:field_13], - postcode_known: %i[field_25 field_23 field_24], - postcode_full: %i[field_25 field_23 field_24], - la: %i[field_25], + postcode_known: %i[field_23 field_21 field_22], + postcode_full: %i[field_23 field_21 field_22], + la: %i[field_23], owning_organisation: [:field_1], managing_organisation: [:field_2], owning_organisation_id: [:field_1], managing_organisation_id: [:field_2], - renewal: [:field_6], - scheme_id: (scheme_field.present? ? [scheme_field] : nil), - scheme: (scheme_field.present? ? [scheme_field] : nil), - location_id: (location_field.present? ? [location_field] : nil), - location: (location_field.present? ? [location_field] : nil), + renewal: [:field_7], + scheme_id: (:field_5.present? ? [:field_5] : nil), + scheme: (:field_5.present? ? [:field_5] : nil), + location_id: (:field_6.present? ? [:field_6] : nil), + location: (:field_6.present? ? [:field_6] : nil), created_by: [:field_3], needstype: [:field_4], - rent_type: %i[field_5 field_10 field_11], - startdate: %i[field_7 field_8 field_9], - unittype_gn: %i[field_29], - builtype: %i[field_30], - wchair: %i[field_31], - beds: %i[field_32], - joint: %i[field_39], - startertenancy: %i[field_40], - tenancy: %i[field_41], - tenancyother: %i[field_42], - tenancylength: %i[field_43], - declaration: %i[field_45], - - age1_known: %i[field_46], - age1: %i[field_46], - age2_known: %i[field_52], - age2: %i[field_52], - age3_known: %i[field_56], - age3: %i[field_56], - age4_known: %i[field_60], - age4: %i[field_60], - age5_known: %i[field_64], - age5: %i[field_64], - age6_known: %i[field_68], - age6: %i[field_68], - age7_known: %i[field_72], - age7: %i[field_72], - age8_known: %i[field_76], - age8: %i[field_76], - - sex1: %i[field_47], - sex2: %i[field_53], - sex3: %i[field_57], - sex4: %i[field_61], - sex5: %i[field_65], - sex6: %i[field_69], - sex7: %i[field_73], - sex8: %i[field_77], - - ethnic_group: %i[field_48], - ethnic: %i[field_48], - national: %i[field_49], - - relat2: %i[field_51], - relat3: %i[field_55], - relat4: %i[field_59], - relat5: %i[field_63], - relat6: %i[field_67], - relat7: %i[field_71], - relat8: %i[field_75], - - ecstat1: %i[field_50], - ecstat2: %i[field_54], - ecstat3: %i[field_58], - ecstat4: %i[field_62], - ecstat5: %i[field_66], - ecstat6: %i[field_70], - ecstat7: %i[field_74], - ecstat8: %i[field_78], - - armedforces: %i[field_79], - leftreg: %i[field_80], - reservist: %i[field_81], - preg_occ: %i[field_82], - housingneeds: %i[field_82], - - illness: %i[field_89], - - layear: %i[field_100], - waityear: %i[field_101], - reason: %i[field_102], - reasonother: %i[field_103], - prevten: %i[field_104], - homeless: %i[field_105], - - prevloc: %i[field_109], - previous_la_known: %i[field_109], - ppcodenk: %i[field_106], - ppostcode_full: %i[field_107 field_108], - - reasonpref: %i[field_110], - rp_homeless: %i[field_111], - rp_insan_unsat: %i[field_112], - rp_medwel: %i[field_113], - rp_hardship: %i[field_114], - rp_dontknow: %i[field_115], - - cbl: %i[field_116], - chr: %i[field_118], - cap: %i[field_117], - letting_allocation: %i[field_116 field_117 field_118], - - referral: %i[field_119], - - net_income_known: %i[field_120], - earnings: %i[field_122], - incfreq: %i[field_121], - hb: %i[field_123], - benefits: %i[field_124], - - period: %i[field_126], - brent: %i[field_128], - scharge: %i[field_129], - pscharge: %i[field_130], - supcharg: %i[field_131], - tcharge: %i[field_132], - chcharge: %i[field_127], - household_charge: %i[field_125], - hbrentshortfall: %i[field_133], - tshortfall: %i[field_134], - - unitletas: %i[field_26], - rsnvac: %i[field_27], - sheltered: %i[field_44], - - illness_type_1: %i[field_98], - illness_type_2: %i[field_92], - illness_type_3: %i[field_95], - illness_type_4: %i[field_90], - illness_type_5: %i[field_91], - illness_type_6: %i[field_93], - illness_type_7: %i[field_94], - illness_type_8: %i[field_97], - illness_type_9: %i[field_96], - illness_type_10: %i[field_99], + rent_type: %i[field_11], + startdate: %i[field_8 field_9 field_10], + unittype_gn: %i[field_26], + builtype: %i[field_27], + wchair: %i[field_28], + beds: %i[field_29], + joint: %i[field_36], + startertenancy: %i[field_37], + tenancy: %i[field_38], + tenancyother: %i[field_39], + tenancylength: %i[field_40], + declaration: %i[field_15], + + age1_known: %i[field_42], + age1: %i[field_42], + age2_known: %i[field_48], + age2: %i[field_48], + age3_known: %i[field_52], + age3: %i[field_52], + age4_known: %i[field_56], + age4: %i[field_56], + age5_known: %i[field_60], + age5: %i[field_60], + age6_known: %i[field_64], + age6: %i[field_64], + age7_known: %i[field_68], + age7: %i[field_68], + age8_known: %i[field_72], + age8: %i[field_72], + + sex1: %i[field_43], + sex2: %i[field_49], + sex3: %i[field_53], + sex4: %i[field_57], + sex5: %i[field_61], + sex6: %i[field_65], + sex7: %i[field_69], + sex8: %i[field_73], + + ethnic_group: %i[field_44], + ethnic: %i[field_44], + national: %i[field_45], + + relat2: %i[field_47], + relat3: %i[field_51], + relat4: %i[field_55], + relat5: %i[field_59], + relat6: %i[field_63], + relat7: %i[field_67], + relat8: %i[field_71], + + ecstat1: %i[field_46], + ecstat2: %i[field_50], + ecstat3: %i[field_54], + ecstat4: %i[field_58], + ecstat5: %i[field_62], + ecstat6: %i[field_66], + ecstat7: %i[field_70], + ecstat8: %i[field_74], + + armedforces: %i[field_75], + leftreg: %i[field_76], + reservist: %i[field_77], + preg_occ: %i[field_78], + housingneeds: %i[field_78], + + illness: %i[field_85], + + layear: %i[field_96], + waityear: %i[field_97], + reason: %i[field_98], + reasonother: %i[field_99], + prevten: %i[field_100], + homeless: %i[field_101], + + prevloc: %i[field_105], + previous_la_known: %i[field_105], + ppcodenk: %i[field_102], + ppostcode_full: %i[field_103 field_104], + + reasonpref: %i[field_106], + rp_homeless: %i[field_107], + rp_insan_unsat: %i[field_108], + rp_medwel: %i[field_109], + rp_hardship: %i[field_110], + rp_dontknow: %i[field_111], + + cbl: %i[field_112], + chr: %i[field_114], + cap: %i[field_113], + letting_allocation: %i[field_112 field_113 field_114], + + referral: %i[field_116], + + net_income_known: %i[field_117], + earnings: %i[field_118], + incfreq: %i[field_119], + hb: %i[field_120], + benefits: %i[field_121], + + period: %i[field_123], + brent: %i[field_125], + scharge: %i[field_126], + pscharge: %i[field_127], + supcharg: %i[field_128], + chcharge: %i[field_124], + household_charge: %i[field_122], + hbrentshortfall: %i[field_129], + tshortfall: %i[field_130], + + unitletas: %i[field_25], + rsnvac: %i[field_24], + sheltered: %i[field_41], + + illness_type_1: %i[field_94], + illness_type_2: %i[field_88], + illness_type_3: %i[field_91], + illness_type_4: %i[field_86], + illness_type_5: %i[field_87], + illness_type_6: %i[field_89], + illness_type_7: %i[field_90], + illness_type_8: %i[field_93], + illness_type_9: %i[field_92], + illness_type_10: %i[field_95], irproduct_other: %i[field_12], - offered: %i[field_28], propcode: %i[field_14], - majorrepairs: %i[field_36 field_37 field_38], - mrcdate: %i[field_36 field_37 field_38], + majorrepairs: %i[field_33 field_34 field_35], + mrcdate: %i[field_33 field_34 field_35], - voiddate: %i[field_33 field_34 field_35], + voiddate: %i[field_30 field_31 field_32], - uprn: [:field_18], - address_line1: [:field_19], - address_line2: [:field_20], - town_or_city: [:field_21], - county: [:field_22], + uprn: [:field_16], + address_line1: [:field_17], + address_line2: [:field_18], + town_or_city: [:field_19], + county: [:field_20], }.compact end @@ -1054,9 +1003,9 @@ private def attributes_for_log attributes = {} - attributes["lettype"] = field_5 + attributes["lettype"] = nil # should get this from rent_type attributes["tenancycode"] = field_13 - attributes["la"] = field_25 + attributes["la"] = field_23 attributes["postcode_known"] = postcode_known attributes["postcode_full"] = postcode_full attributes["owning_organisation"] = owning_organisation @@ -1066,72 +1015,72 @@ private attributes["location"] = location attributes["created_by"] = created_by || bulk_upload.user attributes["needstype"] = field_4 - attributes["rent_type"] = rent_type + attributes["rent_type"] = field_11 attributes["startdate"] = startdate - attributes["unittype_gn"] = field_29 - attributes["builtype"] = field_30 - attributes["wchair"] = field_31 - attributes["beds"] = field_32 - attributes["joint"] = field_39 - attributes["startertenancy"] = field_40 - attributes["tenancy"] = field_41 - attributes["tenancyother"] = field_42 - attributes["tenancylength"] = field_43 - attributes["declaration"] = field_45 + attributes["unittype_gn"] = field_26 + attributes["builtype"] = field_27 + attributes["wchair"] = field_28 + attributes["beds"] = field_29 + attributes["joint"] = field_36 + attributes["startertenancy"] = field_37 + attributes["tenancy"] = field_38 + attributes["tenancyother"] = field_39 + attributes["tenancylength"] = field_40 + attributes["declaration"] = field_15 attributes["age1_known"] = age1_known? - attributes["age1"] = field_46 if attributes["age1_known"]&.zero? && field_46&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age1"] = field_42 if attributes["age1_known"]&.zero? && field_42&.match(/\A\d{1,3}\z|\AR\z/) attributes["age2_known"] = age2_known? - attributes["age2"] = field_52 if attributes["age2_known"]&.zero? && field_52&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age2"] = field_48 if attributes["age2_known"]&.zero? && field_48&.match(/\A\d{1,3}\z|\AR\z/) attributes["age3_known"] = age3_known? - attributes["age3"] = field_56 if attributes["age3_known"]&.zero? && field_56&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age3"] = field_52 if attributes["age3_known"]&.zero? && field_52&.match(/\A\d{1,3}\z|\AR\z/) attributes["age4_known"] = age4_known? - attributes["age4"] = field_60 if attributes["age4_known"]&.zero? && field_60&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age4"] = field_56 if attributes["age4_known"]&.zero? && field_56&.match(/\A\d{1,3}\z|\AR\z/) attributes["age5_known"] = age5_known? - attributes["age5"] = field_64 if attributes["age5_known"]&.zero? && field_64&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age5"] = field_60 if attributes["age5_known"]&.zero? && field_60&.match(/\A\d{1,3}\z|\AR\z/) attributes["age6_known"] = age6_known? - attributes["age6"] = field_68 if attributes["age6_known"]&.zero? && field_68&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age6"] = field_64 if attributes["age6_known"]&.zero? && field_64&.match(/\A\d{1,3}\z|\AR\z/) attributes["age7_known"] = age7_known? - attributes["age7"] = field_72 if attributes["age7_known"]&.zero? && field_72&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age7"] = field_68 if attributes["age7_known"]&.zero? && field_68&.match(/\A\d{1,3}\z|\AR\z/) attributes["age8_known"] = age8_known? - attributes["age8"] = field_76 if attributes["age8_known"]&.zero? && field_76&.match(/\A\d{1,3}\z|\AR\z/) + attributes["age8"] = field_72 if attributes["age8_known"]&.zero? && field_72&.match(/\A\d{1,3}\z|\AR\z/) - attributes["sex1"] = field_47 - attributes["sex2"] = field_53 - attributes["sex3"] = field_57 - attributes["sex4"] = field_61 - attributes["sex5"] = field_65 - attributes["sex6"] = field_69 - attributes["sex7"] = field_73 - attributes["sex8"] = field_77 + attributes["sex1"] = field_43 + attributes["sex2"] = field_49 + attributes["sex3"] = field_53 + attributes["sex4"] = field_57 + attributes["sex5"] = field_61 + attributes["sex6"] = field_65 + attributes["sex7"] = field_69 + attributes["sex8"] = field_73 attributes["ethnic_group"] = ethnic_group_from_ethnic - attributes["ethnic"] = field_48 - attributes["national"] = field_49 - - attributes["relat2"] = field_51 - attributes["relat3"] = field_55 - attributes["relat4"] = field_59 - attributes["relat5"] = field_63 - attributes["relat6"] = field_67 - attributes["relat7"] = field_71 - attributes["relat8"] = field_75 - - attributes["ecstat1"] = field_50 - attributes["ecstat2"] = field_54 - attributes["ecstat3"] = field_58 - attributes["ecstat4"] = field_62 - attributes["ecstat5"] = field_66 - attributes["ecstat6"] = field_70 - attributes["ecstat7"] = field_74 - attributes["ecstat8"] = field_78 + attributes["ethnic"] = field_44 + attributes["national"] = field_45 + + attributes["relat2"] = field_47 + attributes["relat3"] = field_51 + attributes["relat4"] = field_55 + attributes["relat5"] = field_59 + attributes["relat6"] = field_63 + attributes["relat7"] = field_67 + attributes["relat8"] = field_71 + + attributes["ecstat1"] = field_46 + attributes["ecstat2"] = field_50 + attributes["ecstat3"] = field_54 + attributes["ecstat4"] = field_58 + attributes["ecstat5"] = field_62 + attributes["ecstat6"] = field_66 + attributes["ecstat7"] = field_70 + attributes["ecstat8"] = field_74 attributes["details_known_2"] = details_known?(2) attributes["details_known_3"] = details_known?(3) @@ -1141,84 +1090,81 @@ private attributes["details_known_7"] = details_known?(7) attributes["details_known_8"] = details_known?(8) - attributes["armedforces"] = field_79 + attributes["armedforces"] = field_75 attributes["leftreg"] = leftreg - attributes["reservist"] = field_81 + attributes["reservist"] = field_77 - attributes["preg_occ"] = field_82 + attributes["preg_occ"] = field_78 attributes["housingneeds"] = housingneeds attributes["housingneeds_type"] = housingneeds_type attributes["housingneeds_other"] = housingneeds_other - attributes["illness"] = field_89 + attributes["illness"] = field_85 - attributes["layear"] = field_100 - attributes["waityear"] = field_101 - attributes["reason"] = field_102 - attributes["reasonother"] = field_103 - attributes["prevten"] = field_104 - attributes["homeless"] = field_105 + attributes["layear"] = field_96 + attributes["waityear"] = field_97 + attributes["reason"] = field_98 + attributes["reasonother"] = field_99 + attributes["prevten"] = field_100 + attributes["homeless"] = field_101 attributes["prevloc"] = prevloc attributes["previous_la_known"] = previous_la_known attributes["ppcodenk"] = ppcodenk attributes["ppostcode_full"] = ppostcode_full - attributes["reasonpref"] = field_110 - attributes["rp_homeless"] = field_111 - attributes["rp_insan_unsat"] = field_112 - attributes["rp_medwel"] = field_113 - attributes["rp_hardship"] = field_114 - attributes["rp_dontknow"] = field_115 + attributes["reasonpref"] = field_106 + attributes["rp_homeless"] = field_107 + attributes["rp_insan_unsat"] = field_108 + attributes["rp_medwel"] = field_109 + attributes["rp_hardship"] = field_110 + attributes["rp_dontknow"] = field_111 attributes["cbl"] = cbl attributes["chr"] = chr attributes["cap"] = cap attributes["letting_allocation_unknown"] = letting_allocation_unknown - attributes["referral"] = field_119 + attributes["referral"] = field_116 attributes["net_income_known"] = net_income_known attributes["earnings"] = earnings - attributes["incfreq"] = field_121 - attributes["hb"] = field_123 - attributes["benefits"] = field_124 - - attributes["period"] = field_126 - attributes["brent"] = field_128 - attributes["scharge"] = field_129 - attributes["pscharge"] = field_130 - attributes["supcharg"] = field_131 - attributes["tcharge"] = field_132 - attributes["chcharge"] = field_127 - attributes["is_carehome"] = field_127.present? ? 1 : 0 - attributes["household_charge"] = supported_housing? ? field_125 : nil - attributes["hbrentshortfall"] = field_133 + attributes["incfreq"] = field_119 + attributes["hb"] = field_120 + attributes["benefits"] = field_121 + + attributes["period"] = field_123 + attributes["brent"] = field_125 + attributes["scharge"] = field_126 + attributes["pscharge"] = field_127 + attributes["supcharg"] = field_128 + attributes["chcharge"] = field_124 + attributes["is_carehome"] = field_124.present? ? 1 : 0 + attributes["household_charge"] = supported_housing? ? field_122 : nil + attributes["hbrentshortfall"] = field_129 attributes["tshortfall_known"] = tshortfall_known - attributes["tshortfall"] = field_134 + attributes["tshortfall"] = field_130 attributes["hhmemb"] = hhmemb - attributes["unitletas"] = field_26 + attributes["unitletas"] = field_25 attributes["rsnvac"] = rsnvac - attributes["sheltered"] = field_44 - - attributes["illness_type_1"] = field_98 - attributes["illness_type_2"] = field_92 - attributes["illness_type_3"] = field_95 - attributes["illness_type_4"] = field_90 - attributes["illness_type_5"] = field_91 - attributes["illness_type_6"] = field_93 - attributes["illness_type_7"] = field_94 - attributes["illness_type_8"] = field_97 - attributes["illness_type_9"] = field_96 - attributes["illness_type_10"] = field_99 + attributes["sheltered"] = field_41 + + attributes["illness_type_1"] = field_94 + attributes["illness_type_2"] = field_88 + attributes["illness_type_3"] = field_91 + attributes["illness_type_4"] = field_86 + attributes["illness_type_5"] = field_87 + attributes["illness_type_6"] = field_89 + attributes["illness_type_7"] = field_90 + attributes["illness_type_8"] = field_93 + attributes["illness_type_9"] = field_92 + attributes["illness_type_10"] = field_95 attributes["irproduct_other"] = field_12 - attributes["offered"] = field_28 - attributes["propcode"] = field_14 attributes["majorrepairs"] = majorrepairs @@ -1229,14 +1175,14 @@ private attributes["first_time_property_let_as_social_housing"] = first_time_property_let_as_social_housing - attributes["uprn_known"] = field_18.present? ? 1 : 0 - attributes["uprn_confirmed"] = 1 if field_18.present? + attributes["uprn_known"] = field_16.present? ? 1 : 0 + attributes["uprn_confirmed"] = 1 if field_16.present? attributes["skip_update_uprn_confirmed"] = true - attributes["uprn"] = field_18 - attributes["address_line1"] = field_19 - attributes["address_line2"] = field_20 - attributes["town_or_city"] = field_21 - attributes["county"] = field_22 + attributes["uprn"] = field_16 + attributes["address_line1"] = field_17 + attributes["address_line2"] = field_18 + attributes["town_or_city"] = field_19 + attributes["county"] = field_20 attributes end @@ -1244,13 +1190,13 @@ private def postcode_known if postcode_full.present? 1 - elsif field_25.present? + elsif field_23.present? 0 end end def postcode_full - "#{field_23} #{field_24}" if field_23 && field_24 + "#{field_21} #{field_22}" if field_21 && field_22 end def owning_organisation @@ -1262,112 +1208,42 @@ private end def renewal - case field_6 + case field_7 when 1 1 when 2 0 else - field_6 + field_7 end end def rsnvac - field_27 + field_24 end def scheme - return if scheme_id.nil? || owning_organisation.nil? || managing_organisation.nil? + return if field_5.nil? || owning_organisation.nil? || managing_organisation.nil? - @scheme ||= Scheme.where(id: (owning_organisation.owned_schemes + managing_organisation.owned_schemes).map(&:id)).find_by_id_on_multiple_fields(scheme_id, location_id) + @scheme ||= Scheme.where(id: (owning_organisation.owned_schemes + managing_organisation.owned_schemes).map(&:id)).find_by_id_on_multiple_fields(field_5, field_6) end def location return if scheme.nil? - @location ||= scheme.locations.find_by_id_on_multiple_fields(location_id) - end - - def log_uses_new_scheme_id? - field_16&.start_with?("S") - end - - def log_uses_old_scheme_id? - field_16.present? && !field_16.start_with?("S") - end - - def scheme_field - return :field_16 if log_uses_new_scheme_id? - return :field_15 if log_uses_old_scheme_id? - end - - def scheme_id - return field_16 if log_uses_new_scheme_id? - return field_15 if log_uses_old_scheme_id? - end - - def location_field - return :field_17 if log_uses_new_scheme_id? - return :field_16 if log_uses_old_scheme_id? - end - - def location_id - return field_17 if log_uses_new_scheme_id? - return field_16 if log_uses_old_scheme_id? - end - - def scheme_or_management_group - log_uses_new_scheme_id? ? "scheme" : "management group" - end - - def location_or_scheme - log_uses_new_scheme_id? ? "location" : "scheme" - end - - def renttype - case field_5 - when 1, 2, 3, 4 - :social - when 5, 6, 7, 8 - :affordable - when 9, 10, 11, 12 - :intermediate - end - end - - def rent_type - case renttype - when :social - LettingsLog::RENT_TYPE[:social_rent] - when :affordable - case field_10 - when 1 - LettingsLog::RENT_TYPE[:london_affordable_rent] - when 2, 3 - LettingsLog::RENT_TYPE[:affordable_rent] - end - when :intermediate - case field_11 - when 1 - LettingsLog::RENT_TYPE[:rent_to_buy] - when 2 - LettingsLog::RENT_TYPE[:london_living_rent] - when 3 - LettingsLog::RENT_TYPE[:other_intermediate_rent_product] - end - end + @location ||= scheme.locations.find_by_id_on_multiple_fields(field_6) end def startdate - Date.new(field_9 + 2000, field_8, field_7) if field_9.present? && field_8.present? && field_7.present? + Date.new(field_10 + 2000, field_9, field_8) if field_10.present? && field_9.present? && field_8.present? rescue Date::Error Date.new end def ethnic_group_from_ethnic - return nil if field_48.blank? + return nil if field_44.blank? - case field_48 + case field_44 when 1, 2, 3, 18 0 when 4, 5, 6, 7 @@ -1384,19 +1260,19 @@ private end def age1_known? - return 1 if field_46 == "R" + return 1 if field_42 == "R" 0 end [ - { person: 2, field: :field_52 }, - { person: 3, field: :field_56 }, - { person: 4, field: :field_60 }, - { person: 5, field: :field_64 }, - { person: 6, field: :field_68 }, - { person: 7, field: :field_72 }, - { person: 8, field: :field_76 }, + { person: 2, field: :field_48 }, + { person: 3, field: :field_52 }, + { person: 4, field: :field_56 }, + { person: 5, field: :field_60 }, + { person: 6, field: :field_64 }, + { person: 7, field: :field_68 }, + { person: 8, field: :field_72 }, ].each do |hash| define_method("age#{hash[:person]}_known?") do return 1 if public_send(hash[:field]) == "R" @@ -1409,53 +1285,53 @@ private end def person_2_present? - field_51.present? || field_52.present? || field_53.present? + field_47.present? || field_48.present? || field_49.present? end def person_3_present? - field_55.present? || field_56.present? || field_57.present? + field_51.present? || field_52.present? || field_53.present? end def person_4_present? - field_59.present? || field_60.present? || field_61.present? + field_55.present? || field_56.present? || field_57.present? end def person_5_present? - field_63.present? || field_64.present? || field_65.present? + field_59.present? || field_60.present? || field_61.present? end def person_6_present? - field_67.present? || field_68.present? || field_69.present? + field_63.present? || field_64.present? || field_65.present? end def person_7_present? - field_71.present? || field_72.present? || field_73.present? + field_67.present? || field_68.present? || field_69.present? end def person_8_present? - field_75.present? || field_76.present? || field_77.present? + field_71.present? || field_72.present? || field_73.present? end def leftreg - field_80 + field_76 end def housingneeds - if field_87 == 1 + if field_83 == 1 2 - elsif field_88 == 1 + elsif field_84 == 1 3 - elsif field_87.blank? || field_87&.zero? + elsif field_83.blank? || field_83&.zero? 1 end end def housingneeds_type - if field_83 == 1 + if field_79 == 1 0 - elsif field_84 == 1 + elsif field_80 == 1 1 - elsif field_85 == 1 + elsif field_81 == 1 2 else 3 @@ -1463,12 +1339,12 @@ private end def housingneeds_other - return 1 if field_86 == 1 - return 0 if [field_83, field_84, field_85].include?(1) + return 1 if field_82 == 1 + return 0 if [field_79, field_80, field_81].include?(1) end def prevloc - field_109 + field_105 end def previous_la_known @@ -1476,7 +1352,7 @@ private end def ppcodenk - case field_106 + case field_102 when 1 0 when 2 @@ -1485,11 +1361,11 @@ private end def ppostcode_full - "#{field_107} #{field_108}".strip.gsub(/\s+/, " ") + "#{field_103} #{field_104}".strip.gsub(/\s+/, " ") end def cbl - case field_116 + case field_112 when 2 0 when 1 @@ -1498,7 +1374,7 @@ private end def chr - case field_118 + case field_114 when 2 0 when 1 @@ -1507,7 +1383,7 @@ private end def cap - case field_117 + case field_113 when 2 0 when 1 @@ -1520,7 +1396,7 @@ private end def net_income_known - case field_120 + case field_117 when 1 0 when 2 @@ -1531,11 +1407,11 @@ private end def earnings - field_122.round if field_122.present? + field_118.round if field_118.present? end def tshortfall_known - field_133 == 1 ? 0 : 1 + field_129 == 1 ? 0 : 1 end def hhmemb @@ -1555,13 +1431,13 @@ private end def mrcdate - Date.new(field_38 + 2000, field_37, field_36) if field_38.present? && field_37.present? && field_36.present? + Date.new(field_35 + 2000, field_34, field_33) if field_35.present? && field_34.present? && field_33.present? rescue Date::Error Date.new end def voiddate - Date.new(field_35 + 2000, field_34, field_33) if field_35.present? && field_34.present? && field_33.present? + Date.new(field_32 + 2000, field_31, field_30) if field_32.present? && field_31.present? && field_30.present? rescue Date::Error Date.new end diff --git a/spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb index 4e078333a..6db8e1806 100644 --- a/spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb @@ -183,8 +183,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do end it "returns correct column" do - expect(service.column_for_field("field_5")).to eql("B") - expect(service.column_for_field("field_22")).to eql("EL") + expect(service.column_for_field("field_5")).to eql("F") + expect(service.column_for_field("field_22")).to eql("W") end end @@ -195,8 +195,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do end it "returns correct column" do - expect(service.column_for_field("field_5")).to eql("A") - expect(service.column_for_field("field_22")).to eql("EK") + expect(service.column_for_field("field_5")).to eql("E") + expect(service.column_for_field("field_22")).to eql("V") end end @@ -216,10 +216,10 @@ RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do end it "returns correct column" do - expect(service.column_for_field("field_5")).to eql("N") - expect(service.column_for_field("field_22")).to eql("O") - expect(service.column_for_field("field_26")).to eql("B") - expect(service.column_for_field("field_25")).to eql("EF") + expect(service.column_for_field("field_5")).to eql("B") + expect(service.column_for_field("field_22")).to eql("AS") + expect(service.column_for_field("field_26")).to eql("DH") + expect(service.column_for_field("field_25")).to eql("I") end end end diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index d37295441..0f4bfc055 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -20,12 +20,12 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do field_1: owning_org.old_visible_id, field_2: managing_org.old_visible_id, field_4: "1", - field_5: "1", - field_6: "2", - field_7: now.day.to_s, - field_8: now.month.to_s, - field_9: now.strftime("%g"), - field_45: "1", + field_7: "2", + field_8: now.day.to_s, + field_9: now.month.to_s, + field_10: now.strftime("%g"), + field_11: "0", + field_15: "1", } end @@ -37,7 +37,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do ranges_rent_id: "1", la: "E09000008", beds: 1, - lettype: 3, + lettype: 7, soft_min: 12.41, soft_max: 118.85, hard_min: 9.87, @@ -63,7 +63,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do context "when the only populated fields are whitespace" do before do - parser.field_18 = " " + parser.field_16 = " " end it "returns true" do @@ -100,7 +100,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when calling the method multiple times" do - let(:attributes) { { bulk_upload:, field_134: 2 } } + let(:attributes) { { bulk_upload:, field_130: 2 } } it "does not add keep adding errors to the pile" do expect { parser.valid? }.not_to change(parser.errors, :count) @@ -111,125 +111,122 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:valid_attributes) do { bulk_upload:, - field_5: "1", field_13: "123", - field_7: now.day.to_s, - field_8: now.month.to_s, - field_9: now.strftime("%g"), - field_23: "EC1N", - field_24: "2TD", + field_8: now.day.to_s, + field_9: now.month.to_s, + field_10: now.strftime("%g"), + field_21: "EC1N", + field_22: "2TD", field_1: owning_org.old_visible_id, field_2: managing_org.old_visible_id, - field_11: "1", - field_6: "2", - field_29: "2", - field_30: "1", - field_31: "1", - field_32: "1", - field_39: "2", - field_40: "1", - field_41: "2", - field_45: "1", - - field_46: "42", - field_52: "41", - field_56: "20", - field_60: "18", - field_64: "16", - field_68: "14", - field_72: "12", - field_76: "20", - - field_47: "F", - field_53: "M", - field_57: "F", - field_61: "M", - field_65: "F", - field_69: "M", - field_73: "F", - field_77: "M", - - field_48: "17", - field_49: "18", - - field_51: "P", - field_55: "C", - field_59: "X", - field_63: "R", + field_11: "0", + field_7: "2", + field_26: "2", + field_27: "1", + field_28: "1", + field_29: "1", + field_36: "2", + field_37: "1", + field_38: "2", + field_15: "1", + + field_42: "42", + field_48: "41", + field_52: "20", + field_56: "18", + field_60: "16", + field_64: "14", + field_68: "12", + field_72: "20", + + field_43: "F", + field_49: "M", + field_53: "F", + field_57: "M", + field_61: "F", + field_65: "M", + field_69: "F", + field_73: "M", + + field_44: "17", + field_45: "18", + + field_47: "P", + field_51: "C", + field_55: "X", + field_59: "R", + field_63: "C", field_67: "C", - field_71: "C", - field_75: "X", - - field_50: "1", - field_54: "2", - field_58: "6", - field_62: "7", - field_66: "8", - field_70: "9", - field_74: "0", - field_78: "10", + field_71: "X", - field_79: "1", - field_80: "4", - field_81: "1", + field_46: "1", + field_50: "2", + field_54: "6", + field_58: "7", + field_62: "8", + field_66: "9", + field_70: "0", + field_74: "10", + + field_75: "1", + field_76: "4", + field_77: "1", + + field_78: "1", + field_79: "1", + field_80: "0", + field_81: "0", field_82: "1", + field_83: "0", - field_83: "1", - field_84: "0", - field_85: "0", - field_86: "1", - field_87: "0", + field_85: "2", - field_89: "2", + field_96: "5", + field_97: "2", + field_98: "31", + field_100: "3", + field_101: "11", - field_100: "5", - field_101: "2", - field_102: "31", - field_104: "3", - field_105: "11", + field_102: "1", + field_103: "EC1N", + field_104: "2TD", field_106: "1", - field_107: "EC1N", - field_108: "2TD", + field_107: "1", + field_108: "", + field_109: "1", + field_110: "", + field_111: "", - field_110: "1", - field_111: "1", - field_112: "", - field_113: "1", - field_114: "", - field_115: "", + field_112: "1", + field_113: "2", + field_114: "2", - field_116: "1", - field_117: "2", - field_118: "2", + field_116: "2", + field_117: "1", + field_118: "2000", field_119: "2", - field_120: "1", - field_122: "2000", - field_121: "2", - field_123: "1", - field_124: "1", - - field_126: "4", - field_128: "1234.56", - field_129: "43.32", - field_130: "13.14", - field_131: "101.11", - field_132: "1500.19", - field_133: "1", - field_134: "234.56", - - field_27: "15", - field_28: "0", - field_33: now.day.to_s, - field_34: now.month.to_s, - field_35: now.strftime("%g"), + field_121: "1", + + field_123: "4", + field_125: "1234.56", + field_126: "43.32", + field_127: "13.14", + field_128: "101.11", + field_129: "1", + field_130: "234.56", + + field_24: "15", + field_30: now.day.to_s, + field_31: now.month.to_s, + field_32: now.strftime("%g"), field_4: "1", - field_18: "12", + field_16: "12", } end @@ -272,22 +269,21 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode + :field_21, # postcode_full + :field_22, # postcode_full :field_23, # postcode_full - :field_24, # postcode_full - :field_25, # postcode_full - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser.errors[field]).to include(error_message) end - expect(parser.errors[:field_17]).not_to include(error_message) + expect(parser.errors[:field_6]).not_to include(error_message) end end @@ -310,28 +306,27 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_16, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser.errors[field]).to include(error_message) end + expect(parser.errors[:field_21]).not_to include(error_message) + expect(parser.errors[:field_22]).not_to include(error_message) expect(parser.errors[:field_23]).not_to include(error_message) - expect(parser.errors[:field_24]).not_to include(error_message) - expect(parser.errors[:field_25]).not_to include(error_message) end end context "with old core scheme and location ids" do context "when a supported housing log already exists in the db" do - let(:attributes) { { bulk_upload:, field_4: "2", field_16: "123" } } + let(:attributes) { { bulk_upload:, field_4: "2", field_5: "123" } } before do parser.log.save! @@ -349,36 +344,35 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_16, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser.errors[field]).to include(error_message) end + expect(parser.errors[:field_21]).not_to include(error_message) + expect(parser.errors[:field_22]).not_to include(error_message) expect(parser.errors[:field_23]).not_to include(error_message) - expect(parser.errors[:field_24]).not_to include(error_message) - expect(parser.errors[:field_25]).not_to include(error_message) end end context "when a supported housing log with chcharges already exists in the db" do let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) do - valid_attributes.merge({ field_15: scheme.old_visible_id, + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_16: location.old_visible_id, + field_11: "1", + field_6: location.old_visible_id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "88" }) + field_122: 0, + field_41: 4, + field_124: "88" }) end before do @@ -397,47 +391,47 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_16, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_127, # chcharge - :field_125, # household_charge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 + :field_124, # chcharge + :field_122, # household_charge ].each do |field| expect(parser.errors[field]).to include(error_message) end + expect(parser.errors[:field_21]).not_to include(error_message) + expect(parser.errors[:field_22]).not_to include(error_message) expect(parser.errors[:field_23]).not_to include(error_message) - expect(parser.errors[:field_24]).not_to include(error_message) - expect(parser.errors[:field_25]).not_to include(error_message) end end context "when a supported housing log different chcharges already exists in the db" do let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) do - valid_attributes.merge({ field_15: scheme.old_visible_id, + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_16: location.old_visible_id, + field_11: "1", + field_6: location.old_visible_id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "88" }) + field_122: 0, + field_41: 4, + field_124: "88" }) end let(:attributes_too) do - valid_attributes.merge({ field_15: scheme.old_visible_id, + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_16: location.old_visible_id, + field_11: "1", + field_6: location.old_visible_id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "98" }) + field_122: 0, + field_41: 4, + field_124: "98" }) end let(:parser_too) { described_class.new(attributes_too) } @@ -457,15 +451,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_16, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_5, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser_too.errors[field]).not_to include(error_message) end @@ -475,7 +468,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do context "with new core scheme and location ids" do context "when a supported housing log already exists in the db" do - let(:attributes) { { bulk_upload:, field_4: "2", field_16: "S123" } } + let(:attributes) { { bulk_upload:, field_4: "2", field_5: "S123" } } before do parser.log.save! @@ -493,36 +486,35 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_17, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser.errors[field]).to include(error_message) end + expect(parser.errors[:field_21]).not_to include(error_message) + expect(parser.errors[:field_22]).not_to include(error_message) expect(parser.errors[:field_23]).not_to include(error_message) - expect(parser.errors[:field_24]).not_to include(error_message) - expect(parser.errors[:field_25]).not_to include(error_message) end end context "when a supported housing log with chcharges already exists in the db" do let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) do - valid_attributes.merge({ field_16: "S#{scheme.id}", + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_17: location.id, + field_11: "1", + field_6: location.id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "88" }) + field_122: 0, + field_41: 4, + field_124: "88" }) end before do @@ -541,47 +533,47 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_17, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_127, # chcharge - :field_125, # household_charge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 + :field_124, # chcharge + :field_122, # household_charge ].each do |field| expect(parser.errors[field]).to include(error_message) end + expect(parser.errors[:field_21]).not_to include(error_message) + expect(parser.errors[:field_22]).not_to include(error_message) expect(parser.errors[:field_23]).not_to include(error_message) - expect(parser.errors[:field_24]).not_to include(error_message) - expect(parser.errors[:field_25]).not_to include(error_message) end end context "when a supported housing log different chcharges already exists in the db" do let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) do - valid_attributes.merge({ field_16: "S#{scheme.id}", + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_17: location.id, + field_11: "1", + field_6: location.id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "88" }) + field_122: 0, + field_41: 4, + field_124: "88" }) end let(:attributes_too) do - valid_attributes.merge({ field_16: "S#{scheme.id}", + valid_attributes.merge({ field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_17: location.id, + field_11: "1", + field_6: location.id, field_1: owning_org.old_visible_id, - field_125: 0, - field_44: 4, - field_127: "98" }) + field_122: 0, + field_41: 4, + field_124: "98" }) end let(:parser_too) { described_class.new(attributes_too) } @@ -601,15 +593,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate + :field_10, # startdate :field_13, # tenancycode - :field_17, # location - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_6, # location + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser_too.errors[field]).not_to include(error_message) end @@ -619,15 +610,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do context "when the rent range validation is triggered but the log has no scheme or location id" do let(:attributes) do - setup_section_params.merge({ field_15: nil, - field_16: nil, - field_17: nil, - field_128: 300, - field_126: 1, - field_32: 1, + setup_section_params.merge({ field_5: nil, + field_6: nil, + field_125: 300, + field_123: 1, + field_29: 1, field_4: 1, - field_5: "3", - field_25: "E09000008" }) + field_11: "1", + field_23: "E09000008" }) end it "is not a valid row" do @@ -651,17 +641,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do [ :field_1, # owning_organisation - :field_7, # startdate :field_8, # startdate :field_9, # startdate - :field_17, # location + :field_10, # startdate + :field_6, # location + :field_21, # postcode_full + :field_22, # postcode_full :field_23, # postcode_full - :field_24, # postcode_full - :field_25, # postcode_full - :field_46, # age1 - :field_47, # sex1 - :field_50, # ecstat1 - :field_132, # tcharge + :field_42, # age1 + :field_43, # sex1 + :field_46, # ecstat1 ].each do |field| expect(parser.errors[field]).to be_blank end @@ -669,24 +658,24 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when valid row with valid decimal (integer) field_5" do + context "when valid row with valid decimal (integer) field_11" do before do allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true) end - let(:attributes) { valid_attributes.merge(field_5: "1.00") } + let(:attributes) { valid_attributes.merge(field_11: "0.00") } it "returns true" do expect(parser).to be_valid end end - context "when valid row with invalid decimal (non-integer) field_5" do + context "when valid row with invalid decimal (non-integer) field_11" do before do allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true) end - let(:attributes) { valid_attributes.merge(field_5: "1.56") } + let(:attributes) { valid_attributes.merge(field_11: "0.56") } it "returns false" do expect(parser).not_to be_valid @@ -696,12 +685,12 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#validate_nulls" do context "when non-setup questions are null" do - let(:attributes) { setup_section_params.merge({ field_18: "", field_19: "", field_21: "" }) } + let(:attributes) { setup_section_params.merge({ field_16: "", field_17: "", field_19: "" }) } it "fetches the question's check_answer_label if it exists, otherwise it gets the question's header" do parser.valid? - expect(parser.errors[:field_19]).to eql(["You must answer address line 1"]) - expect(parser.errors[:field_21]).to eql(["You must answer town or city"]) + expect(parser.errors[:field_17]).to eql(["You must answer address line 1"]) + expect(parser.errors[:field_19]).to eql(["You must answer town or city"]) end end end @@ -713,7 +702,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do it "has errors on setup fields" do errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute).sort - expect(errors).to eql(%i[field_1 field_2 field_4 field_45 field_5 field_6 field_7 field_8 field_9]) + expect(errors).to eql(%i[field_1 field_10 field_11 field_15 field_2 field_4 field_7 field_8 field_9]) end end @@ -779,144 +768,22 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - describe "#field_5" do - context "when null" do - let(:attributes) { { bulk_upload:, field_5: nil, field_15: "1" } } - - it "returns an error" do - expect(parser.errors[:field_5]).to be_present - end - end - - context "when incorrect data type" do - let(:attributes) { { bulk_upload:, field_5: "foo" } } - - it "returns an error" do - expect(parser.errors[:field_5]).to be_present - end - end - - context "when unpermitted value" do - let(:attributes) { { bulk_upload:, field_5: "101" } } - - it "returns an error" do - expect(parser.errors[:field_5]).to be_present - end - end - - context "when valid" do - let(:attributes) { { bulk_upload:, field_5: "1", field_4: "1" } } - - it "does not return any errors" do - expect(parser.errors[:field_5]).to be_blank - end - end - - context "when intermediate rent and field_11 (Which type of Intermediate Rent) is not given" do - let(:attributes) { { bulk_upload:, field_5: "9", field_11: nil } } - - it "adds error on field_11" do - expect(parser.errors[:field_5]).to be_present - expect(parser.errors[:field_11]).to eq(["You must answer intermediate rent type"]) - end - end - - context "when intermediate rent and field_11 (Which type of Intermediate Rent) is invalid/gets cleared" do - let(:attributes) { { bulk_upload:, field_5: "9", field_11: "Intermediate rent" } } - - it "adds error on field_11" do - expect(parser.errors[:field_5]).to be_present - expect(parser.errors[:field_11]).to eq(["You must answer intermediate rent type"]) - end - end - - context "when affordable rent and field_10 (Is this a London Affordable Rent letting?) is not given" do - let(:attributes) { { bulk_upload:, field_5: "5", field_10: nil } } - - it "adds error on field_10" do - expect(parser.errors[:field_5]).to be_present - expect(parser.errors[:field_10]).to eq(["You must answer is this a London Affordable Rent letting"]) - end - end - - context "when affordable rent and field_10 (Is this a London Affordable Rent letting?) is invalid/gets cleared" do - let(:attributes) { { bulk_upload:, field_5: "5", field_10: "Intermediate rent" } } - - it "adds error on field_10" do - expect(parser.errors[:field_5]).to be_present - expect(parser.errors[:field_10]).to eq(["You must answer is this a London Affordable Rent letting"]) - end - end - - context "when intermediate rent other and field_12 is not given" do - let(:attributes) { { bulk_upload:, field_5: "9", field_11: "3", field_12: nil } } - - it "adds error on field_12" do - expect(parser.errors[:field_12]).to eq(["You must answer product name"]) - end - end - - context "when bulk upload is for general needs" do - context "when general needs option selected" do - let(:attributes) { { bulk_upload:, field_5: "1", field_4: "1" } } - - it "is permitted" do - expect(parser.errors[:field_4]).to be_blank - expect(parser.errors[:field_5]).to be_blank - end - end - - context "when supported housing option selected" do - let(:attributes) { { bulk_upload:, field_5: "2", field_4: "1" } } - - it "is not permitted" do - expect(parser.errors[:field_4]).to include("This letting type is supported housing, but the needs type is general needs. Change either the needs type or the letting type.") - expect(parser.errors[:field_5]).to include("This needs type is general needs, but the letting type is supported housing. Change either the needs type or the letting type.") - end - end - end - - context "when bulk upload is for supported housing" do - let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } - - context "when general needs option selected" do - let(:attributes) { { bulk_upload:, field_5: "1", field_4: "2" } } - - it "is not permitted" do - expect(parser.errors[:field_4]).to include("This letting type is general needs, but the needs type is supported housing. Change either the needs type or the letting type.") - expect(parser.errors[:field_5]).to include("This needs type is supported housing, but the letting type is general needs. Change either the needs type or the letting type.") - end - end - - context "when supported housing option selected" do - let(:attributes) { { bulk_upload:, field_5: "2", field_4: "2" } } - - it "is permitted" do - expect(parser.errors[:field_4]).to be_blank - expect(parser.errors[:field_5]).to be_blank - end - end - end - end - - describe "#field_15, field_16, field_17" do # scheme and location fields + describe "#field_5, field_6" do # scheme and location fields context "when nullable not permitted" do - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: nil, field_16: nil, field_17: nil } } + let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: nil, field_6: nil } } it "cannot be nulled" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to eq(["You must answer scheme code"]) - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors[:field_5]).to eq(["You must answer scheme code"]) + expect(parser.errors[:field_6]).to eq(["You must answer location code"]) end end context "when nullable permitted" do - let(:attributes) { { bulk_upload:, field_4: "1", field_5: "1", field_15: nil, field_16: nil, field_17: nil } } + let(:attributes) { { bulk_upload:, field_4: "1", field_11: "0", field_5: nil, field_6: nil } } it "can be nulled" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors[:field_6]).to be_blank end end @@ -929,443 +796,328 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when matching scheme cannot be found" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S123", field_17: location.id } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S123", field_6: location.id } } it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) + expect(parser.errors[:field_6]).to be_blank end end context "when missing location" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: nil } } - - it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["You must answer location code"]) - expect(parser.errors[:field_17].count).to eq(1) - end - end - - context "when missing management group code" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: scheme.old_visible_id.to_s, field_15: nil, field_17: nil } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: nil } } it "returns a setup error" do - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank - expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["You must answer management group code"]) - expect(parser.errors[:field_15].count).to eq(1) + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to eq(["You must answer location code"]) + expect(parser.errors[:field_6].count).to eq(1) end end context "when matching location cannot be found" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: "123" } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: "123" } } it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"]) + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"]) end end context "when matching location exists" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: location.id } } it "does not return an error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors[:field_6]).to be_blank end end context "when location exists but not related" do let(:other_scheme) { create(:scheme, :with_old_visible_id) } let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: other_location.id } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: other_location.id } } it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"]) + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"]) end end context "when scheme belongs to someone else" do let(:other_scheme) { create(:scheme, :with_old_visible_id) } let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{other_scheme.id}", field_17: other_location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{other_scheme.id}", field_6: other_location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) + expect(parser.errors[:field_6]).to be_blank end end context "when scheme belongs to owning org" do - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } it "does not return an error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors[:field_5]).to be_blank + expect(parser.errors[:field_6]).to be_blank end end context "when scheme belongs to managing org" do let(:managing_org_scheme) { create(:scheme, :with_old_visible_id, owning_organisation: managing_org) } let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) } - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{managing_org_scheme.id}", field_17: managing_org_location.id, field_2: managing_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{managing_org_scheme.id}", field_6: managing_org_location.id, field_2: managing_org.old_visible_id } } it "clears the scheme answer" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to include("You must answer scheme name") - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors[:field_5]).to include("You must answer scheme name") + expect(parser.errors[:field_6]).to be_blank end end context "when matching location exists but is incomplete" do let(:incomplete_location) { create(:location, :with_old_visible_id, :incomplete, scheme:) } - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: incomplete_location.id } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: incomplete_location.id } } it "returns a setup error for scheme" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) - expect(parser.errors.where(:field_17).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) - end - end - end - - context "when using Old CORE ids" do - let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) } - let!(:location) { create(:location, :with_old_visible_id, scheme:) } - - before do - parser.valid? - end - - context "when matching scheme cannot be found" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: "123", field_16: location.old_visible_id } } - - it "returns a setup error" do - expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["This management group code does not belong to the owning organisation or managing organisation"]) - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when missing location" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: nil } } - - it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["You must answer scheme code"]) - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when matching location cannot be found" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: "123" } } - - it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme code must relate to a scheme that is owned by the owning organisation or managing organisation"]) - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when matching location exists" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id } } - - it "does not return an error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when location exists but not related" do - let(:other_scheme) { create(:scheme, :with_old_visible_id) } - let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: other_location.old_visible_id } } - - it "returns a setup error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme code must relate to a scheme that is owned by the owning organisation or managing organisation"]) - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when scheme belongs to someone else" do - let(:other_scheme) { create(:scheme, :with_old_visible_id) } - let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: other_scheme.old_visible_id, field_16: other_location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - it "returns a setup error" do - expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["This management group code does not belong to the owning organisation or managing organisation"]) - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when scheme belongs to owning org" do - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - it "does not return an error" do - expect(parser.errors[:field_15]).to be_blank - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank - end - end - - context "when scheme belongs to managing org" do - let(:managing_org_scheme) { create(:scheme, :with_old_visible_id, owning_organisation: managing_org) } - let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) } - let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: managing_org_scheme.old_visible_id, field_16: managing_org_location.old_visible_id, field_2: managing_org.old_visible_id } } - - it "clears the scheme answer" do - expect(parser.errors[:field_15]).to include("You must answer scheme name") - expect(parser.errors[:field_16]).to be_blank - expect(parser.errors[:field_17]).to be_blank + expect(parser.errors.where(:field_5).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) + expect(parser.errors.where(:field_6).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) end end end end - describe "#field_102" do # leaving reason - context "when field_6 is 1 meaning it is a renewal" do - context "when field_102 is 40" do - let(:attributes) { { bulk_upload:, field_102: "40", field_6: "1" } } + describe "#field_98" do # leaving reason + context "when field_7 is 1 meaning it is a renewal" do + context "when field_98 is 40" do + let(:attributes) { { bulk_upload:, field_98: "40", field_7: "1" } } it "is permitted" do - expect(parser.errors[:field_102]).to be_blank + expect(parser.errors[:field_98]).to be_blank end end - context "when field_102 is 42" do - let(:attributes) { { bulk_upload:, field_102: "42", field_6: "1" } } + context "when field_98 is 42" do + let(:attributes) { { bulk_upload:, field_98: "42", field_7: "1" } } it "is permitted" do - expect(parser.errors[:field_102]).to be_blank + expect(parser.errors[:field_98]).to be_blank end end - context "when field_102 is not 40 or 42" do - let(:attributes) { { bulk_upload:, field_102: "1", field_6: "1" } } + context "when field_98 is not 40 or 42" do + let(:attributes) { { bulk_upload:, field_98: "1", field_7: "1" } } it "is not permitted" do - expect(parser.errors[:field_102]).to be_present + expect(parser.errors[:field_98]).to be_present end end end context "when no longer a valid option from previous year" do - let(:attributes) { setup_section_params.merge({ field_102: "7" }) } + let(:attributes) { setup_section_params.merge({ field_98: "7" }) } it "returns an error" do - expect(parser.errors[:field_102]).to include("Enter a valid value for What is the tenant’s main reason for the household leaving their last settled home?") + expect(parser.errors[:field_98]).to include("Enter a valid value for What is the tenant’s main reason for the household leaving their last settled home?") end end end - describe "#field_83, #field_84, #field_85" do + describe "#field_79, #field_80, #field_81" do context "when one item selected" do - let(:attributes) { { bulk_upload:, field_83: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1" } } it "is permitted" do - expect(parser.errors[:field_83]).to be_blank - expect(parser.errors[:field_84]).to be_blank - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_79]).to be_blank + expect(parser.errors[:field_80]).to be_blank + expect(parser.errors[:field_81]).to be_blank end end context "when more than one item selected" do - let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1", field_80: "1" } } it "is not permitted" do - expect(parser.errors[:field_83]).to be_present - expect(parser.errors[:field_84]).to be_present + expect(parser.errors[:field_79]).to be_present + expect(parser.errors[:field_80]).to be_present end end end - describe "#field_87" do + describe "#field_83" do context "when 1 and another disability field selected" do - let(:attributes) { { bulk_upload:, field_87: "1", field_86: "1" } } + let(:attributes) { { bulk_upload:, field_83: "1", field_82: "1" } } it "is not permitted" do - expect(parser.errors[:field_87]).to be_present + expect(parser.errors[:field_83]).to be_present end end end - describe "#field_88" do + describe "#field_84" do context "when 1 and another disability field selected" do - let(:attributes) { { bulk_upload:, field_88: "1", field_86: "1" } } + let(:attributes) { { bulk_upload:, field_84: "1", field_82: "1" } } it "is not permitted" do - expect(parser.errors[:field_88]).to be_present + expect(parser.errors[:field_84]).to be_present end end end - describe "#field_87, #field_88" do + describe "#field_83, #field_84" do context "when both 1" do - let(:attributes) { { bulk_upload:, field_87: "1", field_88: "1" } } + let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } } it "is not permitted" do - expect(parser.errors[:field_87]).to be_present - expect(parser.errors[:field_88]).to be_present + expect(parser.errors[:field_83]).to be_present + expect(parser.errors[:field_84]).to be_present end end end - describe "#field_83 - #field_88" do + describe "#field_79 - #field_84" do context "when all blank" do - let(:attributes) { setup_section_params.merge({ field_83: nil, field_84: nil, field_85: nil, field_86: nil, field_87: nil, field_88: nil }) } + let(:attributes) { setup_section_params.merge({ field_79: nil, field_80: nil, field_81: nil, field_82: nil, field_83: nil, field_84: nil }) } it "adds errors to correct fields" do + expect(parser.errors[:field_79]).to be_present + expect(parser.errors[:field_80]).to be_present + expect(parser.errors[:field_81]).to be_present + expect(parser.errors[:field_82]).to be_present expect(parser.errors[:field_83]).to be_present - expect(parser.errors[:field_84]).to be_present - expect(parser.errors[:field_85]).to be_present - expect(parser.errors[:field_86]).to be_present - expect(parser.errors[:field_87]).to be_present end end - context "when one item selected and field_86 is blank" do - let(:attributes) { setup_section_params.merge({ field_83: "1", field_86: nil }) } + context "when one item selected and field_82 is blank" do + let(:attributes) { setup_section_params.merge({ field_79: "1", field_82: nil }) } it "sets other disabled access needs as no" do - expect(parser.errors[:field_83]).to be_blank - expect(parser.errors[:field_86]).to be_blank + expect(parser.errors[:field_79]).to be_blank + expect(parser.errors[:field_82]).to be_blank expect(parser.log.housingneeds_other).to eq(0) end end end - describe "#field_89, field_98 - 99" do + describe "#field_85, field_94 - 99" do context "when no illness but illnesses answered" do - let(:attributes) { { bulk_upload:, field_89: "2", field_90: "1", field_91: "1", field_92: "1" } } + let(:attributes) { { bulk_upload:, field_85: "2", field_86: "1", field_87: "1", field_88: "1" } } it "errors added to correct fields" do - expect(parser.errors[:field_90]).to be_present - expect(parser.errors[:field_91]).to be_present - expect(parser.errors[:field_92]).to be_present + expect(parser.errors[:field_86]).to be_present + expect(parser.errors[:field_87]).to be_present + expect(parser.errors[:field_88]).to be_present + expect(parser.errors[:field_89]).not_to be_present + expect(parser.errors[:field_90]).not_to be_present + expect(parser.errors[:field_91]).not_to be_present + expect(parser.errors[:field_92]).not_to be_present expect(parser.errors[:field_93]).not_to be_present expect(parser.errors[:field_94]).not_to be_present expect(parser.errors[:field_95]).not_to be_present - expect(parser.errors[:field_96]).not_to be_present - expect(parser.errors[:field_97]).not_to be_present - expect(parser.errors[:field_98]).not_to be_present - expect(parser.errors[:field_99]).not_to be_present end end context "when illness but no illnesses answered" do - let(:attributes) { { bulk_upload:, field_89: "1", field_90: nil, field_91: nil, field_92: nil, field_93: nil, field_94: nil, field_95: nil, field_96: nil, field_97: nil, field_98: nil, field_99: nil } } + let(:attributes) { { bulk_upload:, field_85: "1", field_86: nil, field_87: nil, field_88: nil, field_89: nil, field_90: nil, field_91: nil, field_92: nil, field_93: nil, field_94: nil, field_95: nil } } it "errors added to correct fields" do + expect(parser.errors[:field_86]).to be_present + expect(parser.errors[:field_87]).to be_present + expect(parser.errors[:field_88]).to be_present + expect(parser.errors[:field_89]).to be_present expect(parser.errors[:field_90]).to be_present expect(parser.errors[:field_91]).to be_present expect(parser.errors[:field_92]).to be_present expect(parser.errors[:field_93]).to be_present expect(parser.errors[:field_94]).to be_present expect(parser.errors[:field_95]).to be_present - expect(parser.errors[:field_96]).to be_present - expect(parser.errors[:field_97]).to be_present - expect(parser.errors[:field_98]).to be_present - expect(parser.errors[:field_99]).to be_present end end end - describe "#field_116, 117, 118" do - context "when none of field_116, 117, 118 are given" do - let(:attributes) { { bulk_upload:, field_116: "", field_117: "", field_118: "", field_89: "1" } } + describe "#field_112, 117, 118" do + context "when none of field_112, 117, 118 are given" do + let(:attributes) { { bulk_upload:, field_112: "", field_113: "", field_114: "", field_85: "1" } } it "sets correct errors" do - expect(parser.errors[:field_116]).to include("You must answer was the letting made under the Choice-Based Lettings (CBL)?") - expect(parser.errors[:field_117]).to include("You must answer was the letting made under the Common Allocation Policy (CAP)?") - expect(parser.errors[:field_118]).to include("You must answer was the letting made under the Common Housing Register (CHR)?") + expect(parser.errors[:field_112]).to include("You must answer was the letting made under the Choice-Based Lettings (CBL)?") + expect(parser.errors[:field_113]).to include("You must answer was the letting made under the Common Allocation Policy (CAP)?") + expect(parser.errors[:field_114]).to include("You must answer was the letting made under the Common Housing Register (CHR)?") end end end - describe "#field_105, field_110 - 15" do + describe "#field_101, field_106 - 15" do context "when there is a reasonable preference but none is given" do - let(:attributes) { { bulk_upload:, field_110: "1", field_111: nil, field_112: nil, field_113: nil, field_114: nil, field_115: nil } } + let(:attributes) { { bulk_upload:, field_106: "1", field_107: nil, field_108: nil, field_109: nil, field_110: nil, field_111: nil } } it "is not permitted" do + expect(parser.errors[:field_107]).to be_present + expect(parser.errors[:field_108]).to be_present + expect(parser.errors[:field_109]).to be_present + expect(parser.errors[:field_110]).to be_present expect(parser.errors[:field_111]).to be_present - expect(parser.errors[:field_112]).to be_present - expect(parser.errors[:field_113]).to be_present - expect(parser.errors[:field_114]).to be_present - expect(parser.errors[:field_115]).to be_present end end end - describe "#field_119" do # referral + describe "#field_116" do # referral context "when 3 ie PRP nominated by LA and owning org is LA" do - let(:attributes) { { bulk_upload:, field_119: "3", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_116: "3", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } it "is not permitted" do - expect(parser.errors[:field_119]).to be_present + expect(parser.errors[:field_116]).to be_present end end context "when 4 ie referred by LA and is general needs and owning org is LA" do - let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "1" } } + let(:attributes) { { bulk_upload:, field_116: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "1" } } it "is not permitted" do - expect(parser.errors[:field_119]).to be_present + expect(parser.errors[:field_116]).to be_present end end context "when 4 ie referred by LA and is general needs and owning org is PRP" do let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) } - let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_116: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } it "is permitted" do - expect(parser.errors[:field_119]).to be_blank + expect(parser.errors[:field_116]).to be_blank end end context "when 4 ie referred by LA and is not general needs" do let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } - let(:attributes) { { bulk_upload:, field_119: "4", field_4: "2" } } + let(:attributes) { { bulk_upload:, field_116: "4", field_4: "2" } } it "is permitted" do - expect(parser.errors[:field_119]).to be_blank + expect(parser.errors[:field_116]).to be_blank end end end describe "fields 7, 8, 9 => startdate" do context "when any one of these fields is blank" do - let(:attributes) { { bulk_upload:, field_5: "1", field_7: nil, field_8: nil, field_9: nil } } + let(:attributes) { { bulk_upload:, field_11: "0", field_8: nil, field_9: nil, field_10: nil } } it "returns an error" do - expect(parser.errors[:field_7]).to be_present expect(parser.errors[:field_8]).to be_present expect(parser.errors[:field_9]).to be_present + expect(parser.errors[:field_10]).to be_present end end - context "when field_9 is 4 digits instead of 2" do - let(:attributes) { { bulk_upload:, field_9: "2022" } } + context "when field_10 is 4 digits instead of 2" do + let(:attributes) { { bulk_upload:, field_10: "2023" } } it "returns an error" do - expect(parser.errors[:field_9]).to include("Tenancy start year must be 2 digits") + expect(parser.errors[:field_10]).to include("Tenancy start year must be 2 digits") end end context "when invalid date given" do - let(:attributes) { { bulk_upload:, field_5: "1", field_7: "a", field_8: "12", field_9: "22" } } + let(:attributes) { { bulk_upload:, field_11: "0", field_8: "a", field_9: "12", field_10: "23" } } it "does not raise an error" do expect { parser.valid? }.not_to raise_error @@ -1373,32 +1125,32 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when inside of collection year" do - let(:attributes) { { bulk_upload:, field_7: "1", field_8: "10", field_9: "22" } } + let(:attributes) { { bulk_upload:, field_8: "1", field_9: "10", field_10: "23" } } let(:bulk_upload) { create(:bulk_upload, :lettings, user:, year: 2022) } it "does not return errors" do - expect(parser.errors[:field_7]).not_to be_present expect(parser.errors[:field_8]).not_to be_present expect(parser.errors[:field_9]).not_to be_present + expect(parser.errors[:field_10]).not_to be_present end end context "when outside of collection year" do around do |example| - Timecop.freeze(Date.new(2022, 4, 2)) do + Timecop.freeze(Date.new(2023, 4, 2)) do example.run end end - let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "22" } } + let(:attributes) { { bulk_upload:, field_8: "1", field_9: "1", field_10: "23" } } - let(:bulk_upload) { create(:bulk_upload, :lettings, user:, year: 2022) } + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, year: 2023) } it "returns setup errors" do - expect(parser.errors.where(:field_7, category: :setup)).to be_present expect(parser.errors.where(:field_8, category: :setup)).to be_present expect(parser.errors.where(:field_9, category: :setup)).to be_present + expect(parser.errors.where(:field_10, category: :setup)).to be_present end end end @@ -1501,9 +1253,9 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do parser.valid? expect(parser.errors[:field_1]).to include(/The owning organisation must be active on the tenancy start date/) expect(parser.errors[:field_2]).to include(/The managing organisation must be active on the tenancy start date/) - expect(parser.errors[:field_7]).to include(/Enter a date when the owning and managing organisation was active/) expect(parser.errors[:field_8]).to include(/Enter a date when the owning and managing organisation was active/) expect(parser.errors[:field_9]).to include(/Enter a date when the owning and managing organisation was active/) + expect(parser.errors[:field_10]).to include(/Enter a date when the owning and managing organisation was active/) end end end @@ -1564,30 +1316,30 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - describe "#field_6" do # renewal + describe "#field_7" do # renewal context "when blank" do - let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_6: "" } } + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_7: "" } } it "has setup errors on the field" do - expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to eql(["You must answer property renewal"]) + expect(parser.errors.where(:field_7, category: :setup).map(&:message)).to eql(["You must answer property renewal"]) end end context "when none possible option selected" do - let(:attributes) { setup_section_params.merge({ field_6: "101" }) } + let(:attributes) { setup_section_params.merge({ field_7: "101" }) } it "adds a setup error" do - expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to include("Enter a valid value for Is this letting a renewal?") + expect(parser.errors.where(:field_7, category: :setup).map(&:message)).to include("Enter a valid value for Is this letting a renewal?") end end end - describe "#field_18" do # UPRN + describe "#field_16" do # UPRN context "when over 12 characters" do - let(:attributes) { setup_section_params.merge({ field_18: "1234567890123" }) } + let(:attributes) { setup_section_params.merge({ field_16: "1234567890123" }) } it "adds an appropriate error" do - expect(parser.errors[:field_18]).to eql(["UPRN is not recognised. Check the number, or enter the address"]) + expect(parser.errors[:field_16]).to eql(["UPRN is not recognised. Check the number, or enter the address"]) end end @@ -1595,9 +1347,9 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) { setup_section_params } it "adds appropriate errors" do - expect(parser.errors[:field_18]).to eql(["You must answer UPRN"]) - expect(parser.errors[:field_19]).to eql(["You must answer address line 1"]) - expect(parser.errors[:field_21]).to eql(["You must answer town or city"]) + expect(parser.errors[:field_16]).to eql(["You must answer UPRN"]) + expect(parser.errors[:field_17]).to eql(["You must answer address line 1"]) + expect(parser.errors[:field_19]).to eql(["You must answer town or city"]) end end @@ -1605,17 +1357,17 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) } let(:attributes) do { bulk_upload:, - field_15: scheme.old_visible_id, + field_5: "S#{scheme.id}", field_4: "2", - field_5: "2", - field_16: location.old_visible_id, + field_11: "1", + field_6: location.old_visible_id, field_1: "1" } end it "does not add UPRN errors" do - expect(parser.errors[:field_18]).to be_empty + expect(parser.errors[:field_16]).to be_empty + expect(parser.errors[:field_17]).to be_empty expect(parser.errors[:field_19]).to be_empty - expect(parser.errors[:field_21]).to be_empty end end @@ -1623,12 +1375,12 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) do { bulk_upload:, - field_18: "123456789012", + field_16: "123456789012", } end it "doesn't add an error" do - expect(parser.errors[:field_18]).to be_empty + expect(parser.errors[:field_16]).to be_empty end end @@ -1636,90 +1388,90 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) do { bulk_upload:, - field_19: "1 Example Rd", - field_21: "Example Town/City", + field_17: "1 Example Rd", + field_19: "Example Town/City", } end it "doesn't add an error" do - expect(parser.errors[:field_18]).to be_empty + expect(parser.errors[:field_16]).to be_empty end end end - describe "#field_26" do # unitletas + describe "#field_25" do # unitletas context "when no longer a valid option from previous year" do - let(:attributes) { setup_section_params.merge({ field_26: "4" }) } + let(:attributes) { setup_section_params.merge({ field_25: "4" }) } it "returns an error" do - expect(parser.errors[:field_26]).to be_present + expect(parser.errors[:field_25]).to be_present end end end - describe "#field_30" do + describe "#field_27" do context "when null" do - let(:attributes) { setup_section_params.merge({ field_30: nil }) } + let(:attributes) { setup_section_params.merge({ field_27: nil }) } it "returns an error" do - expect(parser.errors[:field_30]).to be_present + expect(parser.errors[:field_27]).to be_present end it "populates with correct error message" do - expect(parser.errors[:field_30]).to eql(["You must answer type of building"]) + expect(parser.errors[:field_27]).to eql(["You must answer type of building"]) end end end - describe "#field_52" do # age2 + describe "#field_48" do # age2 context "when null but gender given" do - let(:attributes) { setup_section_params.merge({ field_52: "", field_53: "F" }) } + let(:attributes) { setup_section_params.merge({ field_48: "", field_49: "F" }) } it "returns an error" do - expect(parser.errors[:field_52]).to be_present + expect(parser.errors[:field_48]).to be_present end end end describe "soft validations" do context "when soft validation is triggered" do - let(:attributes) { setup_section_params.merge({ field_46: 22, field_50: 5 }) } + let(:attributes) { setup_section_params.merge({ field_42: 22, field_46: 5 }) } it "adds an error to the relevant fields" do + expect(parser.errors.where(:field_42, category: :soft_validation)).to be_present expect(parser.errors.where(:field_46, category: :soft_validation)).to be_present - expect(parser.errors.where(:field_50, category: :soft_validation)).to be_present end it "populates with correct error message" do + expect(parser.errors.where(:field_42, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") expect(parser.errors.where(:field_46, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") - expect(parser.errors.where(:field_50, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") end end context "when a soft validation is triggered that relates both to fields that are and are not routed to" do - let(:attributes) { setup_section_params.merge({ field_82: "1", field_47: "M", field_53: "M", field_57: "M" }) } + let(:attributes) { setup_section_params.merge({ field_78: "1", field_43: "M", field_49: "M", field_53: "M" }) } it "adds errors to fields that are routed to" do + expect(parser.errors.where(:field_49, category: :soft_validation)).to be_present expect(parser.errors.where(:field_53, category: :soft_validation)).to be_present - expect(parser.errors.where(:field_57, category: :soft_validation)).to be_present end it "does not add errors to fields that are not routed to" do + expect(parser.errors.where(:field_57, category: :soft_validation)).not_to be_present expect(parser.errors.where(:field_61, category: :soft_validation)).not_to be_present - expect(parser.errors.where(:field_65, category: :soft_validation)).not_to be_present end end context "when soft validation is triggered and not required" do - let(:attributes) { setup_section_params.merge({ field_128: 120, field_126: 1, field_32: 1, field_4: 1, field_5: "3", field_25: "E09000008" }) } + let(:attributes) { setup_section_params.merge({ field_125: 120, field_123: 1, field_29: 1, field_4: 1, field_11: "1", field_23: "E09000008" }) } it "adds an error to the relevant fields" do - expect(parser.errors.where(:field_128, category: :soft_validation)).to be_present + expect(parser.errors.where(:field_125, category: :soft_validation)).to be_present end it "populates with correct error message" do - expect(parser.errors.where(:field_128, category: :soft_validation).count).to be(1) - expect(parser.errors.where(:field_128, 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_125, category: :soft_validation).count).to be(1) + expect(parser.errors.where(:field_125, 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 @@ -1747,7 +1499,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#uprn" do - let(:attributes) { { bulk_upload:, field_18: "12" } } + let(:attributes) { { bulk_upload:, field_16: "12" } } it "sets to given value" do expect(parser.log.uprn).to eql("12") @@ -1756,7 +1508,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#uprn_known" do context "when uprn specified" do - let(:attributes) { { bulk_upload:, field_18: "12" } } + let(:attributes) { { bulk_upload:, field_16: "12" } } it "sets to 1" do expect(parser.log.uprn_known).to be(1) @@ -1765,7 +1517,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when uprn blank" do - let(:attributes) { { bulk_upload:, field_18: "", field_4: 1 } } + let(:attributes) { { bulk_upload:, field_16: "", field_4: 1 } } it "sets to 0" do expect(parser.log.uprn_known).to be(0) @@ -1774,7 +1526,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#address_line1" do - let(:attributes) { { bulk_upload:, field_19: "123 Sesame Street" } } + let(:attributes) { { bulk_upload:, field_17: "123 Sesame Street" } } it "sets to given value" do expect(parser.log.address_line1).to eql("123 Sesame Street") @@ -1782,7 +1534,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#address_line2" do - let(:attributes) { { bulk_upload:, field_20: "Cookie Town" } } + let(:attributes) { { bulk_upload:, field_18: "Cookie Town" } } it "sets to given value" do expect(parser.log.address_line2).to eql("Cookie Town") @@ -1790,7 +1542,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#town_or_city" do - let(:attributes) { { bulk_upload:, field_21: "London" } } + let(:attributes) { { bulk_upload:, field_19: "London" } } it "sets to given value" do expect(parser.log.town_or_city).to eql("London") @@ -1798,7 +1550,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#county" do - let(:attributes) { { bulk_upload:, field_22: "Greater London" } } + let(:attributes) { { bulk_upload:, field_20: "Greater London" } } it "sets to given value" do expect(parser.log.county).to eql("Greater London") @@ -1806,14 +1558,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end [ - %w[age1_known details_known_1 age1 field_46 field_51 field_53], - %w[age2_known details_known_2 age2 field_52 field_51 field_53], - %w[age3_known details_known_3 age3 field_56 field_55 field_57], - %w[age4_known details_known_4 age4 field_60 field_59 field_61], - %w[age5_known details_known_5 age5 field_64 field_63 field_65], - %w[age6_known details_known_6 age6 field_68 field_67 field_69], - %w[age7_known details_known_7 age7 field_72 field_71 field_73], - %w[age8_known details_known_8 age8 field_76 field_75 field_77], + %w[age1_known details_known_1 age1 field_42 field_47 field_49], + %w[age2_known details_known_2 age2 field_48 field_47 field_49], + %w[age3_known details_known_3 age3 field_52 field_51 field_53], + %w[age4_known details_known_4 age4 field_56 field_55 field_57], + %w[age5_known details_known_5 age5 field_60 field_59 field_61], + %w[age6_known details_known_6 age6 field_64 field_63 field_65], + %w[age7_known details_known_7 age7 field_68 field_67 field_69], + %w[age8_known details_known_8 age8 field_72 field_71 field_73], ].each do |known, details_known, age, field, relationship, gender| describe "##{known} and ##{age}" do context "when #{field} is blank" do @@ -1875,90 +1627,22 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#location" do context "when lookup is via new core id" do - let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_17: location.id, field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } } - - it "assigns the correct location" do - expect(parser.log.location).to eql(location) - end - end - - context "when lookup is via old core id" do - let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } + let(:attributes) { { bulk_upload:, field_5: "S#{scheme.id}", field_6: location.id, field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } } it "assigns the correct location" do expect(parser.log.location).to eql(location) end - - context "when location had leading zeroes in its id in Old CORE" do - let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - before do - location.old_visible_id = "00123" - location.save! - end - - it "assigns the correct location" do - expect(parser.log.location).to eql(location) - end - end - - context "when the user provides an id with leading zeroes" do - let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "00123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - before do - location.old_visible_id = "123" - location.save! - end - - it "assigns the correct location" do - expect(parser.log.location).to eql(location) - end - end end end describe "#scheme" do context "when lookup is via new core id" do - let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } } + let(:attributes) { { bulk_upload:, field_5: "S#{scheme.id}", field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } } it "assigns the correct scheme" do expect(parser.log.scheme).to eql(scheme) end end - - context "when lookup is via old core id" do - let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - it "assigns the correct scheme" do - expect(parser.log.scheme).to eql(scheme) - end - - context "when scheme had leading zeroes in its id in Old CORE" do - let(:attributes) { { bulk_upload:, field_15: "10", field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - before do - scheme.old_visible_id = "010" - scheme.save! - end - - it "assigns the correct scheme" do - expect(parser.log.scheme).to eql(scheme) - end - end - - context "when the user provides an id with leading zeroes" do - let(:attributes) { { bulk_upload:, field_15: "010", field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } - - before do - scheme.old_visible_id = "10" - scheme.save! - end - - it "assigns the correct scheme" do - expect(parser.log.scheme).to eql(scheme) - end - end - end end describe "#owning_organisation" do @@ -1982,16 +1666,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#cbl" do - context "when field_116 is yes ie 1" do - let(:attributes) { { bulk_upload:, field_116: 1 } } + context "when field_112 is yes ie 1" do + let(:attributes) { { bulk_upload:, field_112: 1 } } it "sets value to 1" do expect(parser.log.cbl).to be(1) end end - context "when field_116 is no ie 2" do - let(:attributes) { { bulk_upload:, field_116: 2 } } + context "when field_112 is no ie 2" do + let(:attributes) { { bulk_upload:, field_112: 2 } } it "sets value to 0" do expect(parser.log.cbl).to be(0) @@ -2000,16 +1684,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#chr" do - context "when field_118 is yes ie 1" do - let(:attributes) { { bulk_upload:, field_118: 1 } } + context "when field_114 is yes ie 1" do + let(:attributes) { { bulk_upload:, field_114: 1 } } it "sets value to 1" do expect(parser.log.chr).to be(1) end end - context "when field_118 is no ie 2" do - let(:attributes) { { bulk_upload:, field_118: 2 } } + context "when field_114 is no ie 2" do + let(:attributes) { { bulk_upload:, field_114: 2 } } it "sets value to 0" do expect(parser.log.chr).to be(0) @@ -2018,16 +1702,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#cap" do - context "when field_117 is yes ie 1" do - let(:attributes) { { bulk_upload:, field_117: 1 } } + context "when field_113 is yes ie 1" do + let(:attributes) { { bulk_upload:, field_113: 1 } } it "sets value to 1" do expect(parser.log.cap).to be(1) end end - context "when field_117 is no ie 2" do - let(:attributes) { { bulk_upload:, field_117: 2 } } + context "when field_113 is no ie 2" do + let(:attributes) { { bulk_upload:, field_113: 2 } } it "sets value to 0" do expect(parser.log.cap).to be(0) @@ -2036,16 +1720,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#letting_allocation_unknown" do - context "when field_116, 117, 118 are no ie 2" do - let(:attributes) { { bulk_upload:, field_116: 2, field_117: 2, field_118: 2 } } + context "when field_112, 117, 118 are no ie 2" do + let(:attributes) { { bulk_upload:, field_112: 2, field_113: 2, field_114: 2 } } it "sets value to 1" do expect(parser.log.letting_allocation_unknown).to be(1) end end - context "when any one of field_116, 117, 118 is yes ie 1" do - let(:attributes) { { bulk_upload:, field_116: 1 } } + context "when any one of field_112, 117, 118 is yes ie 1" do + let(:attributes) { { bulk_upload:, field_112: 1 } } it "sets value to 0" do expect(parser.log.letting_allocation_unknown).to be(0) @@ -2054,8 +1738,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#renewal" do - context "when field_6 is no ie 2" do - let(:attributes) { { bulk_upload:, field_6: 2 } } + context "when field_7 is no ie 2" do + let(:attributes) { { bulk_upload:, field_7: 2 } } it "sets value to 0" do expect(parser.log.renewal).to eq(0) @@ -2067,14 +1751,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) do { bulk_upload:, - field_47: "F", - field_53: "M", - field_57: "X", - field_61: "R", - field_65: "F", - field_69: "M", - field_73: "X", - field_77: "R", + field_43: "F", + field_49: "M", + field_53: "X", + field_57: "R", + field_61: "F", + field_65: "M", + field_69: "X", + field_73: "R", } end @@ -2094,14 +1778,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) do { bulk_upload:, - field_50: "1", - field_54: "2", - field_58: "6", - field_62: "7", - field_66: "8", - field_70: "9", - field_74: "0", - field_78: "10", + field_46: "1", + field_50: "2", + field_54: "6", + field_58: "7", + field_62: "8", + field_66: "9", + field_70: "0", + field_74: "10", } end @@ -2121,13 +1805,13 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do let(:attributes) do { bulk_upload:, - field_51: "P", - field_55: "C", - field_59: "X", - field_63: "R", - field_67: "P", - field_71: "C", - field_75: "X", + field_47: "P", + field_51: "C", + field_55: "X", + field_59: "R", + field_63: "P", + field_67: "C", + field_71: "X", } end @@ -2144,7 +1828,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#net_income_known" do context "when 1" do - let(:attributes) { { bulk_upload:, field_120: "1" } } + let(:attributes) { { bulk_upload:, field_117: "1" } } it "sets value from correct mapping" do expect(parser.log.net_income_known).to eq(0) @@ -2152,7 +1836,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when 2" do - let(:attributes) { { bulk_upload:, field_120: "2" } } + let(:attributes) { { bulk_upload:, field_117: "2" } } it "sets value from correct mapping" do expect(parser.log.net_income_known).to eq(1) @@ -2160,7 +1844,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when 3" do - let(:attributes) { { bulk_upload:, field_120: "3" } } + let(:attributes) { { bulk_upload:, field_117: "3" } } it "sets value from correct mapping" do expect(parser.log.net_income_known).to eq(2) @@ -2169,7 +1853,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#unitletas" do - let(:attributes) { { bulk_upload:, field_26: "1" } } + let(:attributes) { { bulk_upload:, field_25: "1" } } it "sets value from correct mapping" do expect(parser.log.unitletas).to eq(1) @@ -2177,7 +1861,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#rsnvac" do - let(:attributes) { { bulk_upload:, field_27: "5" } } + let(:attributes) { { bulk_upload:, field_24: "5" } } it "sets value from correct mapping" do expect(parser.log.rsnvac).to eq(5) @@ -2185,7 +1869,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#sheltered" do - let(:attributes) { { bulk_upload:, field_44: "1" } } + let(:attributes) { { bulk_upload:, field_41: "1" } } it "sets value from correct mapping" do expect(parser.log.sheltered).to eq(1) @@ -2194,16 +1878,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "illness fields" do mapping = [ - { attribute: :illness_type_1, field: :field_98 }, - { attribute: :illness_type_2, field: :field_92 }, - { attribute: :illness_type_3, field: :field_95 }, - { attribute: :illness_type_4, field: :field_90 }, - { attribute: :illness_type_5, field: :field_91 }, - { attribute: :illness_type_6, field: :field_93 }, - { attribute: :illness_type_7, field: :field_94 }, - { attribute: :illness_type_8, field: :field_97 }, - { attribute: :illness_type_9, field: :field_96 }, - { attribute: :illness_type_10, field: :field_99 }, + { attribute: :illness_type_1, field: :field_94 }, + { attribute: :illness_type_2, field: :field_88 }, + { attribute: :illness_type_3, field: :field_91 }, + { attribute: :illness_type_4, field: :field_86 }, + { attribute: :illness_type_5, field: :field_87 }, + { attribute: :illness_type_6, field: :field_89 }, + { attribute: :illness_type_7, field: :field_90 }, + { attribute: :illness_type_8, field: :field_93 }, + { attribute: :illness_type_9, field: :field_92 }, + { attribute: :illness_type_10, field: :field_95 }, ] mapping.each do |hash| @@ -2236,7 +1920,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#tenancyother" do - let(:attributes) { { bulk_upload:, field_42: "some other tenancy" } } + let(:attributes) { { bulk_upload:, field_39: "some other tenancy" } } it "sets value to given free text string" do expect(parser.log.tenancyother).to eql("some other tenancy") @@ -2244,7 +1928,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#tenancylength" do - let(:attributes) { { bulk_upload:, field_43: "2" } } + let(:attributes) { { bulk_upload:, field_40: "2" } } it "sets value to given free text string" do expect(parser.log.tenancylength).to eq(2) @@ -2252,7 +1936,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#earnings" do - let(:attributes) { { bulk_upload:, field_122: "104.50" } } + let(:attributes) { { bulk_upload:, field_118: "104.50" } } it "rounds to the nearest whole pound" do expect(parser.log.earnings).to eq(105) @@ -2260,7 +1944,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#reasonother" do - let(:attributes) { { bulk_upload:, field_103: "some other reason" } } + let(:attributes) { { bulk_upload:, field_99: "some other reason" } } it "sets value to given free text string" do expect(parser.log.reasonother).to eql("some other reason") @@ -2268,7 +1952,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#ppcodenk" do - let(:attributes) { { bulk_upload:, field_106: "2" } } + let(:attributes) { { bulk_upload:, field_102: "2" } } it "sets correct value from mapping" do expect(parser.log.ppcodenk).to eq(1) @@ -2277,7 +1961,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#household_charge" do context "when log is general needs" do - let(:attributes) { { bulk_upload:, field_4: 1, field_125: "1" } } + let(:attributes) { { bulk_upload:, field_4: 1, field_122: "1" } } it "sets correct value from mapping" do expect(parser.log.household_charge).to eq(nil) @@ -2285,7 +1969,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when log is supported housing" do - let(:attributes) { { bulk_upload:, field_4: 2, field_125: "1" } } + let(:attributes) { { bulk_upload:, field_4: 2, field_122: "1" } } it "sets correct value from mapping" do expect(parser.log.household_charge).to eq(1) @@ -2294,23 +1978,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#chcharge" do - let(:attributes) { { bulk_upload:, field_127: "123.45" } } + let(:attributes) { { bulk_upload:, field_124: "123.45" } } it "sets value given" do expect(parser.log.chcharge).to eq(123.45) end end - describe "#tcharge" do - let(:attributes) { { bulk_upload:, field_132: "123.45" } } - - it "sets value given" do - expect(parser.log.tcharge).to eq(123.45) - end - end - describe "#supcharg" do - let(:attributes) { { bulk_upload:, field_131: "123.45" } } + let(:attributes) { { bulk_upload:, field_128: "123.45" } } it "sets value given" do expect(parser.log.supcharg).to eq(123.45) @@ -2318,7 +1994,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#pscharge" do - let(:attributes) { { bulk_upload:, field_130: "123.45" } } + let(:attributes) { { bulk_upload:, field_127: "123.45" } } it "sets value given" do expect(parser.log.pscharge).to eq(123.45) @@ -2326,21 +2002,13 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#scharge" do - let(:attributes) { { bulk_upload:, field_129: "123.45" } } + let(:attributes) { { bulk_upload:, field_126: "123.45" } } it "sets value given" do expect(parser.log.scharge).to eq(123.45) end end - describe "#offered" do - let(:attributes) { { bulk_upload:, field_28: "3" } } - - it "sets value given" do - expect(parser.log.offered).to eq(3) - end - end - describe "#propcode" do let(:attributes) { { bulk_upload:, field_14: "abc123" } } @@ -2351,7 +2019,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#mrcdate" do context "when valid" do - let(:attributes) { { bulk_upload:, field_36: "13", field_37: "12", field_38: "22" } } + let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "22" } } it "sets value given" do expect(parser.log.mrcdate).to eq(Date.new(2022, 12, 13)) @@ -2359,7 +2027,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when invalid" do - let(:attributes) { { bulk_upload:, field_36: "13", field_37: "13", field_38: "22" } } + let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } } it "does not raise an error" do expect { parser.log.mrcdate }.not_to raise_error @@ -2369,7 +2037,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#majorrepairs" do context "when mrcdate given" do - let(:attributes) { { bulk_upload:, field_36: "13", field_37: "12", field_38: "22" } } + let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "22" } } it "sets #majorrepairs to 1" do expect(parser.log.majorrepairs).to eq(1) @@ -2377,7 +2045,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when mrcdate not given" do - let(:attributes) { { bulk_upload:, field_36: "", field_37: "", field_38: "", field_4: 1 } } + let(:attributes) { { bulk_upload:, field_33: "", field_34: "", field_35: "", field_4: 1 } } it "sets #majorrepairs to 0" do expect(parser.log.majorrepairs).to eq(0) @@ -2387,7 +2055,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#voiddate" do context "when valid" do - let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "22" } } + let(:attributes) { { bulk_upload:, field_30: "13", field_31: "12", field_32: "22" } } it "sets value given" do expect(parser.log.voiddate).to eq(Date.new(2022, 12, 13)) @@ -2395,7 +2063,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when invalid" do - let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } } + let(:attributes) { { bulk_upload:, field_30: "13", field_31: "13", field_32: "22" } } it "does not raise an error" do expect { parser.log.voiddate }.not_to raise_error @@ -2404,7 +2072,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#startdate" do - let(:attributes) { { bulk_upload:, field_7: now.day.to_s, field_8: now.month.to_s, field_9: now.strftime("%g") } } + let(:attributes) { { bulk_upload:, field_8: now.day.to_s, field_9: now.month.to_s, field_10: now.strftime("%g") } } it "sets value given" do expect(parser.log.startdate).to eq(now) @@ -2412,7 +2080,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#postcode_full" do - let(:attributes) { { bulk_upload:, field_23: " EC1N ", field_24: " 2TD " } } + let(:attributes) { { bulk_upload:, field_21: " EC1N ", field_22: " 2TD " } } it "strips whitespace" do expect(parser.log.postcode_full).to eql("EC1N 2TD") @@ -2420,7 +2088,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#la" do - let(:attributes) { { bulk_upload:, field_25: "E07000223" } } + let(:attributes) { { bulk_upload:, field_23: "E07000223" } } it "sets to given value" do expect(parser.log.la).to eql("E07000223") @@ -2428,7 +2096,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#prevloc" do - let(:attributes) { { bulk_upload:, field_109: "E07000223" } } + let(:attributes) { { bulk_upload:, field_105: "E07000223" } } it "sets to given value" do expect(parser.log.prevloc).to eql("E07000223") @@ -2437,7 +2105,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#previous_la_known" do context "when known" do - let(:attributes) { { bulk_upload:, field_109: "E07000223" } } + let(:attributes) { { bulk_upload:, field_105: "E07000223" } } it "sets to 1" do expect(parser.log.previous_la_known).to eq(1) @@ -2445,7 +2113,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when not known" do - let(:attributes) { { bulk_upload:, field_109: "", field_4: 1 } } + let(:attributes) { { bulk_upload:, field_105: "", field_4: 1 } } it "sets to 0" do expect(parser.log.previous_la_known).to eq(0) @@ -2454,16 +2122,16 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#first_time_property_let_as_social_housing" do - context "when field_27 is 15, 16, or 17" do - let(:attributes) { { bulk_upload:, field_27: %w[15 16 17].sample } } + context "when field_24 is 15, 16, or 17" do + let(:attributes) { { bulk_upload:, field_24: %w[15 16 17].sample } } it "sets to 1" do expect(parser.log.first_time_property_let_as_social_housing).to eq(1) end end - context "when field_27 is not 15, 16, or 17" do - let(:attributes) { { bulk_upload:, field_27: "1" } } + context "when field_24 is not 15, 16, or 17" do + let(:attributes) { { bulk_upload:, field_24: "1" } } it "sets to 0" do expect(parser.log.first_time_property_let_as_social_housing).to eq(0) @@ -2473,7 +2141,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#housingneeds" do context "when no disabled needs" do - let(:attributes) { { bulk_upload:, field_87: "1" } } + let(:attributes) { { bulk_upload:, field_83: "1" } } it "sets to 2" do expect(parser.log.housingneeds).to eq(2) @@ -2481,7 +2149,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when dont know about disabled needs" do - let(:attributes) { { bulk_upload:, field_88: "1" } } + let(:attributes) { { bulk_upload:, field_84: "1" } } it "sets to 3" do expect(parser.log.housingneeds).to eq(3) @@ -2489,7 +2157,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when housingneeds are given" do - let(:attributes) { { bulk_upload:, field_87: "0", field_85: "1", field_86: "1" } } + let(:attributes) { { bulk_upload:, field_83: "0", field_81: "1", field_82: "1" } } it "sets correct housingneeds" do expect(parser.log.housingneeds).to eq(1) @@ -2498,8 +2166,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when housingneeds are given and field_86 is nil" do - let(:attributes) { { bulk_upload:, field_87: nil, field_85: "1", field_86: "1" } } + context "when housingneeds are given and field_82 is nil" do + let(:attributes) { { bulk_upload:, field_83: nil, field_81: "1", field_82: "1" } } it "sets correct housingneeds" do expect(parser.log.housingneeds).to eq(1) @@ -2509,7 +2177,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when housingneeds are not given" do - let(:attributes) { { bulk_upload:, field_83: nil, field_84: nil, field_85: nil, field_87: nil } } + let(:attributes) { { bulk_upload:, field_79: nil, field_80: nil, field_81: nil, field_83: nil } } it "sets correct housingneeds" do expect(parser.log.housingneeds).to eq(1) @@ -2518,106 +2186,106 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end context "when housingneeds a and b are selected" do - let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1", field_80: "1" } } it "sets error on housingneeds a and b" do parser.valid? - expect(parser.errors[:field_83]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_84]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_79]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_80]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_81]).to be_blank end end context "when housingneeds a and c are selected" do - let(:attributes) { { bulk_upload:, field_83: "1", field_85: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1", field_81: "1" } } it "sets error on housingneeds a and c" do parser.valid? - expect(parser.errors[:field_83]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_85]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_84]).to be_blank + expect(parser.errors[:field_79]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_81]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_80]).to be_blank end end context "when housingneeds b and c are selected" do - let(:attributes) { { bulk_upload:, field_84: "1", field_85: "1" } } + let(:attributes) { { bulk_upload:, field_80: "1", field_81: "1" } } it "sets error on housingneeds b and c" do parser.valid? - expect(parser.errors[:field_84]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_85]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") - expect(parser.errors[:field_83]).to be_blank + expect(parser.errors[:field_80]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_81]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected") + expect(parser.errors[:field_79]).to be_blank end end context "when housingneeds a and g are selected" do - let(:attributes) { { bulk_upload:, field_83: "1", field_87: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1", field_83: "1" } } it "sets error on housingneeds a and g" do parser.valid? - expect(parser.errors[:field_87]).to include("No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") expect(parser.errors[:field_83]).to include("No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") - expect(parser.errors[:field_84]).to be_blank - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_79]).to include("No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") + expect(parser.errors[:field_80]).to be_blank + expect(parser.errors[:field_81]).to be_blank end end context "when only housingneeds g is selected" do - let(:attributes) { { bulk_upload:, field_83: "0", field_87: "1" } } + let(:attributes) { { bulk_upload:, field_79: "0", field_83: "1" } } it "does not add any housingneeds errors" do parser.valid? - expect(parser.errors[:field_59]).to be_blank - expect(parser.errors[:field_83]).to be_blank - expect(parser.errors[:field_84]).to be_blank - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_55]).to be_blank + expect(parser.errors[:field_79]).to be_blank + expect(parser.errors[:field_80]).to be_blank + expect(parser.errors[:field_81]).to be_blank end end context "when housingneeds a and h are selected" do - let(:attributes) { { bulk_upload:, field_83: "1", field_88: "1" } } + let(:attributes) { { bulk_upload:, field_79: "1", field_84: "1" } } it "sets error on housingneeds a and h" do parser.valid? - expect(parser.errors[:field_88]).to include("Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") - expect(parser.errors[:field_83]).to include("Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") - expect(parser.errors[:field_84]).to be_blank - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_84]).to include("Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") + expect(parser.errors[:field_79]).to include("Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs") + expect(parser.errors[:field_80]).to be_blank + expect(parser.errors[:field_81]).to be_blank end end context "when only housingneeds h is selected" do - let(:attributes) { { bulk_upload:, field_83: "0", field_88: "1" } } + let(:attributes) { { bulk_upload:, field_79: "0", field_84: "1" } } it "does not add any housingneeds errors" do parser.valid? - expect(parser.errors[:field_88]).to be_blank - expect(parser.errors[:field_83]).to be_blank expect(parser.errors[:field_84]).to be_blank - expect(parser.errors[:field_85]).to be_blank + expect(parser.errors[:field_79]).to be_blank + expect(parser.errors[:field_80]).to be_blank + expect(parser.errors[:field_81]).to be_blank end end end describe "#housingneeds_type" do - context "when field_83 is 1" do - let(:attributes) { { bulk_upload:, field_83: "1" } } + context "when field_79 is 1" do + let(:attributes) { { bulk_upload:, field_79: "1" } } it "set to 0" do expect(parser.log.housingneeds_type).to eq(0) end end - context "when field_84 is 1" do - let(:attributes) { { bulk_upload:, field_84: "1" } } + context "when field_80 is 1" do + let(:attributes) { { bulk_upload:, field_80: "1" } } it "set to 1" do expect(parser.log.housingneeds_type).to eq(1) end end - context "when field_85 is 1" do - let(:attributes) { { bulk_upload:, field_85: "1" } } + context "when field_81 is 1" do + let(:attributes) { { bulk_upload:, field_81: "1" } } it "set to 2" do expect(parser.log.housingneeds_type).to eq(2) @@ -2626,8 +2294,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#housingneeds_other" do - context "when field_58 is 1" do - let(:attributes) { { bulk_upload:, field_86: "1" } } + context "when field_54 is 1" do + let(:attributes) { { bulk_upload:, field_82: "1" } } it "sets to 1" do expect(parser.log.housingneeds_other).to eq(1) @@ -2638,7 +2306,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do describe "#start_date" do context "when year of 9 is passed to represent 2009" do - let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "9" } } + let(:attributes) { { bulk_upload:, field_8: "1", field_9: "1", field_10: "9" } } it "uses the year 2009" do expect(parser.send(:start_date)).to eql(Date.new(2009, 1, 1)) diff --git a/spec/support/bulk_upload/lettings_log_to_csv.rb b/spec/support/bulk_upload/lettings_log_to_csv.rb index 13dc7c738..4aaca922f 100644 --- a/spec/support/bulk_upload/lettings_log_to_csv.rb +++ b/spec/support/bulk_upload/lettings_log_to_csv.rb @@ -42,6 +42,15 @@ class BulkUpload::LettingsLogToCsv end end + def to_2024_csv_row(seed: nil) + if seed + row = to_2024_row.shuffle(random: Random.new(seed)) + (row_prefix + row).flatten.join(",") + line_ending + else + (row_prefix + to_2024_row).flatten.join(",") + line_ending + end + end + def to_2023_row to_2022_row + [ log.needstype, @@ -62,10 +71,169 @@ class BulkUpload::LettingsLogToCsv end.flatten.join(",") + line_ending end + def default_2024_field_numbers_row(seed: nil) + if seed + ["Bulk upload field number"] + default_2024_field_numbers.shuffle(random: Random.new(seed)) + else + ["Bulk upload field number"] + default_2024_field_numbers + end.flatten.join(",") + line_ending + end + def default_2023_field_numbers [5, nil, nil, 15, 16, nil, 13, 40, 41, 42, 43, 46, 52, 56, 60, 64, 68, 72, 76, 47, 53, 57, 61, 65, 69, 73, 77, 51, 55, 59, 63, 67, 71, 75, 50, 54, 58, 62, 66, 70, 74, 78, 48, 49, 79, 81, 82, 123, 124, 122, 120, 102, 103, nil, 83, 84, 85, 86, 87, 88, 104, 109, 107, 108, 106, 100, 101, 105, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 126, 128, 129, 130, 131, 132, 127, 125, 133, 134, 33, 34, 35, 36, 37, 38, nil, 7, 8, 9, 28, 14, 32, 29, 30, 31, 26, 27, 25, 23, 24, nil, 1, 3, 2, 80, nil, 121, 44, 89, 98, 92, 95, 90, 91, 93, 94, 97, 96, 99, 10, 11, 12, 45, 39, 6, 4, 17, 18, 19, 20, 21, 22] end + def default_2024_field_numbers + (1..130).to_a + end + + def to_2024_row + [ + log.owning_organisation&.old_visible_id, # 1 + log.managing_organisation&.old_visible_id, + log.created_by&.email, + log.needstype, + "S#{log.scheme&.id}", + log.location&.id, + renewal, + log.startdate&.day, + log.startdate&.month, + log.startdate&.strftime("%y"), # 10 + + london_affordable_rent, + log.irproduct_other, + log.tenancycode, + log.propcode, + log.declaration, + log.uprn, + log.address_line1, + log.address_line2, + log.town_or_city, + log.county, # 20 + + ((log.postcode_full || "").split(" ") || [""]).first, + ((log.postcode_full || "").split(" ") || [""]).last, + log.la, + log.rsnvac, + log.unitletas, + log.unittype_gn, + log.builtype, + log.wchair, + log.beds, + log.voiddate&.day, # 30 + + log.voiddate&.month, + log.voiddate&.strftime("%y"), + log.mrcdate&.day, + log.mrcdate&.month, + log.mrcdate&.strftime("%y"), + log.joint, + log.startertenancy, + log.tenancy, + log.tenancyother, + log.tenancylength, # 40 + + log.sheltered, + log.age1 || overrides[:age1], + log.sex1, + log.ethnic, + log.national, + log.ecstat1, + log.relat2, + log.age2 || overrides[:age2], + log.sex2, + log.ecstat2, # 50 + + log.relat3, + log.age3 || overrides[:age3], + log.sex3, + log.ecstat3, + log.relat4, + log.age4 || overrides[:age4], + log.sex4, + log.ecstat4, + log.relat5, + log.age5 || overrides[:age5], # 60 + + log.sex5, + log.ecstat5, + log.relat6, + log.age6 || overrides[:age6], + log.sex6, + log.ecstat6, + log.relat7, + log.age7 || overrides[:age7], + log.sex7, + log.ecstat7, # 70 + + log.relat8, + log.age8 || overrides[:age8], + log.sex8, + log.ecstat8, + log.armedforces, + log.leftreg, + log.reservist, + log.preg_occ, + log.housingneeds_a, + log.housingneeds_b, # 80 + + log.housingneeds_c, + log.housingneeds_f, + log.housingneeds_g, + log.housingneeds_h, + overrides[:illness] || log.illness, + log.illness_type_1, + log.illness_type_2, + log.illness_type_3, + log.illness_type_4, + log.illness_type_5, # 90 + + log.illness_type_6, + log.illness_type_7, + log.illness_type_8, + log.illness_type_9, + log.illness_type_10, + log.layear, + log.waityear, + log.reason, + log.reasonother, + log.prevten, # 100 + + homeless, + previous_postcode_known, + ((log.ppostcode_full || "").split(" ") || [""]).first, + ((log.ppostcode_full || "").split(" ") || [""]).last, + log.prevloc, + log.reasonpref, + log.rp_homeless, + log.rp_insan_unsat, + log.rp_medwel, + log.rp_hardship, # 110 + + log.rp_dontknow, + cbl, + chr, + cap, + nil, # accessible register + log.referral, + net_income_known, + log.earnings, + log.incfreq, + log.hb, # 120 + + log.benefits, + log.household_charge, + log.period, + log.chcharge, + log.brent, + log.scharge, + log.pscharge, + log.supcharg, + log.hbrentshortfall, + log.tshortfall, # 130 + ] + end + def to_2022_row [ log.renttype, # 1