Fixes #3689 - FreshDesk Import brings in all users as inactive.

This commit is contained in:
Dominik Klein 2021-08-03 17:03:22 +02:00 committed by Thorsten Eckel
parent 0b522cfe17
commit 6a89d716be
4 changed files with 58 additions and 19 deletions

View file

@ -20,7 +20,7 @@ class Sequencer
firstname: contact['name'], firstname: contact['name'],
email: contact['email'], email: contact['email'],
phone: contact['phone'], phone: contact['phone'],
active: contact['active'], active: !contact['deleted'],
group_ids: group_ids, group_ids: group_ids,
password: password, password: password,
last_login: contact['last_login_at'], last_login: contact['last_login_at'],

View file

@ -14,7 +14,7 @@ class Sequencer
provide_mapped do provide_mapped do
{ {
firstname: resource['name'], firstname: resource['name'],
active: resource['active'], active: !resource['deleted'],
organization_id: organization_id, organization_id: organization_id,
email: resource['email'], email: resource['email'],
mobile: resource['mobile'], mobile: resource['mobile'],

View file

@ -22,7 +22,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Agent, sequencer: :sequ
'available_since' => nil, 'available_since' => nil,
'type' => 'support_agent', 'type' => 'support_agent',
'contact' => { 'contact' => {
'active' => true, 'active' => false,
'email' => 'freshdesk@example.com', 'email' => 'freshdesk@example.com',
'job_title' => nil, 'job_title' => nil,
'language' => 'en', 'language' => 'en',
@ -59,16 +59,24 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Agent, sequencer: :sequ
} }
end end
it 'imports user correctly' do # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength let(:imported_user) do
expect { process(process_payload) }.to change(User, :count).by(1) {
expect(User.last).to have_attributes(
firstname: 'John', firstname: 'John',
lastname: 'Doe', lastname: 'Doe',
login: 'freshdesk@example.com', login: 'freshdesk@example.com',
email: 'freshdesk@example.com', email: 'freshdesk@example.com',
active: true, active: true,
last_login: DateTime.parse('2021-05-10T07:52:58Z'), 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 end
it 'sets user roles correctly for admin user' do 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 expect(User.last.groups_access('full').sort).to eq groups
end 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
end end

View file

@ -62,6 +62,20 @@ RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Contact, sequencer: :se
} }
end 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 before do
create :object_manager_attribute_select, object_name: 'User', name: 'cf_custom_dropdown' create :object_manager_attribute_select, object_name: 'User', name: 'cf_custom_dropdown'
create :object_manager_attribute_integer, object_name: 'User', name: 'cf_custom_integer' 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 ObjectManager::Attribute.migration_execute
end 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 { process(process_payload) }.to change(User, :count).by(1)
expect(User.last).to have_attributes( end
firstname: 'Sam',
lastname: 'Osborne', it 'imports customer data correctly' do
login: 'sam.ozzy@freshdesk.com', process(process_payload)
email: 'sam.ozzy@freshdesk.com', expect(User.last).to have_attributes(imported_user)
active: false, end
cf_custom_dropdown: 'key_2',
cf_custom_integer: 999, context 'with deleted flag in resource' do
cf_test_checkbox: true, before do
cf_custom_decimal: '1.1', 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 end
end end