Browse Source

Export logs migrated since the previous partial export

pull/1873/head
Kat 3 years ago
parent
commit
30ac43e0f5
  1. 2
      app/services/exports/lettings_log_export_service.rb
  2. 20
      spec/services/exports/lettings_log_export_service_spec.rb

2
app/services/exports/lettings_log_export_service.rb

@ -119,7 +119,7 @@ module Exports
def retrieve_lettings_logs(start_time, recent_export, full_update) def retrieve_lettings_logs(start_time, recent_export, full_update)
if !full_update && recent_export if !full_update && recent_export
params = { from: recent_export.started_at, to: start_time } params = { from: recent_export.started_at, to: start_time }
LettingsLog.exportable.where("updated_at >= :from and updated_at <= :to", params) LettingsLog.exportable.where("(updated_at >= :from AND updated_at <= :to) OR (imported_at IS NOT NULL AND imported_at >= :from AND imported_at <= :to)", params)
else else
params = { to: start_time } params = { to: start_time }
LettingsLog.exportable.where("updated_at <= :to", params) LettingsLog.exportable.where("updated_at <= :to", params)

20
spec/services/exports/lettings_log_export_service_spec.rb

@ -328,6 +328,26 @@ RSpec.describe Exports::LettingsLogExportService do
expect(LogsExport.last.increment_number).to eq(1) expect(LogsExport.last.increment_number).to eq(1)
end end
end end
context "and a log has been migrated since the previous partial export" do
before do
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1), updated_at: Time.zone.local(2022, 4, 27), imported_at: Time.zone.local(2022, 4, 29))
FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1), updated_at: Time.zone.local(2022, 4, 27), imported_at: Time.zone.local(2022, 4, 29))
LogsExport.create!(started_at: Time.zone.local(2022, 4, 28), base_number: 1, increment_number: 1)
end
it "generates an XML manifest file with the expected content within the ZIP file" do
expected_content = replace_record_number(local_manifest_file.read, 2)
expect(storage_service).to receive(:write_file).with(expected_master_manifest_rerun, any_args)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|
entry = Zip::File.open_buffer(content).find_entry(expected_manifest_filename)
expect(entry).not_to be_nil
expect(entry.get_input_stream.read).to eq(expected_content)
end
export_service.export_xml_lettings_logs
end
end
end end
context "when exporting a supported housing lettings logs in XML" do context "when exporting a supported housing lettings logs in XML" do

Loading…
Cancel
Save