Browse Source

Build master manifest file properly when exporting to CDS

- Internally we building an array of hashes internally, when we should have just built one hash.
- This was formatting the master file CSV poorly.
cds-exports
James Rose 2 years ago
parent
commit
7b34223b7c
  1. 9
      app/services/exports/lettings_log_export_service.rb
  2. 9
      spec/services/exports/lettings_log_export_service_spec.rb

9
app/services/exports/lettings_log_export_service.rb

@ -12,19 +12,20 @@ module Exports
start_time = Time.zone.now
logs_by_collection = retrieve_lettings_logs(start_time, full_update).group_by(&:collection_start_year)
daily_run_number = get_daily_run_number
archives_for_manifest = []
archives_for_manifest = {}
base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1
available_collection_years.each do |collection|
lettings_logs = logs_by_collection.fetch(collection, LettingsLog.none)
export = build_export_run(collection, start_time, base_number, full_update)
archives = write_export_archive(export, lettings_logs)
archives_for_manifest << archives if archives.any?
archives_for_manifest.merge!(archives)
export.empty_export = archives.empty?
export.save!
end
write_master_manifest(daily_run_number, archives_for_manifest.flatten)
write_master_manifest(daily_run_number, archives_for_manifest)
end
private
@ -129,7 +130,7 @@ module Exports
headers = ["zip-name", "date-time zipped folder generated", "zip-file-uri"]
csv_string = CSV.generate do |csv|
csv << headers
archive_datetimes.each do |archive, datetime|
archive_datetimes.each do |(archive, datetime)|
csv << [archive, datetime, "#{archive}.zip"]
end
end

9
spec/services/exports/lettings_log_export_service_spec.rb

@ -135,6 +135,15 @@ RSpec.describe Exports::LettingsLogExportService do
export_service.export_xml_lettings_logs
end
it "generates a master manifest with CSV headers" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\ncore_2021_2022_apr_mar_f0001_inc0001,2022-05-01 00:00:00 +0100,#{expected_zip_filename}\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml_lettings_logs
expect(actual_content).to eq(expected_content)
end
end
context "with 23/24 collection period" do

Loading…
Cancel
Save