diff --git a/app/services/exports/lettings_log_export_constants.rb b/app/services/exports/lettings_log_export_constants.rb index 9d84519f2..efae33dcb 100644 --- a/app/services/exports/lettings_log_export_constants.rb +++ b/app/services/exports/lettings_log_export_constants.rb @@ -138,7 +138,9 @@ module Exports::LettingsLogExportConstants "location_status", "created_by", "amended_by", - "duplicate_set_id" + "duplicate_set_id", + "accessible_register", + "nationality_all" ] (1..8).each do |index| @@ -155,4 +157,14 @@ module Exports::LettingsLogExportConstants %w[a b c d e f g h].each do |letter| EXPORT_FIELDS << "housingneeds_#{letter}" end + + POST_2024_EXPORT_FIELDS = Set[ + "accessible_register", + "nationality_all" + ] + + PRE_2024_EXPORT_FIELDS = Set[ + "national", + "offered" + ] end diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index e63219f7d..7da3906e5 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -193,6 +193,7 @@ module Exports attribute_hash["cbl"] = 2 if attribute_hash["cbl"]&.zero? attribute_hash["cap"] = 2 if attribute_hash["cap"]&.zero? attribute_hash["chr"] = 2 if attribute_hash["chr"]&.zero? + attribute_hash["accessible_register"] = 2 if attribute_hash["accessible_register"]&.zero? # Age refused (1..8).each do |index| @@ -258,12 +259,14 @@ module Exports attributes.reject! { |attribute| is_omitted_field?(attribute) } end - def is_omitted_field?(field_name) + def is_omitted_field?(field_name, lettings_log) pattern_age = /age\d_known/ details_known_prefix = "details_known_" field_name.starts_with?(details_known_prefix) || pattern_age.match(field_name) || - !EXPORT_FIELDS.include?(field_name) + !EXPORT_FIELDS.include?(field_name) || + (lettings_log.form.start_year_after_2024? && PRE_2024_EXPORT_FIELDS.include?(field_name)) || + (!lettings_log.form.start_year_after_2024? && POST_2024_EXPORT_FIELDS.include?(field_name)) end def build_export_xml(lettings_logs) @@ -274,7 +277,7 @@ module Exports form = doc.create_element("form") doc.at("forms") << form attribute_hash.each do |key, value| - if is_omitted_field?(key) + if is_omitted_field?(key, lettings_log) next else form << doc.create_element(key, value) diff --git a/spec/fixtures/exports/general_needs_log_24_25.xml b/spec/fixtures/exports/general_needs_log_24_25.xml new file mode 100644 index 000000000..488167b55 --- /dev/null +++ b/spec/fixtures/exports/general_needs_log_24_25.xml @@ -0,0 +1,164 @@ + + +
+ 1 + BZ737 + 35 + F + 2 + 6 + 0 + 2 + 32 + M + 6 + + + + + + + + + + + + + + + + + + + 1 + 4 + 4 + 1 + 1 + 2 + 1 + 5 + 4 + A1 1AA + 6 + 7 + 3 + 1 + 268 + 1 + 1 + 2 + 2 + 7 + SE2 6RT + 1 + 2 + 1 + 2 + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + + + 4 + 123 + E09000003 + E07000105 + 6 + 1 + 2022-05-05T10:36:49+01:00 + 0 + 2024-04-02T10:36:49+01:00 + 1 + 2 + 1 + 2021-11-03T00:00:00+00:00 + 2 + 1 + 7 + 0 + 0 + 2 + 0 + 2 + 200.0 + 50.0 + 40.0 + 35.0 + 325.0 + 12.0 + + 0 + 1 + 0 + 100.0 + 25.0 + 20.0 + 17.5 + 162.5 + 6.0 + 0 + 1 + + 2 + P + + + + + + + 2 + + 3 + + 4 + 2 + 698 + + 0 + + fake address + + London + + + 1 + + + 2 + {id} + {owning_org_id} + DLUHC + 1234 + {managing_org_id} + DLUHC + 1234 + 2024-04-03T00:00:00+01:00 + 2024-04-03T00:00:00+01:00 + {log_id} + test1@example.com + + 2 + 1 + +
diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index 65a41df26..6141207d1 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/spec/services/exports/lettings_log_export_service_spec.rb @@ -459,6 +459,36 @@ RSpec.describe Exports::LettingsLogExportService do export_service.export_xml_lettings_logs end end + + context "with 24/25 collection period" do + before do + Timecop.freeze(Time.zone.local(2024, 4, 3)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.unfreeze + Singleton.__init__(FormHandler) + end + + context "and one lettings log is available for export" do + let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, created_by: user, ppostcode_full: "A1 1AA", nationality_all_group: 13, propcode: "123", postcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2024, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) } + let(:expected_zip_filename) { "core_2024_2025_apr_mar_f0001_inc0001.zip" } + let(:expected_data_filename) { "core_2024_2025_apr_mar_f0001_inc0001_pt001.xml" } + let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_24_25.xml", "r:UTF-8") } + + it "generates an XML export file with the expected content within the ZIP file" do + expected_content = replace_entity_ids(lettings_log, xml_export_file.read) + expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content| + entry = Zip::File.open_buffer(content).find_entry(expected_data_filename) + expect(entry).not_to be_nil + expect(entry.get_input_stream.read).to eq(expected_content) + end + + export_service.export_xml_lettings_logs + end + end + end end context "when exporting a supported housing lettings logs in XML" do