From da12a36264695763707528ae19d111e716b3fad3 Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Tue, 3 Aug 2021 15:45:28 +0200 Subject: [PATCH] Fixes #3687 - FreshDesk Import doesn't pull in auto-assign domain(s) for organizations. --- .../unit/import/freshdesk/company/mapping.rb | 5 +- .../sequence/import/freshdesk/company_spec.rb | 58 ++++++++++++++++--- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/lib/sequencer/unit/import/freshdesk/company/mapping.rb b/lib/sequencer/unit/import/freshdesk/company/mapping.rb index d81124014..ba793d665 100644 --- a/lib/sequencer/unit/import/freshdesk/company/mapping.rb +++ b/lib/sequencer/unit/import/freshdesk/company/mapping.rb @@ -13,8 +13,9 @@ class Sequencer def process provide_mapped do { - name: resource['name'], - note: resource['description'], + name: resource['name'], + note: resource['description'], + domain: resource['domains']&.first, } end end diff --git a/spec/lib/sequencer/sequence/import/freshdesk/company_spec.rb b/spec/lib/sequencer/sequence/import/freshdesk/company_spec.rb index 8cf7581f3..d95093d2e 100644 --- a/spec/lib/sequencer/sequence/import/freshdesk/company_spec.rb +++ b/spec/lib/sequencer/sequence/import/freshdesk/company_spec.rb @@ -47,6 +47,18 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Company, sequencer: :se } end + let(:imported_organization) do + { + name: 'Test Foundation', + note: nil, + domain: 'acmecorp.com', + cf_custom_dropdown: 'key_2', + cf_custom_integer: 999, + cf_test_checkbox: true, + cf_custom_decimal: '1.1', + } + end + before do create :object_manager_attribute_select, object_name: 'Organization', name: 'cf_custom_dropdown' create :object_manager_attribute_integer, object_name: 'Organization', name: 'cf_custom_integer' @@ -55,16 +67,44 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Company, sequencer: :se ObjectManager::Attribute.migration_execute end - it 'adds organizations' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength + it 'increased organization count' do expect { process(process_payload) }.to change(Organization, :count).by(1) - expect(Organization.last).to have_attributes( - name: 'Test Foundation', - note: nil, - cf_custom_dropdown: 'key_2', - cf_custom_integer: 999, - cf_test_checkbox: true, - cf_custom_decimal: '1.1', - ) + end + + it 'adds correct organization data' do + process(process_payload) + expect(Organization.last).to have_attributes(imported_organization) + end + + context 'when resource has no domains' do + let(:resource) do + { 'id' => 80_000_602_705, + 'name' => 'Test Foundation', + 'description' => nil, + 'note' => nil, + 'domains' => [], + 'created_at' => '2021-04-09T13:24:00Z', + 'updated_at' => '2021-04-12T20:25:36Z', + 'custom_fields' => { + 'cf_test_checkbox' => true, + 'cf_custom_integer' => 999, + 'cf_custom_dropdown' => 'key_2', + 'cf_custom_decimal' => '1.1', + }, + 'health_score' => nil, + 'account_tier' => 'Basic', + 'renewal_date' => nil, + 'industry' => nil } + end + + before do + imported_organization[:domain] = nil + end + + it 'adds organizations' do + process(process_payload) + expect(Organization.last).to have_attributes(imported_organization) + end end end end