Browse Source

Build master manifest file properly when exporting to CDS (#1548)

- Internally we building an array of hashes internally, when we should have just built one hash.
- This was formatting the master file CSV poorly.
pull/1554/head
James Rose 2 years ago committed by GitHub
parent
commit
f6033b64c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 start_time = Time.zone.now
logs_by_collection = retrieve_lettings_logs(start_time, full_update).group_by(&:collection_start_year) logs_by_collection = retrieve_lettings_logs(start_time, full_update).group_by(&:collection_start_year)
daily_run_number = get_daily_run_number daily_run_number = get_daily_run_number
archives_for_manifest = [] archives_for_manifest = {}
base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1 base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1
available_collection_years.each do |collection| available_collection_years.each do |collection|
lettings_logs = logs_by_collection.fetch(collection, LettingsLog.none) lettings_logs = logs_by_collection.fetch(collection, LettingsLog.none)
export = build_export_run(collection, start_time, base_number, full_update) export = build_export_run(collection, start_time, base_number, full_update)
archives = write_export_archive(export, lettings_logs) 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.empty_export = archives.empty?
export.save! export.save!
end end
write_master_manifest(daily_run_number, archives_for_manifest.flatten) write_master_manifest(daily_run_number, archives_for_manifest)
end end
private private
@ -129,7 +130,7 @@ module Exports
headers = ["zip-name", "date-time zipped folder generated", "zip-file-uri"] headers = ["zip-name", "date-time zipped folder generated", "zip-file-uri"]
csv_string = CSV.generate do |csv| csv_string = CSV.generate do |csv|
csv << headers csv << headers
archive_datetimes.each do |archive, datetime| archive_datetimes.each do |(archive, datetime)|
csv << [archive, datetime, "#{archive}.zip"] csv << [archive, datetime, "#{archive}.zip"]
end end
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 export_service.export_xml_lettings_logs
end 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 end
context "with 23/24 collection period" do context "with 23/24 collection period" do

Loading…
Cancel
Save