From 94975fc6476c1736395fd7f5d9e7f8eedfb97950 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 16 May 2024 13:34:58 +0100 Subject: [PATCH] CLDC-3348 Update sales CSV for support (#2407) * Update sales csv for support * CLDC-3352 Update sales CSV address order (#2410) * Update sales support csv address ordering * Refactor * CLDC-3367 Rename sales support CSV fields (#2413) * Rename sales support CSV fields * Update sales CSV user fields order (#2416) --- app/services/csv/sales_log_csv_service.rb | 127 +++++++++++++++--- .../files/sales_logs_csv_export_codes_23.csv | 4 +- .../files/sales_logs_csv_export_codes_24.csv | 4 +- .../files/sales_logs_csv_export_labels_23.csv | 4 +- .../files/sales_logs_csv_export_labels_24.csv | 4 +- ..._logs_csv_export_non_support_labels_24.csv | 2 + .../csv/sales_log_csv_service_spec.rb | 85 ++++++++---- 7 files changed, 175 insertions(+), 55 deletions(-) create mode 100644 spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index 6aac5756f..61bef2972 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -9,7 +9,7 @@ module Csv def prepare_csv(logs) CSV.generate(headers: true) do |csv| - csv << @attributes + csv << formatted_attribute_headers logs.find_each do |log| csv << @attributes.map { |attribute| value(attribute, log) } @@ -56,6 +56,10 @@ module Csv labels: %i[creation_method], codes: %i[creation_method_before_type_cast], }, + mscharge_value_check: { + labels: %i[monthly_charges_value_check], + codes: %i[monthly_charges_value_check], + }, }.freeze PERSON_DETAILS = {}.tap { |hash| @@ -83,6 +87,8 @@ module Csv updated_at ].freeze + ORDERED_ADDRESS_FIELDS = %w[uprn address_line1 address_line2 town_or_city county postcode_full is_la_inferred la_label la 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].freeze + def value(attribute, log) if CUSTOM_CALL_CHAINS.key? attribute.to_sym call_chain = CUSTOM_CALL_CHAINS[attribute.to_sym][@export_type.to_sym] @@ -95,7 +101,7 @@ module Csv get_label(value, attribute, log) elsif SYSTEM_DATE_FIELDS.include? attribute log.public_send(attribute)&.iso8601 - elsif PERSON_DETAILS.any? { |key, _value| key == attribute } && (person_details_not_known?(log, attribute) || age_not_known?(log, attribute)) + elsif PERSON_DETAILS.key?(attribute) && (person_details_not_known?(log, attribute) || age_not_known?(log, attribute)) case @export_type when "codes" PERSON_DETAILS.find { |key, _value| key == attribute }[1]["refused_code"] @@ -125,20 +131,80 @@ module Csv return "No" if value == false end - ATTRIBUTE_MAPPINGS = { - "saledate" => %w[day month year], - "exdate" => %w[exday exmonth exyear], - "hodate" => %w[hoday homonth hoyear], - "postcode_full" => %w[pcode1 pcode2], - "ppostcode_full" => %w[ppostc1 ppostc2], - "la" => %w[la la_label], - "prevloc" => %w[prevloc prevloc_label], - "assigned_to_id" => %w[assigned_to], - "owning_organisation_id" => %w[owning_organisation_name], - "managing_organisation_id" => %w[managing_organisation_name], - }.freeze + def attribute_mappings + mappings = { + "saledate" => %w[day month year], + "exdate" => %w[exday exmonth exyear], + "hodate" => %w[hoday homonth hoyear], + "ppostcode_full" => %w[ppostc1 ppostc2], + "la" => %w[la la_label], + "prevloc" => %w[prevloc prevloc_label], + "assigned_to_id" => %w[created_by assigned_to], + "owning_organisation_id" => %w[owning_organisation_name], + "managing_organisation_id" => %w[managing_organisation_name], + "value" => %w[value value_value_check], + "mscharge" => %w[mscharge mscharge_value_check], + } + unless @user.support? && @year >= 2024 + mappings["postcode_full"] = %w[pcode1 pcode2] + end + mappings + end + + SUPPORT_ONLY_ATTRIBUTES = %w[address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered created_by value_value_check mscharge_value_check].freeze - SUPPORT_ONLY_ATTRIBUTES = %w[address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered created_by].freeze + SUPPORT_ATTRIBUTE_NAME_MAPPINGS = { + "duplicate_set_id" => "DUPLICATESET", + "bulk_upload_id" => "BULKUPLOADID", + "created_at" => "CREATEDDATE", + "updated_at" => "UPLOADDATE", + "old_form_id" => "FORM", + "collection_start_year" => "COLLECTIONYEAR", + "creation_method" => "CREATIONMETHOD", + "is_dpo" => "DATAPROTECT", + "created_by" => "CREATEDBY", + "owning_organisation_name" => "OWNINGORGNAME", + "managing_organisation_name" => "MANINGORGNAME", + "assigned_to" => "USERNAME", + "ownershipsch" => "OWNERSHIP", + "companybuy" => "COMPANY", + "buylivein" => "LIVEINBUYER", + "jointpur" => "JOINT", + "address_line1" => "ADDRESS1", + "address_line2" => "ADDRESS2", + "town_or_city" => "TOWNCITY", + "postcode_full" => "POSTCODE", + "is_la_inferred" => "ISLAINFERRED", + "la_label" => "LANAME", + "uprn_selection" => "UPRNSELECTED", + "address_line1_input" => "ADDRESS1INPUT", + "postcode_full_input" => "POSTCODEINPUT", + "address_line1_as_entered" => "BULKADDRESS1", + "address_line2_as_entered" => "BULKADDRESS2", + "town_or_city_as_entered" => "BULKTOWNCITY", + "county_as_entered" => "BULKCOUNTY", + "postcode_full_as_entered" => "BULKPOSTCODE", + "la_as_entered" => "BULKLA", + "ethnic_group" => "ETHNICGROUP1", + "nationality_all" => "NATIONALITYALL1", + "buy1livein" => "LIVEINBUYER1", + "ethnic_group2" => "ETHNICGROUP2", + "ethnicbuy2" => "ETHNIC2", + "nationality_all_buyer2" => "NATIONALITYALL2", + "buy2livein" => "LIVEINBUYER2", + "hholdcount" => "HHTYPE", + "previous_la_known" => "PREVIOUSLAKNOWN", + "prevloc_label" => "PREVLOCNAME", + "prevtenbuy2" => "PREVTEN2", + "income1nk" => "INC1NK", + "income2nk" => "INC2NK", + "staircasesale" => "STAIRCASETOSALE", + "soctenant" => "SOCTEN", + "mortlen" => "MORTLEN1", + "has_mscharge" => "HASMSCHARGE", + "nationalbuy2" => "NATIONAL2", + "uprn_confirmed" => "UPRNCONFIRMED", + }.freeze def sales_log_attributes ordered_questions = FormHandler.instance.ordered_questions_for_year(@year, "sales") @@ -146,12 +212,19 @@ module Csv attributes = ordered_questions.flat_map do |question| if question.type == "checkbox" question.answer_options.keys - elsif ATTRIBUTE_MAPPINGS.key? question.id - ATTRIBUTE_MAPPINGS[question.id] + elsif attribute_mappings.key? question.id + attribute_mappings[question.id] else question.id end end + if @user.support? && @year >= 2024 + first_address_field_index = attributes.find_index { |q| all_address_fields.include?(q) } + if first_address_field_index + attributes.reject! { |q| all_address_fields.include?(q) } + attributes.insert(first_address_field_index, *ORDERED_ADDRESS_FIELDS) + end + end final_attributes = non_question_fields + attributes @user.support? ? final_attributes : final_attributes - SUPPORT_ONLY_ATTRIBUTES end @@ -169,13 +242,25 @@ module Csv def non_question_fields case @year when 2022 - %w[id status created_at updated_at old_form_id collection_start_year creation_method is_dpo created_by] + %w[id status created_at updated_at old_form_id collection_start_year creation_method is_dpo] when 2023 - %w[id status duplicate_set_id created_at updated_at old_form_id collection_start_year creation_method is_dpo created_by] + %w[id status duplicate_set_id created_at updated_at old_form_id collection_start_year creation_method is_dpo] when 2024 - %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered created_by] + %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo] else - %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered created_by] + %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo] + end + end + + def all_address_fields + ORDERED_ADDRESS_FIELDS + %w[uprn_confirmed] + end + + def formatted_attribute_headers + return @attributes unless @user.support? + + @attributes.map do |attribute| + SUPPORT_ATTRIBUTE_NAME_MAPPINGS[attribute] || attribute.upcase end end end diff --git a/spec/fixtures/files/sales_logs_csv_export_codes_23.csv b/spec/fixtures/files/sales_logs_csv_export_codes_23.csv index aedc0e57d..ad22b82c7 100644 --- a/spec/fixtures/files/sales_logs_csv_export_codes_23.csv +++ b/spec/fixtures/files/sales_logs_csv_export_codes_23.csv @@ -1,2 +1,2 @@ -id,status,duplicate_set_id,created_at,updated_at,old_form_id,collection_start_year,creation_method,is_dpo,created_by,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,beds,proptype,builtype,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,wchair,noint,privacynotice,age1,sex1,ethnic_group,ethnic,national,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationalbuy2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant -,completed,,2023-12-08T00:00:00+00:00,2024-01-01T00:00:00+00:00,,2023,1,false,billyboy@eyeklaud.com,DLUHC,DLUHC,billyboy@eyeklaud.com,8,12,2023,,2,8,,,,1,1,2,1,1,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,1,2,1,30,X,17,17,18,1,1,P,35,X,17,,13,1,1,3,C,14,X,,X,-9,X,3,R,-9,R,10,,,,,1,1,,,0,,,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,10000.0 +ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,FORM,COLLECTIONYEAR,CREATIONMETHOD,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,BEDS,PROPTYPE,BUILTYPE,UPRN,UPRNCONFIRMED,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,PCODE1,PCODE2,LA,LANAME,WCHAIR,NOINT,PRIVACYNOTICE,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONAL,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONAL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT +,completed,,2023-12-08T00:00:00+00:00,2024-01-01T00:00:00+00:00,,2023,1,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,8,12,2023,,2,8,,,,1,1,2,1,1,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,1,2,1,30,X,17,17,18,1,1,P,35,X,17,,13,1,1,3,C,14,X,,X,-9,X,3,R,-9,R,10,,,,,1,1,,,0,,,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,,10000.0 diff --git a/spec/fixtures/files/sales_logs_csv_export_codes_24.csv b/spec/fixtures/files/sales_logs_csv_export_codes_24.csv index 7905aece9..f7c86872d 100644 --- a/spec/fixtures/files/sales_logs_csv_export_codes_24.csv +++ b/spec/fixtures/files/sales_logs_csv_export_codes_24.csv @@ -1,2 +1,2 @@ -id,status,duplicate_set_id,created_at,updated_at,collection_start_year,creation_method,bulk_upload_id,is_dpo,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,created_by,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,noint,privacynotice,uprn,uprn_confirmed,address_line1_input,postcode_full_input,uprn_selection,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,beds,proptype,builtype,wchair,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationality_all_buyer2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant -,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,1,,false,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,billyboy@eyeklaud.com,DLUHC,DLUHC,billyboy@eyeklaud.com,1,5,2024,,2,8,,,,1,1,2,1,,,,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,2,1,1,1,30,X,17,17,,1,1,P,35,X,17,,,1,1,3,C,14,X,9,X,-9,X,3,R,-9,R,10,,,,,1,0,SW1A,1AA,1,E09000003,Barnet,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,10000.0 +ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT +,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,1,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,2,8,,,,1,1,2,1,,Address line 1,,Town or city,,SW1A 1AA,false,Barnet,E09000003,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,1,1,1,30,X,17,17,,1,1,P,35,X,17,,,1,1,3,C,14,X,9,X,-9,X,3,R,-9,R,10,,,,,1,0,SW1A,1AA,1,E09000003,Barnet,1,1,1,1,,3,,1,4,5,1,1,0,10000,1,0,10000,1,4,1,,1,2,10,,,,,,,,,,,,,,,,,110000.0,,,1,20000.0,5,,10,1,80000.0,,,1,100.0,,,10000.0 diff --git a/spec/fixtures/files/sales_logs_csv_export_labels_23.csv b/spec/fixtures/files/sales_logs_csv_export_labels_23.csv index 320ed3ec6..04e3cafc1 100644 --- a/spec/fixtures/files/sales_logs_csv_export_labels_23.csv +++ b/spec/fixtures/files/sales_logs_csv_export_labels_23.csv @@ -1,2 +1,2 @@ -id,status,duplicate_set_id,created_at,updated_at,old_form_id,collection_start_year,creation_method,is_dpo,created_by,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,beds,proptype,builtype,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,wchair,noint,privacynotice,age1,sex1,ethnic_group,ethnic,national,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationalbuy2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant -,completed,,2023-12-08T00:00:00+00:00,2024-01-01T00:00:00+00:00,,2023,single log,false,billyboy@eyeklaud.com,DLUHC,DLUHC,billyboy@eyeklaud.com,8,12,2023,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,2,Flat or maisonette,Purpose built,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,Yes,Yes,1,30,Non-binary,Buyer prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,Buyer prefers not to say,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,No,,,No,,,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 +ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,FORM,COLLECTIONYEAR,CREATIONMETHOD,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,BEDS,PROPTYPE,BUILTYPE,UPRN,UPRNCONFIRMED,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,PCODE1,PCODE2,LA,LANAME,WCHAIR,NOINT,PRIVACYNOTICE,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONAL,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONAL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT +,completed,,2023-12-08T00:00:00+00:00,2024-01-01T00:00:00+00:00,,2023,single log,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,8,12,2023,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,2,Flat or maisonette,Purpose built,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,Yes,Yes,1,30,Non-binary,Buyer prefers not to say,17,United Kingdom,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,Buyer prefers not to say,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,No,,,No,,,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,,10000.0 diff --git a/spec/fixtures/files/sales_logs_csv_export_labels_24.csv b/spec/fixtures/files/sales_logs_csv_export_labels_24.csv index 939965d05..4feac3c6e 100644 --- a/spec/fixtures/files/sales_logs_csv_export_labels_24.csv +++ b/spec/fixtures/files/sales_logs_csv_export_labels_24.csv @@ -1,2 +1,2 @@ -id,status,duplicate_set_id,created_at,updated_at,collection_start_year,creation_method,bulk_upload_id,is_dpo,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,created_by,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,noint,privacynotice,uprn,uprn_confirmed,address_line1_input,postcode_full_input,uprn_selection,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,beds,proptype,builtype,wchair,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationality_all_buyer2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant -,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,billyboy@eyeklaud.com,DLUHC,DLUHC,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,,,,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,Australia,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,SW1A,1AA,Yes,E09000003,Barnet,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 +ID,STATUS,DUPLICATESET,CREATEDDATE,UPLOADDATE,COLLECTIONYEAR,CREATIONMETHOD,BULKUPLOADID,DATAPROTECT,OWNINGORGNAME,MANINGORGNAME,CREATEDBY,USERNAME,DAY,MONTH,YEAR,PURCHID,OWNERSHIP,TYPE,OTHTYPE,COMPANY,LIVEINBUYER,JOINT,JOINTMORE,NOINT,PRIVACYNOTICE,UPRN,ADDRESS1,ADDRESS2,TOWNCITY,COUNTY,POSTCODE,ISLAINFERRED,LANAME,LA,UPRNSELECTED,ADDRESS_SEARCH_VALUE_CHECK,ADDRESS1INPUT,POSTCODEINPUT,BULKADDRESS1,BULKADDRESS2,BULKTOWNCITY,BULKCOUNTY,BULKPOSTCODE,BULKLA,BEDS,PROPTYPE,BUILTYPE,WCHAIR,AGE1,SEX1,ETHNICGROUP1,ETHNIC,NATIONALITYALL1,ECSTAT1,LIVEINBUYER1,RELAT2,AGE2,SEX2,ETHNICGROUP2,ETHNIC2,NATIONALITYALL2,ECSTAT2,LIVEINBUYER2,HHTYPE,RELAT3,AGE3,SEX3,ECSTAT3,RELAT4,AGE4,SEX4,ECSTAT4,RELAT5,AGE5,SEX5,ECSTAT5,RELAT6,AGE6,SEX6,ECSTAT6,PREVTEN,PPCODENK,PPOSTC1,PPOSTC2,PREVIOUSLAKNOWN,PREVLOC,PREVLOCNAME,PREGYRHA,PREGOTHER,PREGLA,PREGGHB,PREGBLANK,BUY2LIVING,PREVTEN2,HHREGRES,HHREGRESSTILL,ARMEDFORCESSPOUSE,DISABLED,WHEEL,INC1NK,INCOME1,INC1MORT,INC2NK,INCOME2,INC2MORT,HB,SAVINGSNK,SAVINGS,PREVOWN,PREVSHARED,PROPLEN,STAIRCASE,STAIRBOUGHT,STAIROWNED,STAIRCASETOSALE,RESALE,EXDAY,EXMONTH,EXYEAR,HODAY,HOMONTH,HOYEAR,LANOMAGR,SOCTEN,FROMBEDS,FROMPROP,SOCPREVTEN,VALUE,VALUE_VALUE_CHECK,EQUITY,MORTGAGEUSED,MORTGAGE,MORTGAGELENDER,MORTGAGELENDEROTHER,MORTLEN1,EXTRABOR,DEPOSIT,CASHDIS,MRENT,HASMSCHARGE,MSCHARGE,MSCHARGE_VALUE_CHECK,DISCOUNT,GRANT +,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,,Address line 1,,Town or city,,SW1A 1AA,No,Barnet,E09000003,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,Australia,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,SW1A,1AA,Yes,E09000003,Barnet,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,,10000.0 diff --git a/spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv b/spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv new file mode 100644 index 000000000..2ca4deac7 --- /dev/null +++ b/spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv @@ -0,0 +1,2 @@ +id,status,duplicate_set_id,created_at,updated_at,collection_start_year,creation_method,bulk_upload_id,is_dpo,owning_organisation_name,managing_organisation_name,assigned_to,day,month,year,purchid,ownershipsch,type,othtype,companybuy,buylivein,jointpur,jointmore,noint,privacynotice,uprn,uprn_confirmed,address_line1_input,postcode_full_input,uprn_selection,address_line1,address_line2,town_or_city,county,pcode1,pcode2,la,la_label,beds,proptype,builtype,wchair,age1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,buy1livein,relat2,age2,sex2,ethnic_group2,ethnicbuy2,nationality_all_buyer2,ecstat2,buy2livein,hholdcount,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,prevten,ppcodenk,ppostc1,ppostc2,previous_la_known,prevloc,prevloc_label,pregyrha,pregother,pregla,pregghb,pregblank,buy2living,prevtenbuy2,hhregres,hhregresstill,armedforcesspouse,disabled,wheel,income1nk,income1,inc1mort,income2nk,income2,inc2mort,hb,savingsnk,savings,prevown,prevshared,proplen,staircase,stairbought,stairowned,staircasesale,resale,exday,exmonth,exyear,hoday,homonth,hoyear,lanomagr,soctenant,frombeds,fromprop,socprevten,value,equity,mortgageused,mortgage,mortgagelender,mortgagelenderother,mortlen,extrabor,deposit,cashdis,mrent,has_mscharge,mscharge,discount,grant +,in_progress,,2024-05-01T00:00:00+01:00,2024-05-01T00:00:00+01:00,2024,single log,,false,DLUHC,DLUHC,billyboy@eyeklaud.com,1,5,2024,,Yes - a discounted ownership scheme,Right to Acquire (RTA),,,,Yes,Yes,Yes,1,,,,,,Address line 1,,Town or city,,SW1A,1AA,E09000003,Barnet,2,Flat or maisonette,Purpose built,Yes,30,Non-binary,Buyer prefers not to say,17,Australia,Full-time - 30 hours or more,Yes,Partner,35,Non-binary,Buyer prefers not to say,,,Full-time - 30 hours or more,Yes,3,Child,14,Non-binary,Child under 16,Other,Not known,Non-binary,In government training into work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,,,,,Local authority tenant,Yes,SW1A,1AA,Yes,E09000003,Barnet,1,1,1,1,,Don't know,,Yes,Yes,No,Yes,Yes,Yes,10000,Yes,Yes,10000,Yes,Don’t know ,No,,Yes,No,10,,,,,,,,,,,,,,,,,110000.0,,Yes,20000.0,Cambridge Building Society,,10,Yes,80000.0,,,Yes,100.0,,10000.0 diff --git a/spec/services/csv/sales_log_csv_service_spec.rb b/spec/services/csv/sales_log_csv_service_spec.rb index 4cd056fe9..9c6176afd 100644 --- a/spec/services/csv/sales_log_csv_service_spec.rb +++ b/spec/services/csv/sales_log_csv_service_spec.rb @@ -52,7 +52,7 @@ RSpec.describe Csv::SalesLogCsvService do end it "returns a csv with headers" do - expect(csv.first.first).to eq "id" + expect(csv.first.first).to eq "ID" end context "when stubbing :ordered_questions_for_year" do @@ -84,13 +84,13 @@ RSpec.describe Csv::SalesLogCsvService do it "includes log attributes related to questions to the headers" do headers = csv.first - expect(headers).to include(*question_ids.first(3)) + expect(headers).to include(*%w[TYPE AGE1 LIVEINBUYER1]) end it "removes some log attributes related to questions from the headers and replaces them with their derived values in the correct order" do headers = csv.first - expect(headers).not_to include "exdate" - expect(headers.last(4)).to eq %w[buy1livein exday exmonth exyear] + expect(headers).not_to include "EXDATE" + expect(headers.last(4)).to eq %w[LIVEINBUYER1 EXDAY EXMONTH EXYEAR] end end @@ -115,14 +115,14 @@ RSpec.describe Csv::SalesLogCsvService do it "does not add the id of checkbox questions, but adds the related attributes of the log in the correct order" do headers = csv.first - expect(headers.last(4)).to eq %w[ownershipsch pregyrha pregother type] + expect(headers.last(4)).to eq %w[OWNERSHIP PREGYRHA PREGOTHER TYPE] end end end it "includes attributes not related to questions to the headers" do headers = csv.first - expect(headers).to include(*%w[id status created_at updated_at]) + expect(headers).to include(*%w[ID STATUS CREATEDDATE UPLOADDATE]) end it "returns a csv with the correct number of logs" do @@ -136,35 +136,35 @@ RSpec.describe Csv::SalesLogCsvService do let(:year) { 2023 } it "gives answers to radio questions as their labels" do - national_column_index = csv.first.index("national") + national_column_index = csv.first.index("NATIONAL") national_value = csv.second[national_column_index] expect(national_value).to eq "United Kingdom" - relat2_column_index = csv.first.index("relat2") + relat2_column_index = csv.first.index("RELAT2") relat2_value = csv.second[relat2_column_index] expect(relat2_value).to eq "Partner" end it "gives answers to free input questions as the user input" do - age1_column_index = csv.first.index("age1") + age1_column_index = csv.first.index("AGE1") age1_value = csv.second[age1_column_index] expect(age1_value).to eq 30.to_s postcode_part1, postcode_part2 = log.postcode_full.split - postcode_part1_column_index = csv.first.index("pcode1") + postcode_part1_column_index = csv.first.index("PCODE1") postcode_part1_value = csv.second[postcode_part1_column_index] expect(postcode_part1_value).to eq postcode_part1 - postcode_part2_column_index = csv.first.index("pcode2") + postcode_part2_column_index = csv.first.index("PCODE2") postcode_part2_value = csv.second[postcode_part2_column_index] expect(postcode_part2_value).to eq postcode_part2 end it "exports the code for the local authority under the heading 'la'" do - la_column_index = csv.first.index("la") + la_column_index = csv.first.index("LA") la_value = csv.second[la_column_index] expect(la_value).to eq "E09000003" end it "exports the label for the local authority under the heading 'la_label'" do - la_label_column_index = csv.first.index("la_label") + la_label_column_index = csv.first.index("LANAME") la_label_value = csv.second[la_label_column_index] expect(la_label_value).to eq "Barnet" end @@ -180,7 +180,7 @@ RSpec.describe Csv::SalesLogCsvService do it "exports the CSV with the 2024 ordering and all values correct" do expected_content = CSV.read("spec/fixtures/files/sales_logs_csv_export_labels_24.csv") - values_to_delete = %w[id] + values_to_delete = %w[ID] values_to_delete.each do |attribute| index = csv.first.index(attribute) csv.second[index] = nil @@ -195,7 +195,7 @@ RSpec.describe Csv::SalesLogCsvService do it "exports the CSV with the 2023 ordering and all values correct" do expected_content = CSV.read("spec/fixtures/files/sales_logs_csv_export_labels_23.csv") - values_to_delete = %w[id] + values_to_delete = %w[ID] values_to_delete.each do |attribute| index = csv.first.index(attribute) csv.second[index] = nil @@ -210,7 +210,7 @@ RSpec.describe Csv::SalesLogCsvService do 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_column_index = csv.first.index("DUPLICATESET") duplicate_set_id_value = csv.second[duplicate_set_id_column_index] expect(duplicate_set_id_value).to eq "12312" end @@ -222,35 +222,35 @@ RSpec.describe Csv::SalesLogCsvService do let(:year) { 2023 } it "gives answers to radio questions as their codes" do - national_column_index = csv.first.index("national") + national_column_index = csv.first.index("NATIONAL") national_value = csv.second[national_column_index] expect(national_value).to eq 18.to_s - relat2_column_index = csv.first.index("relat2") + relat2_column_index = csv.first.index("RELAT2") relat2_value = csv.second[relat2_column_index] expect(relat2_value).to eq "P" end it "gives answers to free input questions as the user input" do - age1_column_index = csv.first.index("age1") + age1_column_index = csv.first.index("AGE1") age1_value = csv.second[age1_column_index] expect(age1_value).to eq 30.to_s postcode_part1, postcode_part2 = log.postcode_full.split - postcode_part1_column_index = csv.first.index("pcode1") + postcode_part1_column_index = csv.first.index("PCODE1") postcode_part1_value = csv.second[postcode_part1_column_index] expect(postcode_part1_value).to eq postcode_part1 - postcode_part2_column_index = csv.first.index("pcode2") + postcode_part2_column_index = csv.first.index("PCODE2") postcode_part2_value = csv.second[postcode_part2_column_index] expect(postcode_part2_value).to eq postcode_part2 end it "exports the code for the local authority under the heading 'la'" do - la_column_index = csv.first.index("la") + la_column_index = csv.first.index("LA") la_value = csv.second[la_column_index] expect(la_value).to eq "E09000003" end it "exports the label for the local authority under the heading 'la_label'" do - la_label_column_index = csv.first.index("la_label") + la_label_column_index = csv.first.index("LANAME") la_label_value = csv.second[la_label_column_index] expect(la_label_value).to eq "Barnet" end @@ -262,7 +262,7 @@ RSpec.describe Csv::SalesLogCsvService do it "exports the CSV with all values correct" do expected_content = CSV.read("spec/fixtures/files/sales_logs_csv_export_codes_24.csv") - values_to_delete = %w[id] + values_to_delete = %w[ID] values_to_delete.each do |attribute| index = csv.first.index(attribute) csv.second[index] = nil @@ -277,7 +277,7 @@ RSpec.describe Csv::SalesLogCsvService do it "exports the CSV with all values correct" do expected_content = CSV.read("spec/fixtures/files/sales_logs_csv_export_codes_23.csv") - values_to_delete = %w[id] + values_to_delete = %w[ID] values_to_delete.each do |attribute| index = csv.first.index(attribute) csv.second[index] = nil @@ -292,10 +292,43 @@ RSpec.describe Csv::SalesLogCsvService do 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_column_index = csv.first.index("DUPLICATESET") duplicate_set_id_value = csv.second[duplicate_set_id_column_index] expect(duplicate_set_id_value).to eq "12312" end end end + + context "when the user is not a support user" do + let(:user) { create(:user, email: "billyboy@eyeklaud.com") } + let(:headers) { csv.first } + + it "does not include certain attributes in the headers" do + expect(headers).not_to include(*%w[address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered created_by value_value_check monthly_charges_value_check]) + end + + context "and the requested form is 2024" do + let(:year) { 2024 } + let(:now) { Time.zone.local(2024, 5, 1) } + let(:fixed_time) { Time.zone.local(2024, 5, 1) } + + before do + log.update!(nationality_all: 36) + end + + context "and exporting with labels" do + let(:export_type) { "labels" } + + it "exports the CSV with all values correct" do + expected_content = CSV.read("spec/fixtures/files/sales_logs_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 + end + end + end end