Browse Source

Set export base number depending on the year (#2224)

pull/2240/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
62e4352176
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/services/exports/lettings_log_export_service.rb
  2. 26
      spec/services/exports/lettings_log_export_service_spec.rb

2
app/services/exports/lettings_log_export_service.rb

@ -12,9 +12,9 @@ module Exports
start_time = Time.zone.now
daily_run_number = get_daily_run_number
archives_for_manifest = {}
base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1
recent_export = LogsExport.order("started_at").last
collection_years_to_export(collection_year).each do |collection|
base_number = LogsExport.where(empty_export: false, collection:).maximum(:base_number) || 1
export = build_export_run(collection, start_time, base_number, full_update)
archives = write_export_archive(export, collection, start_time, recent_export, full_update)

26
spec/services/exports/lettings_log_export_service_spec.rb

@ -256,6 +256,32 @@ RSpec.describe Exports::LettingsLogExportService do
export_service.export_xml_lettings_logs(collection_year: 2022)
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" }
before do
LogsExport.new(started_at: Time.zone.yesterday, base_number: 7, increment_number: 3, collection: 2021).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 2021")
expect(Rails.logger).to receive(:info).with("Creating core_2021_2022_apr_mar_f0007_inc0004 - 1 logs")
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 2022")
expect(Rails.logger).to receive(:info).with("Creating core_2022_2023_apr_mar_f0001_inc0001 - 1 logs")
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 2023")
expect(Rails.logger).to receive(:info).with("Creating core_2023_2024_apr_mar_f0001_inc0001 - 0 logs")
export_service.export_xml_lettings_logs
end
end
end
end

Loading…
Cancel
Save