From 92dc829e8e1c78b0cbe766b17f40c2e670015235 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 6 Jun 2024 16:52:53 +0100 Subject: [PATCH] CLDC-3463: Fix bug with vacdays calculation (#2444) * CLDC-3463: Fix bug with vacdays calculation * CLDC-3463: Fix lettings csv export tests * Lint * Use build_stubbed where necessary for lettings logs in tests * Update all logs in rake task but without validation * Try validations in rake tasks and log when needing to skip them --- .../lettings_log_variables.rb | 4 +- lib/tasks/recalculate_vacdays.rake | 17 + spec/factories/lettings_log.rb | 8 +- .../lettings_log_csv_export_codes_23.csv | 2 +- .../lettings_log_csv_export_codes_24.csv | 2 +- .../lettings_log_csv_export_labels_23.csv | 2 +- .../lettings_log_csv_export_labels_24.csv | 2 +- ...gs_log_csv_export_non_support_codes_23.csv | 2 +- ...gs_log_csv_export_non_support_codes_24.csv | 2 +- ...s_log_csv_export_non_support_labels_23.csv | 2 +- ...s_log_csv_export_non_support_labels_24.csv | 2 +- spec/helpers/tasklist_helper_spec.rb | 2 +- spec/models/form/subsection_spec.rb | 3 +- spec/models/form_spec.rb | 2 +- .../lettings_log_derived_fields_spec.rb | 19 + spec/models/lettings_log_spec.rb | 8 +- spec/models/log_spec.rb | 12 +- spec/request_helper.rb | 8 +- .../csv/lettings_log_csv_service_spec.rb | 538 ++++++++++++------ 19 files changed, 439 insertions(+), 198 deletions(-) create mode 100644 lib/tasks/recalculate_vacdays.rake diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 7bed44cbd..2c0d1f1ad 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -296,9 +296,9 @@ private return unless startdate if mrcdate.present? - (startdate - mrcdate).to_i / 1.day + startdate.to_date - mrcdate.to_date elsif voiddate.present? - (startdate - voiddate).to_i / 1.day + startdate.to_date - voiddate.to_date end end diff --git a/lib/tasks/recalculate_vacdays.rake b/lib/tasks/recalculate_vacdays.rake new file mode 100644 index 000000000..38aa98f9b --- /dev/null +++ b/lib/tasks/recalculate_vacdays.rake @@ -0,0 +1,17 @@ +desc "Recalculate vacdays after bugfix for daylight savings time changes" +task recalculate_vacdays: :environment do + logs = LettingsLog.where.not(vacdays: nil) + logs.each do |log| + Rails.logger.log("Log #{log.id}") + recalculated_vacdays = log.send(:property_vacant_days) + next if recalculated_vacdays == log.vacdays + + log.vacdays = recalculated_vacdays + next if log.save + + Rails.logger.log("Log #{log.id} could not be saved, saving updated vacdays without validation") + log.reload + log.vacdays = recalculated_vacdays + log.save!(validate: false) + end +end diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index eb7f8e5eb..20357161a 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :lettings_log do - assigned_to { FactoryBot.create(:user) } + assigned_to { association :user } created_by { assigned_to } owning_organisation { assigned_to.organisation } managing_organisation { assigned_to.organisation } @@ -216,5 +216,11 @@ FactoryBot.define do illness_type_9 { false } illness_type_10 { false } end + trait :ignore_validation_errors do + to_create do |instance| + instance.valid? + instance.save!(validate: false) + end + end end end diff --git a/spec/fixtures/files/lettings_log_csv_export_codes_23.csv b/spec/fixtures/files/lettings_log_csv_export_codes_23.csv index ca482e070..7415f59f4 100644 --- a/spec/fixtures/files/lettings_log_csv_export_codes_23.csv +++ b/spec/fixtures/files/lettings_log_csv_export_codes_23.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,old_id,old_form_id,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,national,ecstat1,details_known_2,relat2,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_none,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,completed,,s.port@jeemayle.com,s.port@jeemayle.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,1,,,2023,DLUHC,DLUHC,1,7,0,2023-11-26,2,2,1,,2,HIJKLMN,ABCDEFG,0,,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,2,6,2,2,7,1,1,3,2023-11-24,,,1,2023-11-25,,3,1,4,,2,,1,4,,1,4,0,0,2,35,,F,0,2,13,0,0,P,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,,2,,0,0,1,268,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, +,completed,,s.port@jeemayle.com,s.port@jeemayle.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,1,,,2023,DLUHC,DLUHC,1,7,0,2023-11-26,2,2,,,2,HIJKLMN,ABCDEFG,0,,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,2,6,2,2,7,1,1,3,2023-11-24,1,,1,2023-11-25,,3,1,4,,2,,1,4,,1,4,0,0,2,35,,F,0,2,13,0,0,P,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,,2,,0,0,1,268,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_codes_24.csv b/spec/fixtures/files/lettings_log_csv_export_codes_24.csv index e21817cb3..c3db1c8ec 100644 --- a/spec/fixtures/files/lettings_log_csv_export_codes_24.csv +++ b/spec/fixtures/files/lettings_log_csv_export_codes_24.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,nationality_all,ecstat1,details_known_2,relat2,partner_under_16_value_check,multiple_partners_value_check,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,completed,,s.port@jeemayle.com,s.port@jeemayle.com,false,2023-11-26T00:00:00+00:00,,2024-04-01T00:00:00+01:00,1,2023,,DLUHC,DLUHC,1,7,0,2023-11-26,2,2,1,,2,HIJKLMN,ABCDEFG,1,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,0,2,6,2,7,1,1,3,2023-11-24,,,1,2023-11-25,,3,1,4,,2,,4,,1,4,0,0,2,35,,F,0,2,,0,0,P,,,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,0,,2,,0,0,1,268,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, +,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,1,2024,,DLUHC,DLUHC,1,7,0,2024-04-01,2,2,,,2,HIJKLMN,ABCDEFG,1,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,0,2,6,2,7,1,1,3,2024-03-30,1,,1,2024-03-31,,3,1,4,,2,,4,,1,4,0,0,2,35,,F,0,2,36,0,0,P,,,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,0,,2,,0,0,1,268,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_labels_23.csv b/spec/fixtures/files/lettings_log_csv_export_labels_23.csv index d7a2d58bf..227f562b3 100644 --- a/spec/fixtures/files/lettings_log_csv_export_labels_23.csv +++ b/spec/fixtures/files/lettings_log_csv_export_labels_23.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,old_id,old_form_id,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,national,ecstat1,details_known_2,relat2,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_none,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,completed,,s.port@jeemayle.com,s.port@jeemayle.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,single log,,,2023,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2023-11-26,Affordable Rent,Affordable Rent,Rent to Buy,,No,HIJKLMN,ABCDEFG,No,,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,Affordable rent basis,Tenant abandoned property,No,2,House,Purpose built,Yes,3,2023-11-24,,,Yes,2023-11-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,Yes,4,,Yes,4,0,0,2,35,,Female,White,Irish,Tenant prefers not to say,Other,Yes,Partner,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,,Tenant applied directly (no referral or nomination),,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, +,completed,,s.port@jeemayle.com,s.port@jeemayle.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,single log,,,2023,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2023-11-26,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,No,,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,Affordable rent basis,Tenant abandoned property,No,2,House,Purpose built,Yes,3,2023-11-24,1,,Yes,2023-11-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,Yes,4,,Yes,4,0,0,2,35,,Female,White,Irish,Tenant prefers not to say,Other,Yes,Partner,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,,Tenant applied directly (no referral or nomination),,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_labels_24.csv b/spec/fixtures/files/lettings_log_csv_export_labels_24.csv index 78e85dad1..48e4e0f33 100644 --- a/spec/fixtures/files/lettings_log_csv_export_labels_24.csv +++ b/spec/fixtures/files/lettings_log_csv_export_labels_24.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,nationality_all,ecstat1,details_known_2,relat2,partner_under_16_value_check,multiple_partners_value_check,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,single log,2024,,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2024-04-01,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,Yes,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,No,Affordable rent basis,Tenant abandoned property,No,House,Purpose built,Yes,3,2024-03-30,,,Yes,2024-03-31,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,4,,Yes,4,0,0,2,35,,Female,White,Irish,Australia,Other,Yes,Partner,,,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,No,,Tenant applied directly (no referral or nomination),,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, +,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,single log,2024,,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2024-04-01,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,Yes,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,No,Affordable rent basis,Tenant abandoned property,No,House,Purpose built,Yes,3,2024-03-30,1,,Yes,2024-03-31,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,4,,Yes,4,0,0,2,35,,Female,White,Irish,Australia,Other,Yes,Partner,,,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,No,,Tenant applied directly (no referral or nomination),,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv index e4cd2fbc4..23689ad52 100644 --- a/spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv +++ b/spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,majorrepairs,mrcdate,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,refused,age1,sex1,ethnic_group,ethnic,national,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_none,referral,incref,incfreq,earnings,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,brent,scharge,pscharge,supcharg,tcharge,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,completed,,choreographer@owtluk.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,1,2023,DLUHC,DLUHC,1,7,0,2023-11-26,2,2,1,,2,HIJKLMN,ABCDEFG,0,,Address line 1,,London,,NW9 5LL,Barnet,0,2,6,2,2,7,1,1,3,2023-11-24,1,1,2023-11-25,3,1,4,,2,,1,4,1,35,F,0,2,13,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,,2,0,1,268,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,1,12.0,,,,,,,,,,,,,,,,,,,, +,completed,,choreographer@owtluk.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,1,2023,DLUHC,DLUHC,1,7,0,2023-11-26,2,2,,,2,HIJKLMN,ABCDEFG,0,,Address line 1,,London,,NW9 5LL,Barnet,0,2,6,2,2,7,1,1,3,2023-11-24,1,1,2023-11-25,3,1,4,,2,,1,4,1,35,F,0,2,13,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,,2,0,1,268,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,1,12.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv index 21e1c1414..b35d4dfc1 100644 --- a/spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv +++ b/spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,unittype_gn,builtype,wchair,beds,voiddate,vacdays,majorrepairs,mrcdate,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,hhmemb,refused,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral,incref,incfreq,earnings,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,brent,scharge,pscharge,supcharg,tcharge,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,in_progress,,choreographer@owtluk.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,1,2024,,DLUHC,DLUHC,1,7,0,2024-04-01,2,2,1,,2,HIJKLMN,ABCDEFG,1,0,,Address line 1,,London,,NW9 5LL,Barnet,0,2,6,2,7,1,1,3,2024-03-30,0,1,2024-03-31,3,1,4,,2,,4,1,35,F,0,2,,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,0,,2,0,1,268,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,1,12.0,,,,,,,,,,,,,,,,,,,, +,in_progress,,choreographer@owtluk.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,1,2024,,DLUHC,DLUHC,1,7,0,2024-04-01,2,2,,,2,HIJKLMN,ABCDEFG,1,0,,Address line 1,,London,,NW9 5LL,Barnet,0,2,6,2,7,1,1,3,2024-03-30,1,1,2024-03-31,3,1,4,,2,,4,1,35,F,0,2,36,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,0,,2,0,1,268,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,1,12.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv index ead1815e7..1bbbc2692 100644 --- a/spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv +++ b/spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,majorrepairs,mrcdate,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,refused,age1,sex1,ethnic_group,ethnic,national,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_none,referral,incref,incfreq,earnings,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,brent,scharge,pscharge,supcharg,tcharge,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,completed,,choreographer@owtluk.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,single log,2023,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2023-11-26,Affordable Rent,Affordable Rent,Rent to Buy,,No,HIJKLMN,ABCDEFG,No,,Address line 1,,London,,NW9 5LL,Barnet,No,Affordable rent basis,Tenant abandoned property,No,2,House,Purpose built,Yes,3,2023-11-24,1,Yes,2023-11-25,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,Yes,4,Yes,35,Female,White,Irish,Tenant prefers not to say,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,,Yes,,,,No,No,Yes,,Tenant applied directly (no referral or nomination),No,Weekly,268,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,Yes,12.0,,,,,,,,,,,,,,,,,,,, +,completed,,choreographer@owtluk.com,false,2023-11-26T00:00:00+00:00,,2023-11-26T00:00:00+00:00,single log,2023,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2023-11-26,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,No,,Address line 1,,London,,NW9 5LL,Barnet,No,Affordable rent basis,Tenant abandoned property,No,2,House,Purpose built,Yes,3,2023-11-24,1,Yes,2023-11-25,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,Yes,4,Yes,35,Female,White,Irish,Tenant prefers not to say,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,,Yes,,,,No,No,Yes,,Tenant applied directly (no referral or nomination),No,Weekly,268,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,Yes,12.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv index c53147b26..e66b19f0b 100644 --- a/spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv +++ b/spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv @@ -1,2 +1,2 @@ id,status,duplicate_set_id,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,unittype_gn,builtype,wchair,beds,voiddate,vacdays,majorrepairs,mrcdate,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,hhmemb,refused,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral,incref,incfreq,earnings,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,brent,scharge,pscharge,supcharg,tcharge,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,in_progress,,choreographer@owtluk.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,single log,2024,,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2024-04-01,Affordable Rent,Affordable Rent,Rent to Buy,,No,HIJKLMN,ABCDEFG,Yes,No,,Address line 1,,London,,NW9 5LL,Barnet,No,Affordable rent basis,Tenant abandoned property,No,House,Purpose built,Yes,3,2024-03-30,0,Yes,2024-03-31,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,4,Yes,35,Female,White,Irish,,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,,Yes,,,,No,No,Yes,No,,Tenant applied directly (no referral or nomination),No,Weekly,268,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,Yes,12.0,,,,,,,,,,,,,,,,,,,, +,in_progress,,choreographer@owtluk.com,false,2024-04-01T00:00:00+01:00,,2024-04-01T00:00:00+01:00,single log,2024,,DLUHC,DLUHC,General needs,Affordable rent general needs local authority,No,2024-04-01,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,Yes,No,,Address line 1,,London,,NW9 5LL,Barnet,No,Affordable rent basis,Tenant abandoned property,No,House,Purpose built,Yes,3,2024-03-30,1,Yes,2024-03-31,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,4,Yes,35,Female,White,Irish,Australia,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,,Yes,,,,No,No,Yes,No,,Tenant applied directly (no referral or nomination),No,Weekly,268,Universal Credit housing element,Yes,All,,No,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,Yes,12.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 8a34f86d2..7b16a2507 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -13,7 +13,7 @@ RSpec.describe TasklistHelper do describe "with lettings" do let(:empty_lettings_log) { create(:lettings_log) } - let(:lettings_log) { build(:lettings_log, :in_progress, needstype: 1, startdate: now) } + let(:lettings_log) { build_stubbed(:lettings_log, :in_progress, needstype: 1, startdate: now) } describe "get next incomplete section" do it "returns the first subsection name if it is not completed" do diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 4cb430e39..43f4e3bae 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -97,8 +97,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has a status when optional fields are not filled" do - lettings_log.update!({ propcode: nil }) - lettings_log.reload + lettings_log.propcode = nil expect(subsection.status(lettings_log)).to eq(:completed) end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 4370ee43c..0412c6ab2 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -84,7 +84,7 @@ RSpec.describe Form, type: :model do end describe "next_incomplete_section_redirect_path" do - let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) } + let(:lettings_log) { FactoryBot.build_stubbed(:lettings_log, :in_progress) } let(:subsection) { form.get_subsection("household_characteristics") } let(:later_subsection) { form.get_subsection("declaration") } diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index 8b7783d36..3bf73bf44 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -46,6 +46,25 @@ RSpec.describe LettingsLog, type: :model do end describe "deriving vacant days" do + it "correctly derives vacdays from startdate and mrcdate across DST boundaries" do + log.startdate = Time.zone.local(2024, 4, 1) + log.mrcdate = Time.zone.local(2024, 3, 30) + + log.set_derived_fields! + + expect(log.vacdays).to be 2 + end + + it "correctly derives vacdays from startdate and voiddate across DST boundaries" do + log.startdate = Time.zone.local(2024, 4, 1) + log.mrcdate = nil + log.voiddate = Time.zone.local(2024, 3, 30) + + log.set_derived_fields! + + expect(log.vacdays).to be 2 + end + it "correctly derives vacdays from startdate and mrcdate" do day_count = 8 log.startdate = Time.zone.today diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 9e77c45e1..cb112aeff 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1915,7 +1915,7 @@ RSpec.describe LettingsLog do end context "when setup section has been completed" do - let(:lettings_log) { build(:lettings_log, :setup_completed) } + let(:lettings_log) { build_stubbed(:lettings_log, :setup_completed) } it "returns true" do expect(lettings_log).to be_non_location_setup_questions_completed @@ -1923,7 +1923,7 @@ RSpec.describe LettingsLog do end context "when the declaration has not been completed for a 2024 log" do - let(:lettings_log) { build(:lettings_log, :setup_completed, startdate: Time.utc(2024, 10, 1), declaration: nil) } + let(:lettings_log) { build_stubbed(:lettings_log, :setup_completed, startdate: Time.utc(2024, 10, 1), declaration: nil) } it "returns false" do expect(lettings_log).not_to be_non_location_setup_questions_completed @@ -1931,7 +1931,7 @@ RSpec.describe LettingsLog do end context "when an optional question has not been completed" do - let(:lettings_log) { build(:lettings_log, :setup_completed, propcode: nil) } + let(:lettings_log) { build_stubbed(:lettings_log, :setup_completed, propcode: nil) } it "returns true" do expect(lettings_log).to be_non_location_setup_questions_completed @@ -1939,7 +1939,7 @@ RSpec.describe LettingsLog do end context "when scheme and location have not been completed" do - let(:lettings_log) { build(:lettings_log, :setup_completed, :sh, scheme_id: nil, location_id: nil) } + let(:lettings_log) { build_stubbed(:lettings_log, :setup_completed, :sh, scheme_id: nil, location_id: nil) } it "returns true" do expect(lettings_log).to be_non_location_setup_questions_completed diff --git a/spec/models/log_spec.rb b/spec/models/log_spec.rb index 73533f881..21ff2849d 100644 --- a/spec/models/log_spec.rb +++ b/spec/models/log_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Log, type: :model do describe "#blank_invalid_non_setup_fields!" do context "when a setup field is invalid for a lettings log" do - subject(:model) { build(:lettings_log, needstype: 404) } + subject(:model) { build_stubbed(:lettings_log, needstype: 404) } it "does not blank it" do model.valid? @@ -39,7 +39,7 @@ RSpec.describe Log, type: :model do end context "when a setup field is invalid for a sales log" do - subject(:model) { build(:sales_log, companybuy: 404) } + subject(:model) { build_stubbed(:sales_log, companybuy: 404) } it "does not blank it" do model.valid? @@ -48,7 +48,7 @@ RSpec.describe Log, type: :model do end context "when a non setup field is invalid for a lettings log" do - subject(:model) { build(:lettings_log, :completed, startdate: Time.zone.local(2023, 12, 12), offered: 234) } + subject(:model) { build_stubbed(:lettings_log, :completed, startdate: Time.zone.local(2023, 12, 12), offered: 234) } it "blanks it" do model.valid? @@ -58,7 +58,7 @@ RSpec.describe Log, type: :model do end context "when a non setup field is invalid for a sales log" do - subject(:model) { build(:sales_log, :completed, age1: 10) } + subject(:model) { build_stubbed(:sales_log, :completed, age1: 10) } it "blanks it" do model.valid? @@ -68,7 +68,7 @@ RSpec.describe Log, type: :model do end context "when prevloc is invalid for a lettings log" do - subject(:model) { build(:lettings_log, :completed, previous_la_known: 1, prevloc: nil) } + subject(:model) { build_stubbed(:lettings_log, :completed, previous_la_known: 1, prevloc: nil) } it "blanks previous_la_known" do model.valid? @@ -78,7 +78,7 @@ RSpec.describe Log, type: :model do end context "when hhmemb is invalid for a lettings log" do - subject(:model) { build(:lettings_log, :setup_completed, hhmemb: 1, joint: 1) } + subject(:model) { build_stubbed(:lettings_log, :setup_completed, hhmemb: 1, joint: 1) } it "does not blank it" do model.valid? diff --git a/spec/request_helper.rb b/spec/request_helper.rb index d7de32b37..57765d131 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -86,8 +86,12 @@ module RequestHelper WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1234567890123") .to_return(status: 404, body: "", headers: {}) - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query=Address%20line%201,%20SW1A%201AA") - .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result address line 1", POST_TOWN: "result town or city", POSTCODE: "AA1 1AA", UPRN: "1" } }] }.to_json, headers: {}) + template = Addressable::Template.new "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query={+address_query}" + WebMock.stub_request(:get, template) + .to_return do |request| + address = request.uri.query_values["query"].split(",") + { status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result #{address[0]}", POST_TOWN: "result town or city", POSTCODE: address[1], UPRN: "1" } }] }.to_json, headers: {} } + end end def self.real_http_requests diff --git a/spec/services/csv/lettings_log_csv_service_spec.rb b/spec/services/csv/lettings_log_csv_service_spec.rb index 9fd8015dd..d59aa4406 100644 --- a/spec/services/csv/lettings_log_csv_service_spec.rb +++ b/spec/services/csv/lettings_log_csv_service_spec.rb @@ -1,54 +1,8 @@ require "rails_helper" RSpec.describe Csv::LettingsLogCsvService do - before do - Timecop.freeze(now) - Singleton.__init__(FormHandler) - FormHandler.instance.use_real_forms! - log.irproduct = 1 - log.save!(validate: false) - end - - after do - Timecop.return - end - context "when downloading a csv" do - let(:form_handler_mock) { instance_double(FormHandler) } - let(:organisation) { create(:organisation) } - let(:fixed_time) { Time.zone.local(2023, 11, 26) } - let(:now) { Time.zone.now } - let(:log) do - create( - :lettings_log, - :completed, - startdate: fixed_time, - created_at: fixed_time, - updated_at: now, - mrcdate: fixed_time - 1.day, - voiddate: fixed_time - 2.days, - propcode: "ABCDEFG", - tenancycode: "HIJKLMN", - postcode_full: "NW9 5LL", - ppostcode_full: "TN23 6LZ", - assigned_to: user, - managing_organisation: organisation, - hhmemb: 4, - details_known_3: 1, - details_known_4: 0, - sex4: "R", - ecstat4: 10, - relat4: "R", - age4_known: 1, - incref: 0, - address_line1_as_entered: "address line 1 as entered", - address_line2_as_entered: "address line 2 as entered", - town_or_city_as_entered: "town or city as entered", - county_as_entered: "county as entered", - postcode_full_as_entered: "AB1 2CD", - la_as_entered: "la as entered", - ) - end + let(:log) { create(:lettings_log) } let(:user) { create(:user, :support, email: "s.port@jeemayle.com") } let(:service) { described_class.new(user:, export_type:, year:) } let(:export_type) { "labels" } @@ -67,6 +21,7 @@ RSpec.describe Csv::LettingsLogCsvService do end context "when stubbing :ordered_questions_for_year" do + let(:form_handler_mock) { instance_double(FormHandler) } let(:lettings_form) do FormFactory.new(year: 2050, type: "lettings") .with_sections([build(:section, :with_questions, question_ids:, questions:)]) @@ -81,6 +36,7 @@ RSpec.describe Csv::LettingsLogCsvService do allow(form_handler_mock).to receive(:form_name_from_start_year) allow(form_handler_mock).to receive(:get_form).and_return(lettings_form) allow(form_handler_mock).to receive(:ordered_questions_for_year).and_return(lettings_form.questions) + allow(form_handler_mock).to receive(:lettings_in_crossover_period?).and_return(true) end it "calls the form handler to get all questions for the specified year" do @@ -145,6 +101,7 @@ RSpec.describe Csv::LettingsLogCsvService do context "when exporting with human readable labels" do let(:export_type) { "labels" } + let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } it "gives answer to radio questions as labels" do relat2_column_index = csv.first.index("relat2") @@ -170,56 +127,16 @@ RSpec.describe Csv::LettingsLogCsvService do expect(la_label_value).to eq "Barnet" end - context "when the requested form is 2024" do - let(:year) { 2024 } - let(:now) { Time.zone.local(2024, 4, 1) } - let(:fixed_time) { Time.zone.local(2024, 4, 1) } - - before do - log.update!(nationality_all: 36) - end - - it "exports the CSV with 2024 ordering and all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_24.csv") - values_to_delete = %w[id vacdays] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the requested form is 2023" do - let(:year) { 2023 } - let(:now) { Time.zone.local(2023, 11, 26) } - - it "exports the CSV with 2023 ordering and all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv") - values_to_delete = %w[id vacdays] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the log has a duplicate log reference" do - before do - log.update!(duplicate_set_id: 12_312) - end - - it "exports the id for under the heading 'duplicate_set_id'" do - duplicate_set_id_column_index = csv.first.index("duplicate_set_id") - duplicate_set_id_value = csv.second[duplicate_set_id_column_index] - expect(duplicate_set_id_value).to eq "12312" - end + it "exports the id for under the heading 'duplicate_set_id'" do + duplicate_set_id_column_index = csv.first.index("duplicate_set_id") + duplicate_set_id_value = csv.second[duplicate_set_id_column_index] + expect(duplicate_set_id_value).to eq "12312" end end context "when exporting as codes" do let(:export_type) { "codes" } + let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } it "gives answer to radio questions as labels" do relat2_column_index = csv.first.index("relat2") @@ -245,120 +162,399 @@ RSpec.describe Csv::LettingsLogCsvService do expect(la_label_value).to eq "Barnet" end - context "when the requested form is 2024" do - let(:year) { 2024 } - let(:now) { Time.zone.local(2024, 4, 1) } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_24.csv") - values_to_delete = %w[id vacdays] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the requested form is 2023" do - let(:year) { 2023 } - let(:now) { Time.zone.local(2023, 11, 26) } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv") - values_to_delete = %w[id vacdays] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the log has a duplicate log reference" do - before do - log.update!(duplicate_set_id: 12_312) - end - - it "exports the id for under the heading 'duplicate_set_id'" do - duplicate_set_id_column_index = csv.first.index("duplicate_set_id") - duplicate_set_id_value = csv.second[duplicate_set_id_column_index] - expect(duplicate_set_id_value).to eq "12312" - end + it "exports the duplicate log reference under the heading 'duplicate_set_id'" do + duplicate_set_id_column_index = csv.first.index("duplicate_set_id") + duplicate_set_id_value = csv.second[duplicate_set_id_column_index] + expect(duplicate_set_id_value).to eq "12312" end end context "when the user is not a support user" do - let(:user) { create(:user, email: "choreographer@owtluk.com") } + let(:user) { create(:user, :data_coordinator, email: "choreographer@owtluk.com") } it "does not include certain attributes in the headers" do expect(headers).not_to include(*%w[wrent wscharge wpschrge wsupchrg wtcharge]) end + end - context "and the requested form is 2024" do + describe "the full CSV output" do + context "when the requested log year is 2024" do let(:year) { 2024 } - let(:now) { Time.zone.local(2024, 4, 1) } - let(:fixed_time) { Time.zone.local(2024, 4, 1) } + let(:organisation) { create(:organisation, provider_type: "LA") } + let(:log) do + create( + :lettings_log, + :ignore_validation_errors, + created_by: user, + assigned_to: user, + created_at: Time.zone.local(2024, 4, 1), + updated_at: Time.zone.local(2024, 4, 1), + owning_organisation: organisation, + managing_organisation: organisation, + needstype: 1, + renewal: 0, + startdate: Time.zone.local(2024, 4, 1), + rent_type: 1, + tenancycode: "HIJKLMN", + propcode: "ABCDEFG", + declaration: 1, + address_line1: "Address line 1", + town_or_city: "London", + postcode_full: "NW9 5LL", + la: "E09000003", + is_la_inferred: false, + address_line1_as_entered: "address line 1 as entered", + address_line2_as_entered: "address line 2 as entered", + town_or_city_as_entered: "town or city as entered", + county_as_entered: "county as entered", + postcode_full_as_entered: "AB1 2CD", + la_as_entered: "la as entered", + first_time_property_let_as_social_housing: 0, + unitletas: 2, + rsnvac: 6, + unittype_gn: 7, + builtype: 1, + wchair: 1, + beds: 3, + voiddate: Time.zone.local(2024, 3, 30), + majorrepairs: 1, + mrcdate: Time.zone.local(2024, 3, 31), + joint: 3, + startertenancy: 1, + tenancy: 4, + tenancylength: 2, + hhmemb: 4, + age1_known: 0, + age1: 35, + sex1: "F", + ethnic_group: 0, + ethnic: 2, + nationality_all: 36, + ecstat1: 0, + details_known_2: 0, + relat2: "P", + age2_known: 0, + age2: 32, + sex2: "M", + ecstat2: 6, + details_known_3: 1, + details_known_4: 0, + relat4: "R", + age4_known: 1, + sex4: "R", + ecstat4: 10, + armedforces: 1, + leftreg: 4, + reservist: 1, + preg_occ: 2, + housingneeds: 1, + housingneeds_type: 0, + housingneeds_a: 1, + housingneeds_b: 0, + housingneeds_c: 0, + housingneeds_f: 0, + housingneeds_g: 0, + housingneeds_h: 0, + housingneeds_other: 0, + illness: 1, + illness_type_1: 0, + illness_type_2: 1, + illness_type_3: 0, + illness_type_4: 0, + illness_type_5: 0, + illness_type_6: 0, + illness_type_7: 0, + illness_type_8: 0, + illness_type_9: 0, + illness_type_10: 0, + layear: 2, + waityear: 7, + reason: 4, + prevten: 6, + homeless: 1, + ppcodenk: 1, + ppostcode_full: "TN23 6LZ", + previous_la_known: 1, + prevloc: "E07000105", + reasonpref: 1, + rp_homeless: 0, + rp_insan_unsat: 1, + rp_medwel: 0, + rp_hardship: 0, + rp_dontknow: 0, + cbl: 0, + chr: 1, + cap: 0, + accessible_register: 0, + referral: 2, + net_income_known: 0, + incref: 0, + incfreq: 1, + earnings: 268, + hb: 6, + has_benefits: 1, + benefits: 1, + period: 2, + brent: 200, + scharge: 50, + pscharge: 40, + supcharg: 35, + tcharge: 325, + hbrentshortfall: 1, + tshortfall_known: 1, + tshortfall: 12, + ) + end - context "and exporting with labels" do + context "when exporting with human readable labels" do let(:export_type) { "labels" } - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil + context "when the current user is a support user" do + let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } + + it "exports the CSV with 2024 ordering and all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_24.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content + end + end + + context "when the current user is not a support user" do + let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content end - expect(csv).to eq expected_content end end - context "and exporting values as codes" do + context "when exporting values as codes" do let(:export_type) { "codes" } - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil + context "when the current user is a support user" do + let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_24.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content + end + end + + context "when the current user is not a support user" do + let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content end - expect(csv).to eq expected_content end end end - context "and the requested form is 2023" do + context "when the requested log year is 2023" do let(:year) { 2023 } - let(:now) { Time.zone.local(2023, 11, 26) } - let(:fixed_time) { Time.zone.local(2023, 11, 26) } + let(:organisation) { create(:organisation, provider_type: "LA") } + let(:log) do + create( + :lettings_log, + :ignore_validation_errors, + created_by: user, + assigned_to: user, + created_at: Time.zone.local(2023, 11, 26), + updated_at: Time.zone.local(2023, 11, 26), + owning_organisation: organisation, + managing_organisation: organisation, + needstype: 1, + renewal: 0, + startdate: Time.zone.local(2023, 11, 26), + rent_type: 1, + tenancycode: "HIJKLMN", + propcode: "ABCDEFG", + declaration: 1, + address_line1: "Address line 1", + town_or_city: "London", + postcode_full: "NW9 5LL", + la: "E09000003", + is_la_inferred: false, + first_time_property_let_as_social_housing: 0, + unitletas: 2, + rsnvac: 6, + offered: 2, + unittype_gn: 7, + builtype: 1, + wchair: 1, + beds: 3, + voiddate: Time.zone.local(2023, 11, 24), + majorrepairs: 1, + mrcdate: Time.zone.local(2023, 11, 25), + joint: 3, + startertenancy: 1, + tenancy: 4, + tenancylength: 2, + hhmemb: 4, + age1_known: 0, + age1: 35, + sex1: "F", + ethnic_group: 0, + ethnic: 2, + national: 13, + ecstat1: 0, + details_known_2: 0, + relat2: "P", + age2_known: 0, + age2: 32, + sex2: "M", + ecstat2: 6, + details_known_3: 1, + details_known_4: 0, + relat4: "R", + age4_known: 1, + sex4: "R", + ecstat4: 10, + armedforces: 1, + leftreg: 4, + reservist: 1, + preg_occ: 2, + housingneeds: 1, + housingneeds_type: 0, + housingneeds_a: 1, + housingneeds_b: 0, + housingneeds_c: 0, + housingneeds_f: 0, + housingneeds_g: 0, + housingneeds_h: 0, + housingneeds_other: 0, + illness: 1, + illness_type_1: 0, + illness_type_2: 1, + illness_type_3: 0, + illness_type_4: 0, + illness_type_5: 0, + illness_type_6: 0, + illness_type_7: 0, + illness_type_8: 0, + illness_type_9: 0, + illness_type_10: 0, + layear: 2, + waityear: 7, + reason: 4, + prevten: 6, + homeless: 1, + ppcodenk: 1, + ppostcode_full: "TN23 6LZ", + previous_la_known: 1, + prevloc: "E07000105", + reasonpref: 1, + rp_homeless: 0, + rp_insan_unsat: 1, + rp_medwel: 0, + rp_hardship: 0, + rp_dontknow: 0, + cbl: 0, + chr: 1, + cap: 0, + accessible_register: 0, + referral: 2, + net_income_known: 0, + incref: 0, + incfreq: 1, + earnings: 268, + hb: 6, + has_benefits: 1, + benefits: 1, + period: 2, + brent: 200, + scharge: 50, + pscharge: 40, + supcharg: 35, + tcharge: 325, + hbrentshortfall: 1, + tshortfall_known: 1, + tshortfall: 12, + ) + end - context "and exporting with labels" do + context "when exporting with human readable labels" do let(:export_type) { "labels" } - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil + context "when the current user is a support user" do + let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content + end + end + + context "when the current user is not a support user" do + let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content end - expect(csv).to eq expected_content end end - context "and exporting values as codes" do + context "when exporting values as codes" do let(:export_type) { "codes" } - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = csv.first.index(attribute) - csv.second[index] = nil + context "when the current user is a support user" do + let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content + end + end + + context "when the current user is not a support user" do + let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv") + values_to_delete = %w[id] + values_to_delete.each do |attribute| + index = csv.first.index(attribute) + csv.second[index] = nil + end + expect(csv).to eq expected_content end - expect(csv).to eq expected_content end end end