From 62e4352176730334dd71339397ae08a80517a831 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:15:49 +0000 Subject: [PATCH] Set export base number depending on the year (#2224) --- .../exports/lettings_log_export_service.rb | 2 +- .../lettings_log_export_service_spec.rb | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index 404b9f0e6..e63219f7d 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/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) diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index 4e76364c4..65a41df26 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/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