diff --git a/lib/tasks/full_import.rake b/lib/tasks/full_import.rake index 49c1348ce..42ac083f1 100644 --- a/lib/tasks/full_import.rake +++ b/lib/tasks/full_import.rake @@ -20,7 +20,11 @@ namespace :core do import_list.each do |import| folder_path = File.join(path, import.folder, "") - import.import_class.new(storage_service).send(import.import_method, folder_path) + if storage_service.folder_present?(folder_path) + import.import_class.new(storage_service).send(import.import_method, folder_path) + else + Rails.logger.info("#{folder_path} does not exist, skipping #{import.import_class}") + end end end end diff --git a/spec/lib/tasks/full_import_spec.rb b/spec/lib/tasks/full_import_spec.rb index 1ceed5fcb..ac5015947 100644 --- a/spec/lib/tasks/full_import_spec.rb +++ b/spec/lib/tasks/full_import_spec.rb @@ -43,18 +43,43 @@ describe "rake core:full_import", type: :task 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}/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) + context "with all folders being present" do + before { allow(storage_service).to receive(:folder_present?).and_return(true) } + + it "calls every import method with the correct folder" do + 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 + end + + context "when a specific folders are missing" do + before do + allow(storage_service).to receive(:folder_present?).and_return(true) + allow(storage_service).to receive(:folder_present?).with("#{fixture_path}/mgmtgroups/").and_return(false) + allow(storage_service).to receive(:folder_present?).with("#{fixture_path}/schemes/").and_return(false) + end + + it "only calls import methods for existing folders" do + expect(organisation_service).to receive(:create_organisations) + expect(user_service).to receive(:create_users) + expect(data_protection_service).to receive(:create_data_protection_confirmations) + expect(rent_period_service).to receive(:create_organisation_rent_periods) + expect(case_logs_service).to receive(:create_logs) + + expect(scheme_service).to_not receive(:create_schemes) + expect(location_service).to_not receive(:create_scheme_locations) + expect(Rails.logger).to receive(:info).with("spec/fixtures/imports/mgmtgroups/ does not exist, skipping Imports::SchemeImportService") + expect(Rails.logger).to receive(:info).with("spec/fixtures/imports/schemes/ does not exist, skipping Imports::SchemeLocationImportService") + + task.invoke(fixture_path) + end end end end