Browse Source

CLDC-1304: Export changes needed by CDS (#650)

pull/682/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
4fa32a1619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/bulk_upload.rb
  2. 131
      app/models/case_log.rb
  3. 172
      app/models/derived_variables/case_log_variables.rb
  4. 2
      app/models/form.rb
  5. 12
      app/models/form/question.rb
  6. 19
      app/models/validations/financial_validations.rb
  7. 4
      app/services/exports/case_log_export_constants.rb
  8. 2
      app/services/exports/case_log_export_service.rb
  9. 8
      app/services/imports/case_logs_field_import_service.rb
  10. 4
      app/services/imports/case_logs_import_service.rb
  11. 2
      app/views/case_logs/_log_list.html.erb
  12. 129
      config/forms/2021_2022.json
  13. 16
      config/forms/2022_2023.json
  14. 0
      config/forms/setup/log_setup.json
  15. 13
      db/migrate/20220613123730_add_export_fields.rb
  16. 10
      db/schema.rb
  17. 9
      spec/factories/case_log.rb
  18. 10
      spec/features/form/check_answers_page_spec.rb
  19. 6
      spec/features/form/form_navigation_spec.rb
  20. 2
      spec/features/form/saving_data_spec.rb
  21. 2
      spec/features/form/tasklist_page_spec.rb
  22. 5
      spec/fixtures/complete_case_log.json
  23. 4
      spec/fixtures/exports/case_logs.csv
  24. 9
      spec/fixtures/exports/case_logs.xml
  25. 22
      spec/fixtures/forms/2021_2022.json
  26. 2
      spec/fixtures/forms/2022_2023.json
  27. 8
      spec/helpers/tasklist_helper_spec.rb
  28. 24
      spec/models/case_log_spec.rb
  29. 4
      spec/models/form/subsection_spec.rb
  30. 2
      spec/models/form_handler_spec.rb
  31. 6
      spec/models/form_spec.rb
  32. 5
      spec/models/validations/financial_validations_spec.rb
  33. 6
      spec/models/validations/local_authority_validations_spec.rb
  34. 34
      spec/requests/case_logs_controller_spec.rb
  35. 6
      spec/requests/form_controller_spec.rb
  36. 2
      spec/requests/organisations_controller_spec.rb
  37. 3
      spec/requests/schemes_controller_spec.rb
  38. 4
      spec/services/exports/case_log_export_service_spec.rb
  39. 12
      spec/services/imports/case_logs_field_import_service_spec.rb

2
app/models/bulk_upload.rb

@ -62,7 +62,7 @@ class BulkUpload
# managementgroup: row[4], # managementgroup: row[4],
# schemecode: row[5], # schemecode: row[5],
# firstletting: row[6], # firstletting: row[6],
tenant_code: row[7], tenancycode: row[7],
startertenancy: row[8], startertenancy: row[8],
tenancy: row[9], tenancy: row[9],
tenancyother: row[10], tenancyother: row[10],

131
app/models/case_log.rb

@ -18,6 +18,7 @@ end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
include Validations::SoftValidations include Validations::SoftValidations
include DerivedVariables::CaseLogVariables
has_paper_trail has_paper_trail
@ -52,7 +53,7 @@ class CaseLog < ApplicationRecord
} }
scope :filter_by_id, ->(id) { where(id:) } scope :filter_by_id, ->(id) { where(id:) }
scope :filter_by_tenant_code, ->(tenant_code) { where("tenant_code ILIKE ?", "%#{tenant_code}%") } scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") }
scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") }
scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") } scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") }
scope :search_by, lambda { |param| scope :search_by, lambda { |param|
@ -63,8 +64,7 @@ class CaseLog < ApplicationRecord
} }
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenant_code propcode].freeze OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
@ -112,10 +112,6 @@ class CaseLog < ApplicationRecord
status == "in_progress" status == "in_progress"
end end
def supported_housing_schemes_enabled?
FeatureToggle.supported_housing_schemes_enabled?
end
def weekly_net_income def weekly_net_income
return unless earnings && incfreq return unless earnings && incfreq
@ -201,7 +197,7 @@ class CaseLog < ApplicationRecord
def previous_postcode_known? def previous_postcode_known?
# 1: Yes # 1: Yes
previous_postcode_known == 1 ppcodenk == 1
end end
def previous_la_known? def previous_la_known?
@ -266,10 +262,12 @@ class CaseLog < ApplicationRecord
def previous_tenancy_was_temporary? def previous_tenancy_was_temporary?
# 4: Tied housing or renting with job # 4: Tied housing or renting with job
# 6: Supported housing # 6: Supported housing
# 8: Sheltered accomodation # 8: Sheltered accomodation (<= 21/22)
# 24: Housed by National Asylum Support Service (prev Home Office) # 24: Housed by National Asylum Support Service (prev Home Office)
# 25: Other # 25: Other
![4, 6, 8, 24, 25].include?(prevten) # 34: Specialist retirement housing
# 35: Extra care housing
![4, 6, 8, 24, 25, 34, 35].include?(prevten)
end end
def armed_forces_regular? def armed_forces_regular?
@ -302,11 +300,6 @@ class CaseLog < ApplicationRecord
homeless == 11 homeless == 11
end end
def is_other_homeless?
# 7: Other homeless – not found statutorily homeless but considered homeless by landlord
homeless == 7
end
def is_not_homeless? def is_not_homeless?
# 1: No # 1: No
homeless == 1 homeless == 1
@ -338,6 +331,11 @@ class CaseLog < ApplicationRecord
hb == 1 hb == 1
end end
def benefits_unknown?
hb == 3
end
# Option 8 has been removed starting from 22/23
def receives_housing_benefit_and_universal_credit? def receives_housing_benefit_and_universal_credit?
# 8: Housing benefit and Universal Credit (without housing element) # 8: Housing benefit and Universal Credit (without housing element)
hb == 8 hb == 8
@ -353,6 +351,11 @@ class CaseLog < ApplicationRecord
hb == 9 hb == 9
end end
def tenant_refuses_to_say_benefits?
hb == 10
end
# Option 7 has been removed starting from 22/23
def receives_universal_credit_but_no_housing_benefit? def receives_universal_credit_but_no_housing_benefit?
# 7: Universal Credit (without housing element) # 7: Universal Credit (without housing element)
hb == 7 hb == 7
@ -363,13 +366,12 @@ class CaseLog < ApplicationRecord
end end
def receives_housing_related_benefits? def receives_housing_related_benefits?
receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? || if collection_start_year <= 2021
receives_housing_benefit_and_universal_credit? receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? ||
end receives_housing_benefit_and_universal_credit?
else
def benefits_unknown? receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit?
# 3: Don’t know end
hb == 3
end end
def local_housing_referral? def local_housing_referral?
@ -522,64 +524,6 @@ private
collection_start_year >= 2022 && !is_fixed_term_tenancy? collection_start_year >= 2022 && !is_fixed_term_tenancy?
end end
def set_derived_fields!
# TODO: Remove once we support supported housing logs
self.needstype = 1 unless FeatureToggle.supported_housing_schemes_enabled?
if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end
self.incref = 1 if net_income_refused?
self.renttype = RENT_TYPE_MAPPING[rent_type]
self.lettype = get_lettype
self.totchild = get_totchild
self.totelder = get_totelder
self.totadult = get_totadult
self.refused = get_refused
self.ethnic = 17 if ethnic_refused?
if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? }
self.brent ||= 0
self.scharge ||= 0
self.pscharge ||= 0
self.supcharg ||= 0
self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f
end
if period.present?
self.wrent = weekly_value(brent) if brent.present?
self.wscharge = weekly_value(scharge) if scharge.present?
self.wpschrge = weekly_value(pscharge) if pscharge.present?
self.wsupchrg = weekly_value(supcharg) if supcharg.present?
self.wtcharge = weekly_value(tcharge) if tcharge.present?
if is_supported_housing? && chcharge.present?
self.wchchrg = weekly_value(chcharge)
end
end
self.has_benefits = get_has_benefits
self.tshortfall_known = 0 if tshortfall
self.wtshortfall = if tshortfall && receives_housing_related_benefits?
weekly_value(tshortfall)
end
self.nocharge = household_charge&.zero? ? 1 : 0
self.housingneeds = get_housingneeds
if is_renewal?
self.underoccupation_benefitcap = 2 if collection_start_year == 2021
self.homeless = 2
self.referral = 0
self.waityear = 1
if is_general_needs?
# fixed term
self.prevten = 32 if managing_organisation.provider_type == "PRP"
self.prevten = 30 if managing_organisation.provider_type == "LA"
end
end
(2..8).each do |idx|
if age_under_16?(idx)
self["ecstat#{idx}"] = 9
elsif public_send("ecstat#{idx}") == 9 && age_known?(idx)
self["ecstat#{idx}"] = nil
end
end
end
def age_under_16?(person_num) def age_under_16?(person_num)
public_send("age#{person_num}") && public_send("age#{person_num}") < 16 public_send("age#{person_num}") && public_send("age#{person_num}") < 16
end end
@ -591,7 +535,7 @@ private
def process_previous_postcode_changes! def process_previous_postcode_changes!
self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full) self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full)
process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc") process_postcode(ppostcode_full, "ppcodenk", "is_previous_la_inferred", "prevloc")
end end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key) def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)
@ -619,31 +563,6 @@ private
self[postcode_key] = nil self[postcode_key] = nil
end end
def get_totelder
ages = [age1, age2, age3, age4, age5, age6, age7, age8]
ages.count { |x| !x.nil? && x >= 60 }
end
def get_totchild
relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8]
relationships.count("C")
end
def get_totadult
total = !age1.nil? && age1 >= 16 && age1 < 60 ? 1 : 0
total + (2..8).count do |i|
age = public_send("age#{i}")
relat = public_send("relat#{i}")
!age.nil? && ((age >= 16 && age < 18 && %w[P X].include?(relat)) || age >= 18 && age < 60)
end
end
def get_refused
return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused?
0
end
def get_inferred_la(postcode) def get_inferred_la(postcode)
# Avoid network calls when postcode is invalid # Avoid network calls when postcode is invalid
return unless postcode.match(Validations::PropertyValidations::POSTCODE_REGEXP) return unless postcode.match(Validations::PropertyValidations::POSTCODE_REGEXP)

172
app/models/derived_variables/case_log_variables.rb

@ -0,0 +1,172 @@
module DerivedVariables::CaseLogVariables
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze
def supported_housing_schemes_enabled?
FeatureToggle.supported_housing_schemes_enabled?
end
def set_derived_fields!
# TODO: Remove once we support supported housing logs
self.needstype = 1 unless supported_housing_schemes_enabled?
if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end
self.incref = 1 if net_income_refused?
self.renttype = RENT_TYPE_MAPPING[rent_type]
self.lettype = get_lettype
self.totchild = get_totchild
self.totelder = get_totelder
self.totadult = get_totadult
self.refused = get_refused
self.ethnic = 17 if ethnic_refused?
if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? }
self.brent ||= 0
self.scharge ||= 0
self.pscharge ||= 0
self.supcharg ||= 0
self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f
end
if period.present?
self.wrent = weekly_value(brent) if brent.present?
self.wscharge = weekly_value(scharge) if scharge.present?
self.wpschrge = weekly_value(pscharge) if pscharge.present?
self.wsupchrg = weekly_value(supcharg) if supcharg.present?
self.wtcharge = weekly_value(tcharge) if tcharge.present?
if is_supported_housing? && chcharge.present?
self.wchchrg = weekly_value(chcharge)
end
end
self.has_benefits = get_has_benefits
self.tshortfall_known = 0 if tshortfall
self.wtshortfall = if tshortfall && receives_housing_related_benefits?
weekly_value(tshortfall)
end
self.nocharge = household_charge&.zero? ? 1 : 0
self.housingneeds = get_housingneeds
if is_renewal?
self.underoccupation_benefitcap = 2 if collection_start_year == 2021
self.homeless = 1
self.referral = 0
self.waityear = 2
if is_general_needs?
# fixed term
self.prevten = 32 if managing_organisation.provider_type == "PRP"
self.prevten = 30 if managing_organisation.provider_type == "LA"
end
end
child_under_16_constraints!
self.hhtype = household_type
self.new_old = new_or_existing_tenant
self.vacdays = property_vacant_days
end
private
def get_totelder
ages = [age1, age2, age3, age4, age5, age6, age7, age8]
ages.count { |x| !x.nil? && x >= 60 }
end
def get_totchild
relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8]
relationships.count("C")
end
def get_totadult
total = !age1.nil? && age1 >= 16 && age1 < 60 ? 1 : 0
total + (2..8).count do |i|
age = public_send("age#{i}")
relat = public_send("relat#{i}")
!age.nil? && ((age >= 16 && age < 18 && %w[P X].include?(relat)) || age >= 18 && age < 60)
end
end
def get_refused
return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused?
0
end
def child_under_16_constraints!
(2..8).each do |idx|
if age_under_16?(idx)
self["ecstat#{idx}"] = 9
elsif public_send("ecstat#{idx}") == 9 && age_known?(idx)
self["ecstat#{idx}"] = nil
end
end
end
def household_type
return unless totelder && totadult && totchild
if only_one_elder?
1
elsif two_adults_including_elders?
2
elsif only_one_adult?
3
elsif only_two_adults?
4
elsif one_adult_with_at_least_one_child?
5
elsif two_adults_with_at_least_one_child?
6
else
9
end
end
def two_adults_with_at_least_one_child?
totelder.zero? && totadult >= 2 && totchild >= 1
end
def one_adult_with_at_least_one_child?
totelder.zero? && totadult == 1 && totchild >= 1
end
def only_two_adults?
totelder.zero? && totadult == 2 && totchild.zero?
end
def only_one_adult?
totelder.zero? && totadult == 1 && totchild.zero?
end
def two_adults_including_elders?
(totelder + totadult) == 2 && totelder >= 1
end
def only_one_elder?
totelder == 1 && totadult.zero? && totchild.zero?
end
def new_or_existing_tenant
return unless startdate
referral_within_sector = [1, 10]
previous_social_tenancies = if collection_start_year <= 2021
[6, 8, 30, 31, 32, 33]
else
[6, 30, 31, 32, 33, 34, 35]
end
if previous_social_tenancies.include?(prevten) || referral_within_sector.include?(referral)
2 # Tenant existing in social housing sector
else
1 # Tenant new to social housing sector
end
end
def property_vacant_days
return unless startdate
if mrcdate.present?
(startdate - mrcdate).to_i / 1.day
elsif voiddate.present?
(startdate - voiddate).to_i / 1.day
end
end
end

2
app/models/form.rb

@ -124,7 +124,7 @@ class Form
def invalidated_page_questions(case_log) def invalidated_page_questions(case_log)
# we're already treating address fields as a special case and reset their values upon saving a case_log # we're already treating address fields as a special case and reset their values upon saving a case_log
address_questions = %w[postcode_known la previous_postcode_known previous_la_known prevloc postcode_full ppostcode_full] address_questions = %w[postcode_known la ppcodenk previous_la_known prevloc postcode_full ppostcode_full]
invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || [] invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || []
end end

12
app/models/form/question.rb

@ -237,13 +237,13 @@ private
RADIO_YES_VALUE = { RADIO_YES_VALUE = {
renewal: [1], renewal: [1],
postcode_known: [1], postcode_known: [1],
previous_postcode_known: [1], ppcodenk: [1],
previous_la_known: [1], previous_la_known: [1],
first_time_property_let_as_social_housing: [1], first_time_property_let_as_social_housing: [1],
wchair: [1], wchair: [1],
majorrepairs: [1], majorrepairs: [1],
startertenancy: [0], startertenancy: [0],
shelteredaccom: [0, 1], sheltered: [0, 1],
armedforces: [1, 4, 5], armedforces: [1, 4, 5],
leftreg: [0], leftreg: [0],
reservist: [0], reservist: [0],
@ -261,13 +261,13 @@ private
RADIO_NO_VALUE = { RADIO_NO_VALUE = {
renewal: [0], renewal: [0],
postcode_known: [0], postcode_known: [0],
previous_postcode_known: [0], ppcodenk: [0],
previous_la_known: [0], previous_la_known: [0],
first_time_property_let_as_social_housing: [0], first_time_property_let_as_social_housing: [0],
wchair: [0], wchair: [0],
majorrepairs: [0], majorrepairs: [0],
startertenancy: [1], startertenancy: [1],
shelteredaccom: [2], sheltered: [2],
armedforces: [2], armedforces: [2],
leftreg: [1], leftreg: [1],
reservist: [1], reservist: [1],
@ -283,7 +283,7 @@ private
}.freeze }.freeze
RADIO_DONT_KNOW_VALUE = { RADIO_DONT_KNOW_VALUE = {
shelteredaccom: [3], sheltered: [3],
underoccupation_benefitcap: [3], underoccupation_benefitcap: [3],
reasonpref: [3], reasonpref: [3],
hbrentshortfall: [3], hbrentshortfall: [3],
@ -319,7 +319,7 @@ private
ecstat6: [10], ecstat6: [10],
ecstat7: [10], ecstat7: [10],
ecstat8: [10], ecstat8: [10],
shelteredaccom: [3], sheltered: [3],
armedforces: [3], armedforces: [3],
leftreg: [3], leftreg: [3],
reservist: [2], reservist: [2],

19
app/models/validations/financial_validations.rb

@ -51,14 +51,25 @@ module Validations::FinancialValidations
end end
def validate_tshortfall(record) def validate_tshortfall(record)
if record.has_hbrentshortfall? && if record.has_hbrentshortfall? && no_known_benefits?(record)
(record.benefits_unknown? ||
record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?)
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end end
end end
def no_known_benefits?(record)
return true unless record.collection_start_year
if record.collection_start_year <= 2021
record.benefits_unknown? ||
record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?
else
record.benefits_unknown? ||
record.receives_no_benefits? ||
record.tenant_refuses_to_say_benefits?
end
end
def validate_rent_amount(record) def validate_rent_amount(record)
if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2 if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2
record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2) record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2)

4
app/services/exports/case_log_export_constants.rb

@ -36,6 +36,7 @@ module Exports::CaseLogExportConstants
"hbrentshortfall", "hbrentshortfall",
"hcnum", "hcnum",
"hhmemb", "hhmemb",
"hhtype",
"homeless", "homeless",
"housingneeds", "housingneeds",
"illness", "illness",
@ -92,7 +93,7 @@ module Exports::CaseLogExportConstants
"scharge", "scharge",
"scheme", "scheme",
"schtype", "schtype",
"shelteredaccom", "sheltered",
"startdate", "startdate",
"startertenancy", "startertenancy",
"supcharg", "supcharg",
@ -114,6 +115,7 @@ module Exports::CaseLogExportConstants
"unittype_sh", "unittype_sh",
"uploaddate", "uploaddate",
"username", "username",
"vacdays",
"voiddate", "voiddate",
"waityear", "waityear",
"wchair", "wchair",

2
app/services/exports/case_log_export_service.rb

@ -179,8 +179,6 @@ module Exports
# Mapping which would require a change in our data model # Mapping which would require a change in our data model
attribute_hash["createddate"] = attribute_hash["created_at"] attribute_hash["createddate"] = attribute_hash["created_at"]
attribute_hash["uploaddate"] = attribute_hash["updated_at"] attribute_hash["uploaddate"] = attribute_hash["updated_at"]
attribute_hash["tenancycode"] = attribute_hash["tenant_code"]
attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"]
attribute_hash["cbl"] = 2 if attribute_hash["cbl"]&.zero? attribute_hash["cbl"] = 2 if attribute_hash["cbl"]&.zero?
attribute_hash["cap"] = 2 if attribute_hash["cap"]&.zero? attribute_hash["cap"] = 2 if attribute_hash["cap"]&.zero?

8
app/services/imports/case_logs_field_import_service.rb

@ -2,7 +2,7 @@ module Imports
class CaseLogsFieldImportService < ImportService class CaseLogsFieldImportService < ImportService
def update_field(field, folder) def update_field(field, folder)
case field case field
when "tenant_code" when "tenancycode"
import_from(folder, :update_tenant_code) import_from(folder, :update_tenant_code)
when "major_repairs" when "major_repairs"
import_from(folder, :update_major_repairs) import_from(folder, :update_major_repairs)
@ -74,10 +74,10 @@ module Imports
if record.present? if record.present?
tenant_code = string_or_nil(xml_doc, "_2bTenCode") tenant_code = string_or_nil(xml_doc, "_2bTenCode")
if tenant_code.present? && record.tenant_code.blank? if tenant_code.present? && record.tenancycode.blank?
record.update!(tenant_code:) record.update!(tenancycode: tenant_code)
else else
@logger.info("Case Log #{record.id} has a value for tenant_code, skipping update") @logger.info("Case Log #{record.id} has a value for tenancycode, skipping update")
end end
else else
@logger.warn("Could not find record matching legacy ID #{old_id}") @logger.warn("Could not find record matching legacy ID #{old_id}")

4
app/services/imports/case_logs_import_service.rb

@ -61,7 +61,7 @@ module Imports
attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint")
attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a")
attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b")
attributes["tenant_code"] = string_or_nil(xml_doc, "_2bTenCode") attributes["tenancycode"] = string_or_nil(xml_doc, "_2bTenCode")
attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba") attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba")
attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears") attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears")
attributes["needstype"] = needs_type(xml_doc) attributes["needstype"] = needs_type(xml_doc)
@ -111,7 +111,7 @@ module Imports
attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11") attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11")
attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS") attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS")
attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2") attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2")
attributes["previous_postcode_known"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"])
attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c") attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c")
attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d") attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d")
attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13") attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13")

2
app/views/case_logs/_log_list.html.erb

@ -51,7 +51,7 @@
<% end %> <% end %>
<% end %> <% end %>
<% row.cell( <% row.cell(
text: log.tenant_code? ? log.tenant_code : "–", text: log.tenancycode? ? log.tenancycode : "–",
classes: "app-!-font-tabular", classes: "app-!-font-tabular",
) %> ) %>
<% row.cell( <% row.cell(

129
config/forms/2021_2022.json

@ -981,7 +981,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"shelteredaccom": { "sheltered": {
"check_answer_label": "Is this letting in sheltered accommodation?", "check_answer_label": "Is this letting in sheltered accommodation?",
"header": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?",
"hint_text": "", "hint_text": "",
@ -1161,7 +1161,14 @@
"age1": [0] "age1": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age1_known": 0 }, { "age1_known": 1 }] "depends_on": [
{
"age1_known": 0
},
{
"age1_known": 1
}
]
} }
}, },
"age1": { "age1": {
@ -1859,7 +1866,14 @@
"age2": [0] "age2": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age2_known": 0 }, { "age2_known": 1 }] "depends_on": [
{
"age2_known": 0
},
{
"age2_known": 1
}
]
} }
}, },
"age2": { "age2": {
@ -2147,7 +2161,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_2": 0, "details_known_2": 0,
"age2": { "operator": ">", "operand": 15 } "age2": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_2": 0, "details_known_2": 0,
@ -2340,7 +2357,14 @@
"age3": [0] "age3": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age3_known": 0 }, { "age3_known": 1 }] "depends_on": [
{
"age3_known": 0
},
{
"age3_known": 1
}
]
} }
}, },
"age3": { "age3": {
@ -2628,7 +2652,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_3": 0, "details_known_3": 0,
"age3": { "operator": ">", "operand": 15 } "age3": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_3": 0, "details_known_3": 0,
@ -2818,7 +2845,14 @@
"age4": [0] "age4": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age4_known": 0 }, { "age4_known": 1 }] "depends_on": [
{
"age4_known": 0
},
{
"age4_known": 1
}
]
} }
}, },
"age4": { "age4": {
@ -3106,7 +3140,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_4": 0, "details_known_4": 0,
"age4": { "operator": ">", "operand": 15 } "age4": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_4": 0, "details_known_4": 0,
@ -3293,7 +3330,14 @@
"age5": [0] "age5": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age5_known": 0 }, { "age5_known": 1 }] "depends_on": [
{
"age5_known": 0
},
{
"age5_known": 1
}
]
} }
}, },
"age5": { "age5": {
@ -3581,7 +3625,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_5": 0, "details_known_5": 0,
"age5": { "operator": ">", "operand": 15 } "age5": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_5": 0, "details_known_5": 0,
@ -3765,7 +3812,14 @@
"age6": [0] "age6": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age6_known": 0 }, { "age6_known": 1 }] "depends_on": [
{
"age6_known": 0
},
{
"age6_known": 1
}
]
} }
}, },
"age6": { "age6": {
@ -4053,7 +4107,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_6": 0, "details_known_6": 0,
"age6": { "operator": ">", "operand": 15 } "age6": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_6": 0, "details_known_6": 0,
@ -4234,7 +4291,14 @@
"age7": [0] "age7": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age7_known": 0 }, { "age7_known": 1 }] "depends_on": [
{
"age7_known": 0
},
{
"age7_known": 1
}
]
} }
}, },
"age7": { "age7": {
@ -4522,7 +4586,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_7": 0, "details_known_7": 0,
"age7": { "operator": ">", "operand": 15 } "age7": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_7": 0, "details_known_7": 0,
@ -4700,7 +4767,14 @@
"age8": [0] "age8": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age8_known": 0 }, { "age8_known": 1 }] "depends_on": [
{
"age8_known": 0
},
{
"age8_known": 1
}
]
} }
}, },
"age8": { "age8": {
@ -4988,7 +5062,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_8": 0, "details_known_8": 0,
"age8": { "operator": ">", "operand": 15 } "age8": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_8": 0, "details_known_8": 0,
@ -5857,7 +5934,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"previous_postcode_known": { "ppcodenk": {
"header": "Do you know the postcode of the household’s last settled accommodation?", "header": "Do you know the postcode of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ‘last settled home’.", "hint_text": "This is also known as the household’s ‘last settled home’.",
"type": "radio", "type": "radio",
@ -5874,8 +5951,12 @@
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ "previous_postcode_known": 0 }, {
{ "previous_postcode_known": 1 } "ppcodenk": 0
},
{
"ppcodenk": 1
}
] ]
} }
}, },
@ -5892,7 +5973,7 @@
}, },
"inferred_check_answers_value": { "inferred_check_answers_value": {
"condition": { "condition": {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
"value": "Not known" "value": "Not known"
} }
@ -5910,8 +5991,12 @@
"type": "radio", "type": "radio",
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ "previous_la_known": 0 }, {
{ "previous_la_known": 1 } "previous_la_known": 0
},
{
"previous_la_known": 1
}
] ]
}, },
"answer_options": { "answer_options": {

16
config/forms/2022_2023.json

@ -1016,7 +1016,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"shelteredaccom": { "sheltered": {
"check_answer_label": "Is this letting in sheltered accommodation?", "check_answer_label": "Is this letting in sheltered accommodation?",
"header": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?",
"hint_text": "", "hint_text": "",
@ -5199,6 +5199,9 @@
}, },
"3": { "3": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
},
"6": {
"value": "Don’t know"
} }
} }
} }
@ -5560,9 +5563,6 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"1": {
"value": "Just moved to local authority area"
},
"2": { "2": {
"value": "Less than 1 year" "value": "Less than 1 year"
}, },
@ -5893,7 +5893,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"previous_postcode_known": { "ppcodenk": {
"header": "Do you know the postcode of the household’s last settled accommodation?", "header": "Do you know the postcode of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ‘last settled home’.", "hint_text": "This is also known as the household’s ‘last settled home’.",
"type": "radio", "type": "radio",
@ -5911,10 +5911,10 @@
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
{ {
"previous_postcode_known": 1 "ppcodenk": 1
} }
] ]
} }
@ -5932,7 +5932,7 @@
}, },
"inferred_check_answers_value": { "inferred_check_answers_value": {
"condition": { "condition": {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
"value": "Not known" "value": "Not known"
} }

0
config/forms/setup/log_setup.json

13
db/migrate/20220613123730_add_export_fields.rb

@ -0,0 +1,13 @@
class AddExportFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :hhtype, :integer
t.column :new_old, :integer
t.column :vacdays, :integer
t.rename :tenant_code, :tenancycode
t.rename :previous_postcode_known, :ppcodenk
t.rename :shelteredaccom, :sheltered
t.remove :tenancy_code, type: :string
end
end
end

10
db/schema.rb

@ -18,7 +18,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do
t.integer "status", default: 0 t.integer "status", default: 0
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "tenant_code" t.string "tenancycode"
t.integer "age1" t.integer "age1"
t.string "sex1" t.string "sex1"
t.integer "ethnic" t.integer "ethnic"
@ -53,7 +53,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do
t.integer "reservist" t.integer "reservist"
t.integer "illness" t.integer "illness"
t.integer "preg_occ" t.integer "preg_occ"
t.string "tenancy_code"
t.integer "startertenancy" t.integer "startertenancy"
t.integer "tenancylength" t.integer "tenancylength"
t.integer "tenancy" t.integer "tenancy"
@ -143,7 +142,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do
t.decimal "tshortfall", precision: 10, scale: 2 t.decimal "tshortfall", precision: 10, scale: 2
t.decimal "chcharge", precision: 10, scale: 2 t.decimal "chcharge", precision: 10, scale: 2
t.integer "declaration" t.integer "declaration"
t.integer "previous_postcode_known" t.integer "ppcodenk"
t.integer "previous_la_known" t.integer "previous_la_known"
t.boolean "is_previous_la_inferred" t.boolean "is_previous_la_inferred"
t.integer "age1_known" t.integer "age1_known"
@ -194,8 +193,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "retirement_value_check" t.integer "retirement_value_check"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "shelteredaccom" t.integer "sheltered"
t.integer "pregnancy_value_check" t.integer "pregnancy_value_check"
t.integer "hhtype"
t.integer "new_old"
t.integer "vacdays"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true

9
spec/factories/case_log.rb

@ -11,7 +11,7 @@ FactoryBot.define do
end end
trait :in_progress do trait :in_progress do
status { 1 } status { 1 }
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
postcode_full { Faker::Address.postcode } postcode_full { Faker::Address.postcode }
ppostcode_full { Faker::Address.postcode } ppostcode_full { Faker::Address.postcode }
age1 { 17 } age1 { 17 }
@ -27,7 +27,7 @@ FactoryBot.define do
incfreq { 1 } incfreq { 1 }
end end
trait :conditional_section_complete do trait :conditional_section_complete do
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 34 } age1 { 34 }
sex1 { "M" } sex1 { "M" }
ethnic { 2 } ethnic { 2 }
@ -37,7 +37,7 @@ FactoryBot.define do
end end
trait :completed do trait :completed do
status { 2 } status { 2 }
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 35 } age1 { 35 }
sex1 { "F" } sex1 { "F" }
ethnic { 2 } ethnic { 2 }
@ -55,7 +55,6 @@ FactoryBot.define do
reservist { 0 } reservist { 0 }
illness { 1 } illness { 1 }
preg_occ { 2 } preg_occ { 2 }
tenancy_code { Faker::Name.initials(number: 10) }
startertenancy { 0 } startertenancy { 0 }
tenancylength { 5 } tenancylength { 5 }
tenancy { 1 } tenancy { 1 }
@ -132,7 +131,7 @@ FactoryBot.define do
unitletas { 2 } unitletas { 2 }
has_benefits { 1 } has_benefits { 1 }
is_carehome { 0 } is_carehome { 0 }
shelteredaccom { 0 } sheltered { 0 }
declaration { 1 } declaration { 1 }
end end
created_at { Time.utc(2022, 2, 8, 16, 52, 15) } created_at { Time.utc(2022, 2, 8, 16, 52, 15) }

10
spec/features/form/check_answers_page_spec.rb

@ -148,7 +148,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -161,7 +161,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -176,7 +176,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -195,7 +195,7 @@ RSpec.describe "Form Check Answers Page" do
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
needstype: 1, needstype: 1,
tenant_code: nil, tenancycode: nil,
age1: nil, age1: nil,
layear: 2, layear: 2,
waityear: 1, waityear: 1,
@ -221,7 +221,7 @@ RSpec.describe "Form Check Answers Page" do
it "they can click a button to skip sections until the next incomplete section" do it "they can click a button to skip sections until the next incomplete section" do
visit("/logs/#{skip_section_case_log.id}/household-characteristics/check-answers") visit("/logs/#{skip_section_case_log.id}/household-characteristics/check-answers")
click_link("Save and go to next incomplete section") click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/tenancy-code") expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/property-information/check-answers")
end end
it "they can click a button to cycle around to the next incomplete section" do it "they can click a button to cycle around to the next incomplete section" do

6
spec/features/form/form_navigation_spec.rb

@ -16,7 +16,7 @@ RSpec.describe "Form Navigation" do
let(:id) { case_log.id } let(:id) { case_log.id }
let(:question_answers) do let(:question_answers) do
{ {
tenant_code: { type: "text", answer: "BZ737", path: "tenant-code-test" }, tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" },
age1: { type: "numeric", answer: 25, path: "person-1-age" }, age1: { type: "numeric", answer: 25, path: "person-1-age" },
sex1: { type: "radio", answer: "Female", path: "person-1-gender" }, sex1: { type: "radio", answer: "Female", path: "person-1-gender" },
ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" }, ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" },
@ -55,7 +55,7 @@ RSpec.describe "Form Navigation" do
describe "Back link directs correctly", js: true do describe "Back link directs correctly", js: true do
it "go back to tasklist page from tenant code" do it "go back to tasklist page from tenant code" do
visit("/logs/#{id}") visit("/logs/#{id}")
visit("/logs/#{id}/tenant-code") visit("/logs/#{id}/tenant-code-test")
click_link(text: "Back") click_link(text: "Back")
expect(page).to have_content("Log #{id}") expect(page).to have_content("Log #{id}")
end end
@ -65,7 +65,7 @@ RSpec.describe "Form Navigation" do
click_button("Save and continue") click_button("Save and continue")
visit("/logs/#{id}/person-1-age") visit("/logs/#{id}/person-1-age")
click_link(text: "Back") click_link(text: "Back")
expect(page).to have_field("case-log-tenant-code-field") expect(page).to have_field("case-log-tenancycode-field")
end end
it "doesn't get stuck in infinite loops", js: true do it "doesn't get stuck in infinite loops", js: true do

2
spec/features/form/saving_data_spec.rb

@ -23,7 +23,7 @@ RSpec.describe "Form Saving Data" do
end end
let(:question_answers) do let(:question_answers) do
{ {
tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" }, tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" },
age1: { type: "numeric", answer: 25, path: "person_1_age" }, age1: { type: "numeric", answer: 25, path: "person_1_age" },
sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" }, sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" },
hhmemb: { type: "numeric", answer: 3, path: "household_number_of_members" }, hhmemb: { type: "numeric", answer: 3, path: "household_number_of_members" },

2
spec/features/form/tasklist_page_spec.rb

@ -50,7 +50,7 @@ RSpec.describe "Task List" do
it "shows number of completed sections if one section is completed" do it "shows number of completed sections if one section is completed" do
visit("/logs/#{setup_completed_log.id}") visit("/logs/#{setup_completed_log.id}")
expect(page).to have_content("1 of 10 sections completed.") expect(page).to have_content("1 of 9 sections completed.")
end end
it "show skip link for next incomplete section" do it "show skip link for next incomplete section" do

5
spec/fixtures/complete_case_log.json vendored

@ -1,6 +1,6 @@
{ {
"case_log": { "case_log": {
"tenant_code": "T657", "tenancycode": "T657",
"age1": 35, "age1": 35,
"sex1": "F", "sex1": "F",
"ethnic": 0, "ethnic": 0,
@ -44,7 +44,6 @@
"reservist": 0, "reservist": 0,
"illness": 1, "illness": 1,
"preg_occ": 1, "preg_occ": 1,
"tenancy_code": "BZ757",
"startdate": "12/12/2021", "startdate": "12/12/2021",
"startertenancy": 0, "startertenancy": 0,
"tenancylength": 5, "tenancylength": 5,
@ -132,7 +131,7 @@
"has_benefits": 1, "has_benefits": 1,
"household_charge": 0, "household_charge": 0,
"is_carehome": 1, "is_carehome": 1,
"shelteredaccom": 0, "sheltered": 0,
"declaration": 1, "declaration": 1,
"referral": 1 "referral": 1
} }

4
spec/fixtures/exports/case_logs.csv vendored

@ -1,2 +1,2 @@
status,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,shelteredaccom,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate
2,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC,BZ737,1 2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC

1 status tenancycode age1 sex1 ethnic national prevten ecstat1 hhmemb age2 sex2 ecstat2 age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap leftreg reservist illness preg_occ startertenancy tenancylength tenancy ppostcode_full rsnvac unittype_gn beds offered wchair earnings incfreq benefits period layear waityear postcode_full reasonpref cbl chr cap reasonother housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h illness_type_1 illness_type_2 illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother irproduct_other reason propcode la prevloc hb hbrentshortfall mrcdate incref startdate armedforces unitletas builtype voiddate renttype needstype lettype totchild totelder totadult nocharge referral brent scharge pscharge supcharg tcharge tshortfall chcharge ppcodenk has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 lar shelteredaccom irproduct joint sheltered hhtype new_old vacdays form owningorgid owningorgname hcnum maningorgid maningorgname manhcnum createddate uploaddate
2 2 BZ737 35 F 2 4 6 0 2 32 M 6 1 0 1 0 1 2 0 5 1 SE26RT 6 7 3 2 1 68 1 1 2 2 1 NW15TY 1 1 1 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 4 123 E09000003 E07000105 6 1 2020-05-05 10:36:49 UTC 0 2022-02-02 10:36:49 UTC 1 2 1 2019-11-03 00:00:00 UTC 2 1 7 0 0 2 0 200.0 50.0 40.0 35.0 325.0 12.0 1 1 0 100.0 25.0 20.0 17.5 162.5 6.0 0 1 2 P 0 0 4 2 638 {id} {owning_org_id} DLUHC 1234 {managing_org_id} DLUHC 1234 2022-02-08 16:52:15 UTC 2022-02-08 16:52:15 UTC

9
spec/fixtures/exports/case_logs.xml vendored

@ -2,6 +2,7 @@
<forms> <forms>
<form> <form>
<status>2</status> <status>2</status>
<tenancycode>BZ737</tenancycode>
<age1>35</age1> <age1>35</age1>
<sex1>F</sex1> <sex1>F</sex1>
<ethnic>2</ethnic> <ethnic>2</ethnic>
@ -108,6 +109,7 @@
<tcharge>325.0</tcharge> <tcharge>325.0</tcharge>
<tshortfall>12.0</tshortfall> <tshortfall>12.0</tshortfall>
<chcharge/> <chcharge/>
<ppcodenk>1</ppcodenk>
<has_benefits>1</has_benefits> <has_benefits>1</has_benefits>
<renewal>0</renewal> <renewal>0</renewal>
<wrent>100.0</wrent> <wrent>100.0</wrent>
@ -129,7 +131,10 @@
<relat8/> <relat8/>
<lar/> <lar/>
<irproduct/> <irproduct/>
<shelteredaccom>0</shelteredaccom> <sheltered>0</sheltered>
<hhtype>4</hhtype>
<new_old>2</new_old>
<vacdays>638</vacdays>
<form>{id}</form> <form>{id}</form>
<owningorgid>{owning_org_id}</owningorgid> <owningorgid>{owning_org_id}</owningorgid>
<owningorgname>DLUHC</owningorgname> <owningorgname>DLUHC</owningorgname>
@ -139,8 +144,6 @@
<manhcnum>1234</manhcnum> <manhcnum>1234</manhcnum>
<createddate>2022-02-08 16:52:15 UTC</createddate> <createddate>2022-02-08 16:52:15 UTC</createddate>
<uploaddate>2022-02-08 16:52:15 UTC</uploaddate> <uploaddate>2022-02-08 16:52:15 UTC</uploaddate>
<tenancycode>BZ737</tenancycode>
<ppcodenk>1</ppcodenk>
<providertype>1</providertype> <providertype>1</providertype>
</form> </form>
</forms> </forms>

22
spec/fixtures/forms/2021_2022.json vendored

@ -12,7 +12,7 @@
"pages": { "pages": {
"tenant_code_test": { "tenant_code_test": {
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "This is how you usually refer to this tenancy on your own systems.", "hint_text": "This is how you usually refer to this tenancy on your own systems.",
@ -47,7 +47,7 @@
{ {
"housingneeds_a": null "housingneeds_a": null
} }
] ]
}, },
"person_1_gender": { "person_1_gender": {
"questions": { "questions": {
@ -220,7 +220,7 @@
"header": "property reference?", "header": "property reference?",
"type": "text" "type": "text"
} }
} }
} }
} }
}, },
@ -367,21 +367,6 @@
"tenancy_and_property": { "tenancy_and_property": {
"label": "Tenancy and property information", "label": "Tenancy and property information",
"subsections": { "subsections": {
"tenancy_information": {
"label": "Tenancy information",
"pages": {
"tenancy_code": {
"questions": {
"tenancy_code": {
"check_answer_label": "What is the tenancy code?",
"header": "What is the tenancy code?",
"type": "text",
"width": 10
}
}
}
}
},
"property_information": { "property_information": {
"label": "Property information", "label": "Property information",
"pages": { "pages": {
@ -983,7 +968,6 @@
"depends_on": [{ "depends_on": [{
"household_characteristics": "completed", "household_characteristics": "completed",
"household_needs": "completed", "household_needs": "completed",
"tenancy_information": "completed",
"property_information": "completed" "property_information": "completed"
}], }],
"pages": { "pages": {

2
spec/fixtures/forms/2022_2023.json vendored

@ -11,7 +11,7 @@
"pages": { "pages": {
"tenant_code_test": { "tenant_code_test": {
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "Different question header text for this year - 2023", "header": "Different question header text for this year - 2023",
"type": "text", "type": "text",

8
spec/helpers/tasklist_helper_spec.rb

@ -10,14 +10,14 @@ RSpec.describe TasklistHelper do
end end
it "returns the first subsection name if it is partially completed" do it "returns the first subsection name if it is partially completed" do
case_log["tenant_code"] = 123 case_log["tenancycode"] = 123
expect(get_next_incomplete_section(case_log).id).to eq("setup") expect(get_next_incomplete_section(case_log).id).to eq("setup")
end end
end end
describe "get sections count" do describe "get sections count" do
it "returns the total of sections if no status is given" do it "returns the total of sections if no status is given" do
expect(get_subsections_count(empty_case_log)).to eq(10) expect(get_subsections_count(empty_case_log)).to eq(9)
end end
it "returns 0 sections for completed sections if no sections are completed" do it "returns 0 sections for completed sections if no sections are completed" do
@ -25,7 +25,7 @@ RSpec.describe TasklistHelper do
end end
it "returns the number of not started sections" do it "returns the number of not started sections" do
expect(get_subsections_count(empty_case_log, :not_started)).to eq(9) expect(get_subsections_count(empty_case_log, :not_started)).to eq(8)
end end
it "returns the number of sections in progress" do it "returns the number of sections in progress" do
@ -45,7 +45,7 @@ RSpec.describe TasklistHelper do
end end
it "returns the first question page path for the section if it has not been started yet" do it "returns the first question page path for the section if it has not been started yet" do
expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code-test/)
end end
it "when first question being not routed to returns the next routed question link" do it "when first question being not routed to returns the next routed question link" do

24
spec/models/case_log_spec.rb

@ -1235,7 +1235,7 @@ RSpec.describe CaseLog do
managing_organisation: owning_organisation, managing_organisation: owning_organisation,
owning_organisation:, owning_organisation:,
created_by: created_by_user, created_by: created_by_user,
previous_postcode_known: 1, ppcodenk: 1,
ppostcode_full: "M1 1AE", ppostcode_full: "M1 1AE",
}) })
end end
@ -1275,7 +1275,7 @@ RSpec.describe CaseLog do
end end
it "correctly resets all fields if previous postcode not known" do it "correctly resets all fields if previous postcode not known" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["ppostcode_full"]).to eq(nil) expect(record_from_db["ppostcode_full"]).to eq(nil)
@ -1284,7 +1284,7 @@ RSpec.describe CaseLog do
end end
it "correctly resets la if la is not known" do it "correctly resets la if la is not known" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
address_case_log.update!({ previous_la_known: 1, prevloc: "S92000003" }) address_case_log.update!({ previous_la_known: 1, prevloc: "S92000003" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["prevloc"]).to eq("S92000003") expect(record_from_db["prevloc"]).to eq("S92000003")
@ -1297,7 +1297,7 @@ RSpec.describe CaseLog do
end end
it "changes the prevloc if previous postcode changes from not known to known and provided" do it "changes the prevloc if previous postcode changes from not known to known and provided" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" }) address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
@ -1305,7 +1305,7 @@ RSpec.describe CaseLog do
expect(address_case_log.prevloc).to eq("E09000033") expect(address_case_log.prevloc).to eq("E09000033")
expect(record_from_db["prevloc"]).to eq("E09000033") expect(record_from_db["prevloc"]).to eq("E09000033")
address_case_log.update!({ previous_postcode_known: 0, ppostcode_full: "M1 1AD" }) address_case_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["ppostcode_full"]).to eq("M11AD") expect(record_from_db["ppostcode_full"]).to eq("M11AD")
@ -1400,8 +1400,8 @@ RSpec.describe CaseLog do
it "correctly derives and saves waityear" do it "correctly derives and saves waityear" do
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["waityear"]).to eq(1) expect(record_from_db["waityear"]).to eq(2)
expect(case_log["waityear"]).to eq(1) expect(case_log["waityear"]).to eq(2)
end end
it "correctly derives and saves underoccupation_benefitcap if year is 2021" do it "correctly derives and saves underoccupation_benefitcap if year is 2021" do
@ -1757,8 +1757,8 @@ RSpec.describe CaseLog do
case_log.update!({ renewal: 1 }) case_log.update!({ renewal: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["waityear"]).to eq(1) expect(record_from_db["waityear"]).to eq(2)
expect(case_log["waityear"]).to eq(1) expect(case_log["waityear"]).to eq(2)
case_log.update!({ renewal: 0 }) case_log.update!({ renewal: 0 })
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
@ -1891,13 +1891,13 @@ RSpec.describe CaseLog do
describe "#filter_by_tenant_code" do describe "#filter_by_tenant_code" do
it "allows searching by a Tenant Code" do it "allows searching by a Tenant Code" do
result = described_class.filter_by_tenant_code(case_log_to_search.tenant_code) result = described_class.filter_by_tenant_code(case_log_to_search.tenancycode)
expect(result.count).to eq(1) expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id expect(result.first.id).to eq case_log_to_search.id
end end
context "when tenant_code has lower case letters" do context "when tenant_code has lower case letters" do
let(:matching_tenant_code_lower_case) { case_log_to_search.tenant_code.downcase } let(:matching_tenant_code_lower_case) { case_log_to_search.tenancycode.downcase }
it "allows searching by a Tenant Code" do it "allows searching by a Tenant Code" do
result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case) result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case)
@ -1941,7 +1941,7 @@ RSpec.describe CaseLog do
end end
it "allows searching using tenancy code" do it "allows searching using tenancy code" do
result = described_class.search_by(case_log_to_search.tenant_code) result = described_class.search_by(case_log_to_search.tenancycode)
expect(result.count).to eq(1) expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id expect(result.first.id).to eq case_log_to_search.id
end end

4
spec/models/form/subsection_spec.rb

@ -30,7 +30,7 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has questions" do it "has questions" do
expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode]
expect(subsection.questions.map(&:id)).to eq(expected_questions) expect(subsection.questions.map(&:id)).to eq(expected_questions)
end end
@ -73,7 +73,7 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has question helpers for the number of applicable questions" do it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb ecstat2 propcode] expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb ecstat2 propcode]
expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subsection.applicable_questions_count(case_log)).to eq(7) expect(subsection.applicable_questions_count(case_log)).to eq(7)
end end

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance form_handler = described_class.instance
form = form_handler.get_form(test_form_name) form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(41) expect(form.pages.count).to eq(40)
end end
end end

6
spec/models/form_spec.rb

@ -88,7 +88,7 @@ RSpec.describe Form, type: :model do
end end
def answer_tenancy_information(case_log) def answer_tenancy_information(case_log)
case_log.tenancy_code = "1234" case_log.tenancycode = "1234"
end end
def answer_property_information(case_log) def answer_property_information(case_log)
@ -126,7 +126,7 @@ RSpec.describe Form, type: :model do
end end
before do before do
case_log.tenant_code = "123" case_log.tenancycode = "123"
case_log.age1 = 35 case_log.age1 = 35
case_log.sex1 = "M" case_log.sex1 = "M"
case_log.ecstat1 = 0 case_log.ecstat1 = 0
@ -149,7 +149,7 @@ RSpec.describe Form, type: :model do
it "returns the first page of the next incomplete subsection (skipping completed subsections)" do it "returns the first page of the next incomplete subsection (skipping completed subsections)" do
answer_household_needs(case_log) answer_household_needs(case_log)
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code") expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("accessible-select-too")
end end
it "returns the declaration section for a completed case log" do it "returns the declaration section for a completed case log" do

5
spec/models/validations/financial_validations_spec.rb

@ -109,6 +109,8 @@ RSpec.describe Validations::FinancialValidations do
end end
describe "housing benefit rent shortfall validations" do describe "housing benefit rent shortfall validations" do
before { record.startdate = Time.zone.local(2022, 5, 1) }
context "when shortfall is yes" do context "when shortfall is yes" do
it "validates that housing benefit is not none" do it "validates that housing benefit is not none" do
record.hbrentshortfall = 1 record.hbrentshortfall = 1
@ -126,7 +128,8 @@ RSpec.describe Validations::FinancialValidations do
.to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")) .to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits"))
end end
it "validates that housing benefit is not Universal Credit without housing benefit" do it "validates that housing benefit is not Universal Credit without housing benefit (prior to 22/23)" do
record.startdate = Time.zone.local(2022, 3, 1)
record.hbrentshortfall = 1 record.hbrentshortfall = 1
record.hb = 7 record.hb = 7
financial_validator.validate_tshortfall(record) financial_validator.validate_tshortfall(record)

6
spec/models/validations/local_authority_validations_spec.rb

@ -14,21 +14,21 @@ RSpec.describe Validations::LocalAuthorityValidations do
end end
it "does not add an error if the record ppostcode_full is valid (uppercase space)" do it "does not add an error if the record ppostcode_full is valid (uppercase space)" do
record.previous_postcode_known = 1 record.ppcodenk = 1
record.ppostcode_full = "M1 1AE" record.ppostcode_full = "M1 1AE"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do
record.previous_postcode_known = 1 record.ppcodenk = 1
record.ppostcode_full = "m11ae" record.ppostcode_full = "m11ae"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does add an error when the postcode is invalid" do it "does add an error when the postcode is invalid" do
record.previous_postcode_known = 1 record.ppcodenk = 1
record.ppostcode_full = "invalid" record.ppostcode_full = "invalid"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).not_to be_empty expect(record.errors).not_to be_empty

34
spec/requests/case_logs_controller_spec.rb

@ -40,7 +40,7 @@ RSpec.describe CaseLogsController, type: :request do
"owning_organisation_id": owning_organisation.id, "owning_organisation_id": owning_organisation.id,
"managing_organisation_id": managing_organisation.id, "managing_organisation_id": managing_organisation.id,
"created_by_id": user.id, "created_by_id": user.id,
"tenant_code": tenant_code, "tenancycode": tenant_code,
"age1": age1, "age1": age1,
"postcode_full": postcode_full, "postcode_full": postcode_full,
"offered": offered, "offered": offered,
@ -63,7 +63,7 @@ RSpec.describe CaseLogsController, type: :request do
it "creates a case log with the values passed" do it "creates a case log with the values passed" do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response["tenant_code"]).to eq(tenant_code) expect(json_response["tenancycode"]).to eq(tenant_code)
expect(json_response["age1"]).to eq(age1) expect(json_response["age1"]).to eq(age1)
expect(json_response["postcode_full"]).to eq(postcode_full) expect(json_response["postcode_full"]).to eq(postcode_full)
end end
@ -149,7 +149,7 @@ RSpec.describe CaseLogsController, type: :request do
:case_log, :case_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
tenant_code: "LC783", tenancycode: "LC783",
) )
end end
let!(:unauthorized_case_log) do let!(:unauthorized_case_log) do
@ -157,7 +157,7 @@ RSpec.describe CaseLogsController, type: :request do
:case_log, :case_log,
owning_organisation: other_organisation, owning_organisation: other_organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,
tenant_code: "UA984", tenancycode: "UA984",
) )
end end
@ -289,7 +289,7 @@ RSpec.describe CaseLogsController, type: :request do
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
tenancy: 6, tenancy: 6,
managing_organisation: organisation, managing_organisation: organisation,
tenant_code: nil) tenancycode: nil)
end end
it "shows case logs for multiple selected statuses and years" do it "shows case logs for multiple selected statuses and years" do
@ -339,7 +339,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "shows case logs matching the tenant code" do it "shows case logs matching the tenant code" do
get "/logs?search=#{log_to_search.tenant_code}", headers: headers, params: {} get "/logs?search=#{log_to_search.tenancycode}", headers: headers, params: {}
expect(page).to have_link(log_to_search.id.to_s) expect(page).to have_link(log_to_search.id.to_s)
logs.each do |log| logs.each do |log|
expect(page).not_to have_link(log.id.to_s) expect(page).not_to have_link(log.id.to_s)
@ -487,8 +487,8 @@ RSpec.describe CaseLogsController, type: :request do
let(:tenant_code_2) { "TC8745" } let(:tenant_code_2) { "TC8745" }
before do before do
FactoryBot.create(:case_log, :in_progress, owning_organisation: org_1, tenant_code: tenant_code_1) FactoryBot.create(:case_log, :in_progress, owning_organisation: org_1, tenancycode: tenant_code_1)
FactoryBot.create(:case_log, :in_progress, owning_organisation: org_2, tenant_code: tenant_code_2) FactoryBot.create(:case_log, :in_progress, owning_organisation: org_2, tenancycode: tenant_code_2)
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
end end
@ -624,7 +624,7 @@ RSpec.describe CaseLogsController, type: :request do
it "displays a section status for a case log" do it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 7 assert_select ".govuk-tag", text: /Not started/, count: 7
assert_select ".govuk-tag", text: /In progress/, count: 2 assert_select ".govuk-tag", text: /In progress/, count: 1
assert_select ".govuk-tag", text: /Completed/, count: 0 assert_select ".govuk-tag", text: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end
@ -752,7 +752,7 @@ RSpec.describe CaseLogsController, type: :request do
expect(csv.second[10]).to eq("Full-time – 30 hours or more") expect(csv.second[10]).to eq("Full-time – 30 hours or more")
end end
it "dowloads filtered logs" do it "downloads filtered logs" do
get "/logs?status[]=completed", headers:, params: {} get "/logs?status[]=completed", headers:, params: {}
csv = CSV.parse(response.body) csv = CSV.parse(response.body)
expect(csv.count).to eq(2) expect(csv.count).to eq(2)
@ -772,7 +772,7 @@ RSpec.describe CaseLogsController, type: :request do
FactoryBot.create(:case_log, :completed, postcode_full: postcode, owning_organisation: organisation) FactoryBot.create(:case_log, :completed, postcode_full: postcode, owning_organisation: organisation)
end end
it "dowloads logs matching both csv and filter logs" do it "downloads logs matching both csv and filter logs" do
get "/logs?status[]=completed&search=#{postcode}", headers:, params: {} get "/logs?status[]=completed&search=#{postcode}", headers:, params: {}
csv = CSV.parse(response.body) csv = CSV.parse(response.body)
expect(csv.count).to eq(2) expect(csv.count).to eq(2)
@ -796,10 +796,10 @@ RSpec.describe CaseLogsController, type: :request do
describe "PATCH" do describe "PATCH" do
let(:case_log) do let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "M1 1AE") FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "M1 1AE")
end end
let(:params) do let(:params) do
{ tenant_code: "New Value" } { tenancycode: "New Value" }
end end
let(:id) { case_log.id } let(:id) { case_log.id }
@ -813,7 +813,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload case_log.reload
expect(case_log.tenant_code).to eq("New Value") expect(case_log.tenancycode).to eq("New Value")
expect(case_log.postcode_full).to eq("M11AE") expect(case_log.postcode_full).to eq("M11AE")
end end
@ -854,10 +854,10 @@ RSpec.describe CaseLogsController, type: :request do
# what actually happens to an ActiveRecord object and what we're doing here, but either is allowed. # what actually happens to an ActiveRecord object and what we're doing here, but either is allowed.
describe "PUT" do describe "PUT" do
let(:case_log) do let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "SW1A 2AA") FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "SW1A 2AA")
end end
let(:params) do let(:params) do
{ tenant_code: "New Value" } { tenancycode: "New Value" }
end end
let(:id) { case_log.id } let(:id) { case_log.id }
@ -871,7 +871,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload case_log.reload
expect(case_log.tenant_code).to eq("New Value") expect(case_log.tenancycode).to eq("New Value")
expect(case_log.postcode_full).to eq("SW1A2AA") expect(case_log.postcode_full).to eq("SW1A2AA")
end end

6
spec/requests/form_controller_spec.rb

@ -286,7 +286,7 @@ RSpec.describe FormController, type: :request do
accessibility_requirements: accessibility_requirements:
%w[ housingneeds_a %w[ housingneeds_a
housingneeds_f], housingneeds_f],
tenant_code:, tenancycode: tenant_code,
}, },
} }
end end
@ -306,7 +306,7 @@ RSpec.describe FormController, type: :request do
"housingneeds_h" => "Don’t know" }, "housingneeds_h" => "Don’t know" },
}, nil }, nil
), ),
Form::Question.new("tenant_code", { "type" => "text" }, nil), Form::Question.new("tenancycode", { "type" => "text" }, nil),
] ]
end end
let(:page) { case_log.form.get_page("accessibility_requirements") } let(:page) { case_log.form.get_page("accessibility_requirements") }
@ -318,7 +318,7 @@ RSpec.describe FormController, type: :request do
expect(case_log.housingneeds_a).to eq(1) expect(case_log.housingneeds_a).to eq(1)
expect(case_log.housingneeds_f).to eq(1) expect(case_log.housingneeds_f).to eq(1)
expect(case_log.tenant_code).to eq(tenant_code) expect(case_log.tenancycode).to eq(tenant_code)
end end
end end
end end

2
spec/requests/organisations_controller_spec.rb

@ -624,7 +624,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows case logs matching the tenant code" do it "shows case logs matching the tenant code" do
get "/organisations/#{organisation.id}/logs?search=#{log_to_search.tenant_code}", headers: headers, params: {} get "/organisations/#{organisation.id}/logs?search=#{log_to_search.tenancycode}", headers: headers, params: {}
expect(page).to have_link(log_to_search.id.to_s) expect(page).to have_link(log_to_search.id.to_s)
logs.each do |log| logs.each do |log|
expect(page).not_to have_link(log.id.to_s) expect(page).not_to have_link(log.id.to_s)

3
spec/requests/schemes_controller_spec.rb

@ -312,7 +312,8 @@ RSpec.describe SchemesController, type: :request do
end end
it "has correct title" do it "has correct title" do
expect(page).to have_title("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK") expected_title = CGI.escapeHTML("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title(expected_title)
end end
context "when paginating over 20 results" do context "when paginating over 20 results" do

4
spec/services/exports/case_log_export_service_spec.rb

@ -47,7 +47,7 @@ RSpec.describe Exports::CaseLogExportService do
end end
context "and one case log is available for export" do context "and one case log is available for export" do
let!(:case_log) { FactoryBot.create(:case_log, :completed, tenancy_code: "BZ757", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenant_code: "BZ737") } let!(:case_log) { FactoryBot.create(:case_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") }
let(:expected_data_filename) { "core_2021_2022_jan_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "core_2021_2022_jan_mar_f0001_inc0001_pt001.xml" }
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
@ -226,7 +226,7 @@ RSpec.describe Exports::CaseLogExportService do
let(:csv_export_file) { File.open("spec/fixtures/exports/case_logs.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/exports/case_logs.csv", "r:UTF-8") }
let(:expected_csv_filename) { "export_2022_05_01.csv" } let(:expected_csv_filename) { "export_2022_05_01.csv" }
let(:case_log) { FactoryBot.create(:case_log, :completed, tenancy_code: "BZ757", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenant_code: "BZ737") } let(:case_log) { FactoryBot.create(:case_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") }
it "generates an CSV export file with the expected content" do it "generates an CSV export file with the expected content" do
expected_content = replace_entity_ids(case_log, csv_export_file.read) expected_content = replace_entity_ids(case_log, csv_export_file.read)

12
spec/services/imports/case_logs_field_import_service_spec.rb

@ -41,7 +41,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do
end end
context "when updating tenant code" do context "when updating tenant code" do
let(:field) { "tenant_code" } let(:field) { "tenancycode" }
context "and the case log was previously imported" do context "and the case log was previously imported" do
let(:case_log) { CaseLog.find_by(old_id: case_log_id) } let(:case_log) { CaseLog.find_by(old_id: case_log_id) }
@ -51,10 +51,10 @@ RSpec.describe Imports::CaseLogsFieldImportService do
case_log_file.rewind case_log_file.rewind
end end
it "logs that the tenant_code already has a value and does not update the case_log" do it "logs that the tenancycode already has a value and does not update the case_log" do
expect(logger).to receive(:info).with(/Case Log \d+ has a value for tenant_code, skipping update/) expect(logger).to receive(:info).with(/Case Log \d+ has a value for tenancycode, skipping update/)
expect { import_service.send(:update_field, field, remote_folder) } expect { import_service.send(:update_field, field, remote_folder) }
.not_to(change { case_log.reload.tenant_code }) .not_to(change { case_log.reload.tenancycode })
end end
end end
@ -64,12 +64,12 @@ RSpec.describe Imports::CaseLogsFieldImportService do
before do before do
Imports::CaseLogsImportService.new(storage_service, logger).create_logs(fixture_directory) Imports::CaseLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
case_log_file.rewind case_log_file.rewind
case_log.update!(tenant_code: nil) case_log.update!(tenancycode: nil)
end end
it "updates the case_log" do it "updates the case_log" do
expect { import_service.send(:update_field, field, remote_folder) } expect { import_service.send(:update_field, field, remote_folder) }
.to(change { case_log.reload.tenant_code }) .to(change { case_log.reload.tenancycode })
end end
end end
end end

Loading…
Cancel
Save