Browse Source

Remove CSV export

pull/1491/head
James Rose 2 years ago
parent
commit
a197840525
  1. 10
      app/jobs/data_export_csv_job.rb
  2. 26
      app/services/exports/lettings_log_export_service.rb
  3. 19
      spec/jobs/data_export_csv_job_spec.rb
  4. 8
      spec/lib/tasks/data_export_spec.rb
  5. 16
      spec/services/exports/lettings_log_export_service_spec.rb

10
app/jobs/data_export_csv_job.rb

@ -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

26
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("<forms/>")

19
spec/jobs/data_export_csv_job_spec.rb

@ -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

8
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

16
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") }

Loading…
Cancel
Save