Browse Source

CLDC-3499: Start changes to lettings log export service

CLDC-3499-remove-pre-2025-tests
samyou-softwire 2 weeks ago
parent
commit
1edbc9ab8c
  1. 10
      app/models/form_handler.rb
  2. 10
      spec/fixtures/exports/general_needs_log.xml
  3. 113
      spec/services/exports/lettings_log_export_service_spec.rb

10
app/models/form_handler.rb

@ -122,11 +122,11 @@ class FormHandler
forms.delete("archived_lettings")
end
if Rails.env.test?
forms.merge({ fake_lettings_2021: Form.new("spec/fixtures/forms/2021_2022.json"), real_lettings_2021: Form.new("config/forms/2021_2022.json") })
else
forms
end
# if Rails.env.test?
# forms.merge({ fake_lettings_2021: Form.new("spec/fixtures/forms/2021_2022.json"), real_lettings_2021: Form.new("config/forms/2021_2022.json") })
# else
forms
# end
end
def lettings_form_for_start_year(year)

10
spec/fixtures/exports/general_needs_log.xml vendored

@ -87,13 +87,13 @@
<prevloc>E07000105</prevloc>
<hb>6</hb>
<hbrentshortfall>1</hbrentshortfall>
<mrcdate>2020-05-05T10:36:49+01:00</mrcdate>
<mrcdate>{mrcdate}</mrcdate>
<incref>0</incref>
<startdate>2022-02-02T10:36:49+00:00</startdate>
<startdate>{startdate}</startdate>
<armedforces>1</armedforces>
<unitletas>2</unitletas>
<builtype>1</builtype>
<voiddate>2019-11-03T00:00:00+00:00</voiddate>
<voiddate>{voiddate}</voiddate>
<renttype>2</renttype>
<needstype>1</needstype>
<lettype>7</lettype>
@ -152,8 +152,8 @@
<maningorgid>{managing_org_id}</maningorgid>
<maningorgname>{managing_org_name}</maningorgname>
<manhcnum>1234</manhcnum>
<createddate>2022-05-01T00:00:00+01:00</createddate>
<uploaddate>2022-05-01T00:00:00+01:00</uploaddate>
<createddate>{startdate}</createddate>
<uploaddate>{startdate}</uploaddate>
<log_id>{log_id}</log_id>
<assigned_to>test1@example.com</assigned_to>
<created_by>test1@example.com</created_by>

113
spec/services/exports/lettings_log_export_service_spec.rb

@ -10,13 +10,13 @@ RSpec.describe Exports::LettingsLogExportService do
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log.xml", "r:UTF-8") }
let(:local_manifest_file) { File.open("spec/fixtures/exports/manifest.xml", "r:UTF-8") }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json") }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json") }
# let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json") }
# let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json") }
let(:expected_zip_filename) { "core_2021_2022_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2021_2022_apr_mar_f0001_inc0001_pt001.xml" }
let(:expected_zip_filename) { "core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001_pt001.xml" }
let(:expected_manifest_filename) { "manifest.xml" }
let(:start_time) { Time.zone.local(2022, 5, 1) }
let(:start_time) { current_collection_start_date }
let(:organisation) { create(:organisation, name: "MHCLG", housing_registration_no: 1234) }
let(:user) { create(:user, email: "test1@example.com", organisation:) }
@ -29,6 +29,9 @@ RSpec.describe Exports::LettingsLogExportService do
export_template.sub!(/\{location_id\}/, lettings_log["location_id"].to_s) if lettings_log.needstype == 2
export_template.sub!(/\{scheme_id\}/, lettings_log["scheme_id"].to_s) if lettings_log.needstype == 2
export_template.sub!(/\{log_id\}/, lettings_log["id"].to_s)
export_template.sub!(/\{startdate\}/, lettings_log["startdate"].to_s)
export_template.sub!(/\{voiddate\}/, lettings_log["voiddate"].to_s)
export_template.sub!(/\{mrcdate\}/, lettings_log["mrcdate"].to_s)
end
def replace_record_number(export_template, record_number)
@ -41,9 +44,9 @@ RSpec.describe Exports::LettingsLogExportService do
allow(storage_service).to receive(:write_file)
# Stub the form handler to use the real form
allow(FormHandler.instance).to receive(:get_form).with("previous_lettings").and_return(real_2021_2022_form)
allow(FormHandler.instance).to receive(:get_form).with("current_lettings").and_return(real_2022_2023_form)
allow(FormHandler.instance).to receive(:get_form).with("next_lettings").and_return(real_2022_2023_form)
# allow(FormHandler.instance).to receive(:get_form).with("previous_lettings").and_return(real_2021_2022_form)
# allow(FormHandler.instance).to receive(:get_form).with("current_lettings").and_return(real_2022_2023_form)
# allow(FormHandler.instance).to receive(:get_form).with("next_lettings").and_return(real_2022_2023_form)
end
after do
@ -64,15 +67,6 @@ RSpec.describe Exports::LettingsLogExportService do
:lettings_log,
:completed,
status: "pending",
propcode: "123",
ppostcode_full: "SE2 6RT",
postcode_full: "NW1 5TY",
tenancycode: "BZ737",
startdate: Time.zone.local(2022, 2, 2, 10, 36, 49),
voiddate: Time.zone.local(2019, 11, 3),
mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49),
tenancylength: 5,
underoccupation_benefitcap: 4,
)
end
@ -127,7 +121,24 @@ RSpec.describe Exports::LettingsLogExportService do
end
context "and one lettings log with unknown user details is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, assigned_to: user, age1: 35, sex1: "F", sexrab1: nil, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
let!(:lettings_log) { FactoryBot.create(
:lettings_log,
:completed,
details_known_2: 1,
assigned_to: user,
age1: 35,
sex1: "F",
sexrab1: nil,
propcode: "123",
ppostcode_full: "SE2 6RT",
postcode_full: "NW1 5TY",
town_or_city: "London",
tenancycode: "BZ737",
startdate: Time.zone.local(current_collection, 2, 2, 10, 36, 49),
voiddate: Time.zone.local(2019, 11, 3),
mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49),
tenancylength: 5, underoccupation_benefitcap: 4)
}
def replace_person_details(export_file)
export_file.sub!("<age2>32</age2>", "<age2>-9</age2>")
@ -199,62 +210,66 @@ RSpec.describe Exports::LettingsLogExportService do
end
context "and multiple lettings logs are available for export on different periods" do
let(:expected_zip_filename2) { "core_2022_2023_apr_mar_f0001_inc0001.zip" }
let(:expected_zip_filename2) { "core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001.zip" }
before do
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1))
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 4, 1))
FactoryBot.create(:lettings_log, startdate: Time.zone.local(previous_collection_end_year, 2, 1))
FactoryBot.create(:lettings_log, startdate: current_collection_start_date)
end
context "when lettings logs are across multiple quarters" do
it "generates multiple ZIP export files with the expected filenames" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
expect(storage_service).to receive(:write_file).with(expected_zip_filename2, any_args)
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2021")
expect(Rails.logger).to receive(:info).with("Creating core_2021_2022_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_2021_2022_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2021_2022_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2022")
expect(Rails.logger).to receive(:info).with("Creating core_2022_2023_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_2022_2023_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2022_2023_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2023")
expect(Rails.logger).to receive(:info).with("Creating core_2023_2024_apr_mar_f0001_inc0001 - 0 resources")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{previous_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{archived_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{archived_collection_start_year}_#{archived_collection_end_year}_apr_mar_f0001_inc0001 - 0 resources")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{current_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{next_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{next_collection_start_year}_#{next_collection_end_year}_apr_mar_f0001_inc0001 - 0 resources")
export_service.export_xml_lettings_logs
end
it "generates zip export files only for specified year" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename2, any_args)
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2022")
expect(Rails.logger).to receive(:info).with("Creating core_2022_2023_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_2022_2023_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2022_2023_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{previous_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0001_inc0001.zip")
export_service.export_xml_lettings_logs(collection_year: 2022)
export_service.export_xml_lettings_logs(collection_year: previous_collection_start_year)
end
context "and previous full exports are different for previous years" do
let(:expected_zip_filename) { "core_2021_2022_apr_mar_f0007_inc0004.zip" }
let(:expected_zip_filename2) { "core_2022_2023_apr_mar_f0001_inc0001.zip" }
let(:expected_zip_filename) { "core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0007_inc0004.zip" }
let(:expected_zip_filename2) { "core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001.zip" }
before do
Export.new(started_at: Time.zone.yesterday, base_number: 7, increment_number: 3, collection: "lettings", year: 2021).save!
Export.new(started_at: Time.zone.yesterday, base_number: 7, increment_number: 3, collection: "lettings", year: previous_collection_start_year).save!
end
it "generates multiple ZIP export files with different base numbers in the filenames" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
expect(storage_service).to receive(:write_file).with(expected_zip_filename2, any_args)
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2021")
expect(Rails.logger).to receive(:info).with("Creating core_2021_2022_apr_mar_f0007_inc0004 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_2021_2022_apr_mar_f0007_inc0004_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2021_2022_apr_mar_f0007_inc0004.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2022")
expect(Rails.logger).to receive(:info).with("Creating core_2022_2023_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_2022_2023_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2022_2023_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings 2023")
expect(Rails.logger).to receive(:info).with("Creating core_2023_2024_apr_mar_f0001_inc0001 - 0 resources")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{previous_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0007_inc0004 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0007_inc0004_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_#{previous_collection_start_year}_#{previous_collection_end_year}_apr_mar_f0007_inc0004.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{archived_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{archived_collection_start_year}_#{archived_collection_end_year}_apr_mar_f0001_inc0001 - 0 resources")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{current_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001 - 1 resources")
expect(Rails.logger).to receive(:info).with("Added core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_#{current_collection_start_year}_#{current_collection_end_year}_apr_mar_f0001_inc0001.zip")
expect(Rails.logger).to receive(:info).with("Building export run for lettings #{next_collection_start_year}")
expect(Rails.logger).to receive(:info).with("Creating core_#{next_collection_start_year}_#{next_collection_end_year}_apr_mar_f0001_inc0001 - 0 resources")
export_service.export_xml_lettings_logs
end

Loading…
Cancel
Save