From a19784052519053a479d21278f9b305822a14df0 Mon Sep 17 00:00:00 2001 From: James Rose Date: Thu, 30 Mar 2023 10:25:33 +0100 Subject: [PATCH] Remove CSV export --- app/jobs/data_export_csv_job.rb | 10 ------- .../exports/lettings_log_export_service.rb | 26 +------------------ spec/jobs/data_export_csv_job_spec.rb | 19 -------------- spec/lib/tasks/data_export_spec.rb | 8 ------ .../lettings_log_export_service_spec.rb | 16 ------------ 5 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 app/jobs/data_export_csv_job.rb delete mode 100644 spec/jobs/data_export_csv_job_spec.rb diff --git a/app/jobs/data_export_csv_job.rb b/app/jobs/data_export_csv_job.rb deleted file mode 100644 index 8db19a202..000000000 --- a/app/jobs/data_export_csv_job.rb +++ /dev/null @@ -1,10 +0,0 @@ -class DataExportCsvJob < ApplicationJob - queue_as :default - - def perform - storage_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"]) - export_service = Exports::LettingsLogExportService.new(storage_service) - - export_service.export_csv_lettings_logs - end -end diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index 158d52147..350b7150a 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -8,14 +8,7 @@ module Exports @logger = logger end - def export_csv_lettings_logs - time_str = Time.zone.now.strftime("%F").underscore - lettings_logs = retrieve_lettings_logs(Time.zone.now, true) - csv_io = build_export_csv(lettings_logs) - @storage_service.write_file("export_#{time_str}.csv", csv_io) - end - - def export_xml_lettings_logs(full_update: false) + def export_xml_lettings_logs(collection:, full_update: false) start_time = Time.zone.now lettings_logs = retrieve_lettings_logs(start_time, full_update) export = build_export_run(start_time, full_update) @@ -237,23 +230,6 @@ module Exports !EXPORT_FIELDS.include?(field_name) end - def build_export_csv(lettings_logs) - csv_io = CSV.generate do |csv| - attribute_keys = nil - lettings_logs.each do |lettings_log| - attribute_hash = apply_cds_transformation(lettings_log, EXPORT_MODE[:csv]) - if attribute_keys.nil? - attribute_keys = attribute_hash.keys - filter_keys!(attribute_keys) - csv << attribute_keys - end - csv << attribute_keys.map { |attribute_key| attribute_hash[attribute_key] } - end - end - - StringIO.new(csv_io) - end - def build_export_xml(lettings_logs) doc = Nokogiri::XML("") diff --git a/spec/jobs/data_export_csv_job_spec.rb b/spec/jobs/data_export_csv_job_spec.rb deleted file mode 100644 index cf06752c7..000000000 --- a/spec/jobs/data_export_csv_job_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require "rails_helper" - -describe DataExportCsvJob do - let(:storage_service) { instance_double(Storage::S3Service) } - let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) } - let(:export_service) { instance_double(Exports::LettingsLogExportService) } - - before do - allow(Storage::S3Service).to receive(:new).and_return(storage_service) - allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) - allow(Exports::LettingsLogExportService).to receive(:new).and_return(export_service) - end - - it "calls the export service" do - expect(export_service).to receive(:export_csv_lettings_logs) - - described_class.perform_now - end -end diff --git a/spec/lib/tasks/data_export_spec.rb b/spec/lib/tasks/data_export_spec.rb index e1242e6b6..ba2e9928b 100644 --- a/spec/lib/tasks/data_export_spec.rb +++ b/spec/lib/tasks/data_export_spec.rb @@ -26,12 +26,4 @@ describe "rake core:data_export", type: task do expect { task.invoke }.to enqueue_job(DataExportXmlJob) end end - - context "when exporting lettings logs with CSV format" do - let(:task) { Rake::Task["core:data_export_csv"] } - - it "starts the CSV export process" do - expect { task.invoke }.to enqueue_job(DataExportCsvJob) - end - end end diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index 6580a6acd..970b90226 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/spec/services/exports/lettings_log_export_service_spec.rb @@ -306,22 +306,6 @@ RSpec.describe Exports::LettingsLogExportService do end end - context "when exporting a general needs lettings logs in CSV" do - let(:csv_export_file) { File.open("spec/fixtures/exports/general_needs_log.csv", "r:UTF-8") } - let(:expected_csv_filename) { "export_2022_05_01.csv" } - - let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) } - - it "generates an CSV export file with the expected content" do - expected_content = replace_entity_ids(lettings_log, csv_export_file.read) - expect(storage_service).to receive(:write_file).with(expected_csv_filename, any_args) do |_, content| - expect(content).not_to be_nil - expect(content.read).to eq(expected_content) - end - export_service.export_csv_lettings_logs - end - end - context "when exporting a supporting housing lettings logs in XML" do let(:export_file) { File.open("spec/fixtures/exports/supported_housing_logs.xml", "r:UTF-8") } let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") }