Browse Source

Maintenance: Added more robust custom field value handling in Kayako import (e.g. if a value is not existing).

Dominik Klein 1 year ago
parent
commit
eaf9894d68

+ 12 - 1
lib/sequencer/unit/import/kayako/mapping/custom_fields.rb

@@ -22,7 +22,18 @@ class Sequencer::Unit::Import::Kayako::Mapping::CustomFields < Sequencer::Unit::
 
       field_type_instance = attribute_type_instance(field)
 
-      result[ local_name.to_sym ] = field_type_instance.local_value(item['value'])
+      result[ local_name.to_sym ] = local_value(local_name, field_type_instance, item['value'])
+    end
+  end
+
+  def local_value(local_name, field_type_instance, value)
+    begin
+      field_type_instance.local_value(value)
+    rescue => e
+      logger.error "Error when setting local value for custom field (#{local_name}) for case: #{resource['id']}."
+      logger.error e
+
+      nil
     end
   end
 

+ 31 - 0
spec/lib/sequencer/sequence/import/kayako/examples/object_custom_field_values_examples.rb

@@ -509,4 +509,35 @@ RSpec.shared_examples 'Object custom field values', db_strategy: :reset do |obje
     process(process_payload)
     expect(klass.last).to have_attributes(imported_resource_fields)
   end
+
+  context 'when select option value no longer exists in options' do
+    let(:resource) do
+      resource = super()
+
+      resource['custom_fields'][1]['value'] = '99'
+
+      resource
+    end
+
+    let(:imported_resource_fields) do
+      {
+        custom_textfield:       'Testing',
+        custom_singleselection: nil,
+        custom_multiselection:  %w[two three],
+        custom_boolean:         true,
+        custom_radio:           'third',
+        custom_text_regex:      '999',
+        custom_textarea:        'Example textarea content.\nA new line.',
+        custom_tree_select:     'First-Level 2::Second-Level 2',
+        custom_text_decimal:    '3.5',
+        custom_integer:         3,
+        custom_date:            Date.new(2021, 8, 13)
+      }
+    end
+
+    it 'adds correct custom field data' do
+      process(process_payload)
+      expect(klass.last).to have_attributes(imported_resource_fields)
+    end
+  end
 end