diff --git a/lib/sequencer/unit/import/freshdesk/agent/mapping.rb b/lib/sequencer/unit/import/freshdesk/agent/mapping.rb index 660c0e932..a0a982821 100644 --- a/lib/sequencer/unit/import/freshdesk/agent/mapping.rb +++ b/lib/sequencer/unit/import/freshdesk/agent/mapping.rb @@ -20,7 +20,7 @@ class Sequencer firstname: contact['name'], email: contact['email'], phone: contact['phone'], - active: contact['active'], + active: !contact['deleted'], group_ids: group_ids, password: password, last_login: contact['last_login_at'], diff --git a/lib/sequencer/unit/import/freshdesk/contact/mapping.rb b/lib/sequencer/unit/import/freshdesk/contact/mapping.rb index 60cbd9078..f1cf6185c 100644 --- a/lib/sequencer/unit/import/freshdesk/contact/mapping.rb +++ b/lib/sequencer/unit/import/freshdesk/contact/mapping.rb @@ -14,7 +14,7 @@ class Sequencer provide_mapped do { firstname: resource['name'], - active: resource['active'], + active: !resource['deleted'], organization_id: organization_id, email: resource['email'], mobile: resource['mobile'], diff --git a/spec/lib/sequencer/sequence/import/freshdesk/agent_spec.rb b/spec/lib/sequencer/sequence/import/freshdesk/agent_spec.rb index a6d67963e..e3ee76bf5 100644 --- a/spec/lib/sequencer/sequence/import/freshdesk/agent_spec.rb +++ b/spec/lib/sequencer/sequence/import/freshdesk/agent_spec.rb @@ -22,7 +22,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Agent, sequencer: :sequ 'available_since' => nil, 'type' => 'support_agent', 'contact' => { - 'active' => true, + 'active' => false, 'email' => 'freshdesk@example.com', 'job_title' => nil, 'language' => 'en', @@ -59,16 +59,24 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Agent, sequencer: :sequ } end - it 'imports user correctly' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength - expect { process(process_payload) }.to change(User, :count).by(1) - expect(User.last).to have_attributes( + let(:imported_user) do + { firstname: 'John', lastname: 'Doe', login: 'freshdesk@example.com', email: 'freshdesk@example.com', active: true, last_login: DateTime.parse('2021-05-10T07:52:58Z'), - ) + } + end + + it 'imports user correctly (increased user count)' do + expect { process(process_payload) }.to change(User, :count).by(1) + end + + it 'imports user data correctly' do + process(process_payload) + expect(User.last).to have_attributes(imported_user) end it 'sets user roles correctly for admin user' do @@ -87,5 +95,16 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Agent, sequencer: :sequ expect(User.last.groups_access('full').sort).to eq groups end + context 'with deleted flag in resource' do + before do + resource['contact']['deleted'] = true + imported_user[:active] = false + end + + it 'imports user data correctly' do + process(process_payload) + expect(User.last).to have_attributes(imported_user) + end + end end end diff --git a/spec/lib/sequencer/sequence/import/freshdesk/contact_spec.rb b/spec/lib/sequencer/sequence/import/freshdesk/contact_spec.rb index 273c75e76..206fa521d 100644 --- a/spec/lib/sequencer/sequence/import/freshdesk/contact_spec.rb +++ b/spec/lib/sequencer/sequence/import/freshdesk/contact_spec.rb @@ -62,6 +62,20 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Contact, sequencer: :se } end + let(:imported_user) do + { + firstname: 'Sam', + lastname: 'Osborne', + login: 'sam.ozzy@freshdesk.com', + email: 'sam.ozzy@freshdesk.com', + active: true, + 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: 'User', name: 'cf_custom_dropdown' create :object_manager_attribute_integer, object_name: 'User', name: 'cf_custom_integer' @@ -70,19 +84,25 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Contact, sequencer: :se ObjectManager::Attribute.migration_execute end - it 'imports customers correctly' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength + it 'imports customer correctly (increased user count)' do expect { process(process_payload) }.to change(User, :count).by(1) - expect(User.last).to have_attributes( - firstname: 'Sam', - lastname: 'Osborne', - login: 'sam.ozzy@freshdesk.com', - email: 'sam.ozzy@freshdesk.com', - active: false, - cf_custom_dropdown: 'key_2', - cf_custom_integer: 999, - cf_test_checkbox: true, - cf_custom_decimal: '1.1', - ) + end + + it 'imports customer data correctly' do + process(process_payload) + expect(User.last).to have_attributes(imported_user) + end + + context 'with deleted flag in resource' do + before do + resource['deleted'] = true + imported_user[:active] = false + end + + it 'imports customer data correctly' do + process(process_payload) + expect(User.last).to have_attributes(imported_user) + end end end end