Browse Source

CLDC-1221: Handles the confirm status during import (#834)

* Handles the confirm status during import

* Typo
pull/841/head
Stéphane Meny 2 years ago committed by GitHub
parent
commit
a70c90e485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/services/imports/scheme_location_import_service.rb
  2. 1
      lib/tasks/full_import.rake
  3. 1
      spec/lib/tasks/full_import_spec.rb
  4. 15
      spec/services/imports/scheme_location_import_service_spec.rb

22
app/services/imports/scheme_location_import_service.rb

@ -27,7 +27,7 @@ module Imports
}.freeze
def create_scheme(source_scheme, attributes)
Scheme.create!(
scheme = Scheme.new(
scheme_type: attributes["scheme_type"],
registered_under_care_act: attributes["registered_under_care_act"],
support_type: attributes["support_type"],
@ -36,7 +36,6 @@ module Imports
secondary_client_group: attributes["secondary_client_group"],
sensitive: attributes["sensitive"],
end_date: attributes["end_date"],
confirmed: true,
# These values were set by the scheme import (management groups)
owning_organisation_id: source_scheme.owning_organisation_id,
managing_organisation_id: source_scheme.managing_organisation_id,
@ -45,10 +44,12 @@ module Imports
old_id: source_scheme.old_id,
old_visible_id: source_scheme.old_visible_id,
)
confirm_scheme(scheme)
scheme.save! && scheme
end
def update_scheme(scheme, attributes)
scheme.update!(
scheme.attributes = {
scheme_type: attributes["scheme_type"],
registered_under_care_act: attributes["registered_under_care_act"],
support_type: attributes["support_type"],
@ -57,9 +58,18 @@ module Imports
secondary_client_group: attributes["secondary_client_group"],
sensitive: attributes["sensitive"],
end_date: attributes["end_date"],
confirmed: true,
)
scheme
}
confirm_scheme(scheme)
scheme.save! && scheme
end
def confirm_scheme(scheme)
scheme.confirmed = true
scheme.validate_confirmed
unless scheme.errors.empty?
scheme.confirmed = false
scheme.errors.clear
end
end
def scheme_attributes(xml_doc)

1
lib/tasks/full_import.rake

@ -22,6 +22,7 @@ namespace :core do
import_list.each do |step|
if archive_service.folder_present?(step.folder)
Rails.logger.info("Start importing folder #{step.folder}")
step.import_class.new(archive_service).send(step.import_method, step.folder)
else
Rails.logger.info("#{step.folder} does not exist, skipping #{step.import_class}")

1
spec/lib/tasks/full_import_spec.rb

@ -64,6 +64,7 @@ describe "rake core:full_import", type: :task do
allow(archive_service).to receive(:folder_present?).and_return(true)
allow(archive_service).to receive(:folder_present?).with("mgmtgroups").and_return(false)
allow(archive_service).to receive(:folder_present?).with("schemes").and_return(false)
allow(Rails.logger).to receive(:info)
end
it "only calls import methods for existing folders" do

15
spec/services/imports/scheme_location_import_service_spec.rb

@ -157,6 +157,7 @@ RSpec.describe Imports::SchemeLocationImportService do
expect(location.scheme.secondary_client_group).to be_nil
expect(location.scheme.sensitive).to eq("No")
expect(location.scheme.end_date).to eq("2050-12-31")
expect(location.scheme.confirmed).to be_truthy
end
context "and the end date is before the current date" do
@ -183,5 +184,19 @@ RSpec.describe Imports::SchemeLocationImportService do
.not_to change(Location, :count)
end
end
context "and the registered under care act value is missing" do
before { location_xml.at_xpath("//scheme:reg-home-type").content = "0" }
it "sets the registered under care act to nil" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.registered_under_care_act).to be_nil
end
it "sets the confirmed status to false" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.confirmed).to be_falsey
end
end
end
end

Loading…
Cancel
Save