Browse Source

Call organisations export and write manifest

pull/2652/head
Kat 2 years ago
parent
commit
ca91ae7e50
  1. 11
      app/services/exports/export_service.rb
  2. 4
      spec/jobs/data_export_xml_job_spec.rb
  3. 115
      spec/services/exports/export_service_spec.rb

11
app/services/exports/export_service.rb

@ -12,20 +12,24 @@ module Exports
daily_run_number = get_daily_run_number daily_run_number = get_daily_run_number
lettings_archives_for_manifest = {} lettings_archives_for_manifest = {}
users_archives_for_manifest = {} users_archives_for_manifest = {}
organisations_archives_for_manifest = {}
if collection.present? if collection.present?
case collection case collection
when "users" when "users"
users_archives_for_manifest = get_user_archives(start_time, full_update) users_archives_for_manifest = get_user_archives(start_time, full_update)
when "organisations"
organisations_archives_for_manifest = get_organisation_archives(start_time, full_update)
else else
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection) lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection)
end end
else else
users_archives_for_manifest = get_user_archives(start_time, full_update) users_archives_for_manifest = get_user_archives(start_time, full_update)
organisations_archives_for_manifest = get_organisation_archives(start_time, full_update)
lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection) lettings_archives_for_manifest = get_lettings_archives(start_time, full_update, collection)
end end
write_master_manifest(daily_run_number, lettings_archives_for_manifest.merge(users_archives_for_manifest)) write_master_manifest(daily_run_number, lettings_archives_for_manifest.merge(users_archives_for_manifest).merge(organisations_archives_for_manifest))
end end
private private
@ -61,6 +65,11 @@ module Exports
users_export_service.export_xml_users(full_update:) users_export_service.export_xml_users(full_update:)
end end
def get_organisation_archives(start_time, full_update)
organisations_export_service = Exports::OrganisationExportService.new(@storage_service, start_time)
organisations_export_service.export_xml_organisations(full_update:)
end
def get_lettings_archives(start_time, full_update, collection) def get_lettings_archives(start_time, full_update, collection)
lettings_export_service = Exports::LettingsLogExportService.new(@storage_service, start_time) lettings_export_service = Exports::LettingsLogExportService.new(@storage_service, start_time)
lettings_export_service.export_xml_lettings_logs(full_update:, collection_year: collection) lettings_export_service.export_xml_lettings_logs(full_update:, collection_year: collection)

4
spec/jobs/data_export_xml_job_spec.rb

@ -5,17 +5,20 @@ describe DataExportXmlJob do
let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) } let(:env_config_service) { instance_double(Configuration::EnvConfigurationService) }
let(:lettings_export_service) { instance_double(Exports::LettingsLogExportService, export_xml_lettings_logs: {}) } let(:lettings_export_service) { instance_double(Exports::LettingsLogExportService, export_xml_lettings_logs: {}) }
let(:user_export_service) { instance_double(Exports::UserExportService, export_xml_users: {}) } let(:user_export_service) { instance_double(Exports::UserExportService, export_xml_users: {}) }
let(:organisation_export_service) { instance_double(Exports::OrganisationExportService, export_xml_organisations: {}) }
before do before do
allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_config_service) allow(Configuration::EnvConfigurationService).to receive(:new).and_return(env_config_service)
allow(Exports::LettingsLogExportService).to receive(:new).and_return(lettings_export_service) allow(Exports::LettingsLogExportService).to receive(:new).and_return(lettings_export_service)
allow(Exports::UserExportService).to receive(:new).and_return(user_export_service) allow(Exports::UserExportService).to receive(:new).and_return(user_export_service)
allow(Exports::OrganisationExportService).to receive(:new).and_return(organisation_export_service)
end end
it "calls the export services" do it "calls the export services" do
expect(lettings_export_service).to receive(:export_xml_lettings_logs) expect(lettings_export_service).to receive(:export_xml_lettings_logs)
expect(user_export_service).to receive(:export_xml_users) expect(user_export_service).to receive(:export_xml_users)
expect(organisation_export_service).to receive(:export_xml_organisations)
described_class.perform_now described_class.perform_now
end end
@ -24,6 +27,7 @@ describe DataExportXmlJob do
it "calls the export service" do it "calls the export service" do
expect(lettings_export_service).to receive(:export_xml_lettings_logs).with(full_update: true, collection_year: nil) expect(lettings_export_service).to receive(:export_xml_lettings_logs).with(full_update: true, collection_year: nil)
expect(user_export_service).to receive(:export_xml_users).with(full_update: true) expect(user_export_service).to receive(:export_xml_users).with(full_update: true)
expect(organisation_export_service).to receive(:export_xml_organisations).with(full_update: true)
described_class.perform_now(full_update: true) described_class.perform_now(full_update: true)
end end

115
spec/services/exports/export_service_spec.rb

@ -7,6 +7,8 @@ RSpec.describe Exports::ExportService do
let(:expected_master_manifest_filename) { "Manifest_2022_05_01_0001.csv" } let(:expected_master_manifest_filename) { "Manifest_2022_05_01_0001.csv" }
let(:start_time) { Time.zone.local(2022, 5, 1) } let(:start_time) { Time.zone.local(2022, 5, 1) }
let(:user) { FactoryBot.create(:user, email: "test1@example.com") } let(:user) { FactoryBot.create(:user, email: "test1@example.com") }
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: {}) }
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
before do before do
Timecop.freeze(start_time) Timecop.freeze(start_time)
@ -14,6 +16,7 @@ RSpec.describe Exports::ExportService do
allow(storage_service).to receive(:write_file) allow(storage_service).to receive(:write_file)
allow(Exports::LettingsLogExportService).to receive(:new).and_return(lettings_logs_export_service) allow(Exports::LettingsLogExportService).to receive(:new).and_return(lettings_logs_export_service)
allow(Exports::UserExportService).to receive(:new).and_return(users_export_service) allow(Exports::UserExportService).to receive(:new).and_return(users_export_service)
allow(Exports::OrganisationExportService).to receive(:new).and_return(organisations_export_service)
end end
after do after do
@ -24,9 +27,7 @@ RSpec.describe Exports::ExportService do
context "and no lettings archives get created in lettings logs export" do context "and no lettings archives get created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: {}) } let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: {}) }
context "and no user archives get created in user export" do context "and no user or organisation archives get created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
it "generates a master manifest with the correct name" do it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml export_service.export_xml
@ -59,14 +60,49 @@ RSpec.describe Exports::ExportService do
expect(actual_content).to eq(expected_content) expect(actual_content).to eq(expected_content)
end end
end end
context "and one organisation archive gets created in organisation export" do
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: { "some_organisation_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml
end
it "generates a master manifest with CSV headers and correct data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_organisation_file_base_name,2022-05-01 00:00:00 +0100,some_organisation_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml
expect(actual_content).to eq(expected_content)
end
end
context "and user and organisation archive gets created in organisation export" do
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: { "some_organisation_file_base_name" => start_time }) }
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: { "some_user_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml
end
it "generates a master manifest with CSV headers and correct data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_user_file_base_name,2022-05-01 00:00:00 +0100,some_user_file_base_name.zip\nsome_organisation_file_base_name,2022-05-01 00:00:00 +0100,some_organisation_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml
expect(actual_content).to eq(expected_content)
end
end
end end
context "and one lettings archive gets created in lettings logs export" do context "and one lettings archive gets created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) } let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
context "and no user archives get created in user export" do context "and no user archives get created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
it "generates a master manifest with the correct name" do it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml export_service.export_xml
@ -105,8 +141,6 @@ RSpec.describe Exports::ExportService do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time, "second_file_base_name" => start_time }) } let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time, "second_file_base_name" => start_time }) }
context "and no user archives get created in user export" do context "and no user archives get created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
it "generates a master manifest with the correct name" do it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml export_service.export_xml
@ -139,6 +173,25 @@ RSpec.describe Exports::ExportService do
expect(actual_content).to eq(expected_content) expect(actual_content).to eq(expected_content)
end end
end end
context "and multiple user and organisation archives gets created in user export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: { "some_user_file_base_name" => start_time, "second_user_file_base_name" => start_time }) }
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: { "some_organisation_file_base_name" => start_time, "second_organisation_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml
end
it "generates a master manifest with CSV headers and correct data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_file_base_name,2022-05-01 00:00:00 +0100,some_file_base_name.zip\nsecond_file_base_name,2022-05-01 00:00:00 +0100,second_file_base_name.zip\nsome_user_file_base_name,2022-05-01 00:00:00 +0100,some_user_file_base_name.zip\nsecond_user_file_base_name,2022-05-01 00:00:00 +0100,second_user_file_base_name.zip\nsome_organisation_file_base_name,2022-05-01 00:00:00 +0100,some_organisation_file_base_name.zip\nsecond_organisation_file_base_name,2022-05-01 00:00:00 +0100,second_organisation_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml
expect(actual_content).to eq(expected_content)
end
end
end end
end end
@ -190,8 +243,6 @@ RSpec.describe Exports::ExportService do
context "when exporting user collection" do context "when exporting user collection" do
context "and no user archives get created in users export" do context "and no user archives get created in users export" do
let(:users_export_service) { instance_double("Exports::UserExportService", export_xml_users: {}) }
context "and lettings log archive gets created in lettings logs export" do context "and lettings log archive gets created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) } let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
@ -233,4 +284,50 @@ RSpec.describe Exports::ExportService do
end end
end end
end end
context "when exporting organisation collection" do
context "and no organisation archives get created in organisations export" do
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: {}) }
context "and lettings log archive gets created in lettings logs export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "organisations")
end
it "does not write lettings log data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "organisations")
expect(actual_content).to eq(expected_content)
end
end
end
context "and organisations archive gets created in organisations export" do
let(:lettings_logs_export_service) { instance_double("Exports::LettingsLogExportService", export_xml_lettings_logs: { "some_file_base_name" => start_time }) }
context "and lettings log archive gets created in lettings log export" do
let(:organisations_export_service) { instance_double("Exports::OrganisationExportService", export_xml_organisations: { "some_organisation_file_base_name" => start_time }) }
it "generates a master manifest with the correct name" do
expect(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args)
export_service.export_xml(full_update: true, collection: "organisations")
end
it "does not write lettings log data" do
actual_content = nil
expected_content = "zip-name,date-time zipped folder generated,zip-file-uri\nsome_organisation_file_base_name,2022-05-01 00:00:00 +0100,some_organisation_file_base_name.zip\n"
allow(storage_service).to receive(:write_file).with(expected_master_manifest_filename, any_args) { |_, arg2| actual_content = arg2&.string }
export_service.export_xml(full_update: true, collection: "organisations")
expect(actual_content).to eq(expected_content)
end
end
end
end
end end

Loading…
Cancel
Save