Browse Source

Refactored the full import calls

pull/821/head
Stéphane Meny 3 years ago
parent
commit
7ce0760cf5
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 22
      app/services/imports/core_import_service.rb
  2. 25
      lib/tasks/full_import.rake
  3. 39
      spec/lib/tasks/full_import_spec.rb

22
app/services/imports/core_import_service.rb

@ -1,22 +0,0 @@
module Imports
class CoreImportService < ImportService
def start_import
end
private
ARCHIVE_FOLDERS = {
organisation: "institution",
scheme: "mgmtgroups",
scheme_location: "schemes",
user: "user",
data_protection_confirmation: "dataprotect",
organisation_rent_periods: "rent-period",
case_log: "logs"
}.freeze
end
end

25
lib/tasks/full_import.rake

@ -1,17 +1,26 @@
Import = Struct.new("Import", :import_class, :import_method, :folder)
namespace :core do
desc "Import all data XMLs from legacy CORE"
task :full_import, %i[path] => :environment do |_task, args|
path = args[:path]
raise "Usage: rake core:full_import['path/to/xml_files']" if path.blank?
raise "Usage: rake core:full_import['path/to/main_folder']" if path.blank?
storage_service = StorageService.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
Imports::OrganisationImportService.new(storage_service).create_organisations(path)
Imports::SchemeImportService.new(storage_service).create_schemes(path)
Imports::SchemeLocationImportService.new(storage_service).create_scheme_locations(path)
Imports::UserImportService.new(storage_service).create_users(path)
Imports::DataProtectionConfirmationImportService.new(storage_service).create_data_protection_confirmations(path)
Imports::OrganisationRentPeriodImportService.new(storage_service).create_organisation_rent_periods(path)
Imports::CaseLogsImportService.new(storage_service).create_logs(path)
import_list = [
Import.new(Imports::OrganisationImportService, :create_organisations, "institution"),
Import.new(Imports::SchemeImportService, :create_schemes, "mgmtgroups"),
Import.new(Imports::SchemeLocationImportService, :create_scheme_locations, "schemes"),
Import.new(Imports::UserImportService, :create_users, "user"),
Import.new(Imports::DataProtectionConfirmationImportService, :create_data_protection_confirmations, "dataprotect"),
Import.new(Imports::OrganisationRentPeriodImportService, :create_organisation_rent_periods, "rent-period"),
Import.new(Imports::CaseLogsImportService, :create_logs, "logs"),
]
import_list.each do |import|
folder_path = File.join(path, import.folder, "")
import.import_class.new(storage_service).send(import.import_method, folder_path)
end
end
end

39
spec/lib/tasks/full_import_spec.rb

@ -20,19 +20,14 @@ describe "rake core:full_import", type: :task do
end
context "when starting a full import" do
it "raises an exception if no parameters are provided" do
expect { task.invoke }.to raise_error(/Usage/)
end
context "with all folders being present"
let(:organisation_service) { instance_double(Imports::OrganisationImportService) }
let(:scheme_service) { instance_double(Imports::SchemeImportService) }
let(:location_service) { instance_double(Imports::SchemeLocationImportService) }
let(:user_service) { instance_double(Imports::UserImportService) }
let(:data_protection_service) { instance_double(Imports::DataProtectionConfirmationImportService) }
let(:rent_period_service) { instance_double(Imports::OrganisationRentPeriodImportService) }
let(:case_logs_service) { instance_double(Imports::CaseLogsImportService) }
let(:fixture_path) { "spec/fixtures/imports" }
let(:case_logs_service) { instance_double(Imports::CaseLogsImportService) }
let(:rent_period_service) { instance_double(Imports::OrganisationRentPeriodImportService) }
let(:data_protection_service) { instance_double(Imports::DataProtectionConfirmationImportService) }
let(:user_service) { instance_double(Imports::UserImportService) }
let(:location_service) { instance_double(Imports::SchemeLocationImportService) }
let(:scheme_service) { instance_double(Imports::SchemeImportService) }
let(:organisation_service) { instance_double(Imports::OrganisationImportService) }
before do
allow(Imports::OrganisationImportService).to receive(:new).and_return(organisation_service)
@ -44,14 +39,20 @@ describe "rake core:full_import", type: :task do
allow(Imports::CaseLogsImportService).to receive(:new).and_return(case_logs_service)
end
it "raises an exception if no parameters are provided" do
expect { task.invoke }.to raise_error(/Usage/)
end
context "with all folders being present"
it "calls every import method" do
expect(organisation_service).to receive(:create_organisations).with(fixture_path)
expect(scheme_service).to receive(:create_schemes).with(fixture_path)
expect(location_service).to receive(:create_scheme_locations).with(fixture_path)
expect(user_service).to receive(:create_users).with(fixture_path)
expect(data_protection_service).to receive(:create_data_protection_confirmations).with(fixture_path)
expect(rent_period_service).to receive(:create_organisation_rent_periods).with(fixture_path)
expect(case_logs_service).to receive(:create_logs).with(fixture_path)
expect(organisation_service).to receive(:create_organisations).with("#{fixture_path}/institution/")
expect(scheme_service).to receive(:create_schemes).with("#{fixture_path}/mgmtgroups/")
expect(location_service).to receive(:create_scheme_locations).with("#{fixture_path}/schemes/")
expect(user_service).to receive(:create_users).with("#{fixture_path}/user/")
expect(data_protection_service).to receive(:create_data_protection_confirmations).with("#{fixture_path}/dataprotect/")
expect(rent_period_service).to receive(:create_organisation_rent_periods).with("#{fixture_path}/rent-period/")
expect(case_logs_service).to receive(:create_logs).with("#{fixture_path}/logs/")
task.invoke(fixture_path)
end

Loading…
Cancel
Save