2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Import::OTRS::CustomerUser do
|
|
|
|
|
|
|
|
def creates_with(zammad_structure)
|
2020-10-22 13:57:01 +00:00
|
|
|
allow_organization_lookup
|
|
|
|
allow(import_object).to receive(:new).with(zammad_structure).and_call_original
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
expect_any_instance_of(import_object).to receive(:save)
|
|
|
|
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
|
|
|
|
start_import_test
|
|
|
|
end
|
|
|
|
|
|
|
|
def updates_with(zammad_structure)
|
2020-10-22 13:57:01 +00:00
|
|
|
allow_organization_lookup
|
|
|
|
allow(import_object).to receive(:find_by).and_return(existing_object)
|
2016-12-12 10:46:48 +00:00
|
|
|
# we delete the :role_ids from the zammad_structure to make sure that
|
|
|
|
# a) role_ids call returns the initial role_ids
|
2017-09-11 11:16:08 +00:00
|
|
|
# b) and update! gets called without them
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once)
|
|
|
|
|
2017-09-11 11:16:08 +00:00
|
|
|
expect(existing_object).to receive(:update!).with(zammad_structure)
|
2016-11-25 16:10:37 +00:00
|
|
|
expect(import_object).not_to receive(:new)
|
|
|
|
start_import_test
|
|
|
|
end
|
|
|
|
|
2020-10-22 13:57:01 +00:00
|
|
|
def allow_organization_lookup
|
|
|
|
allow(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization)
|
|
|
|
allow(organization).to receive(:id).and_return(organization_id)
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_customer_json(file)
|
|
|
|
json_fixture("import/otrs/customer_user/#{file}")
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:import_object) { User }
|
|
|
|
let(:existing_object) { instance_double(import_object) }
|
|
|
|
let(:start_import_test) { described_class.new(object_structure) }
|
|
|
|
let(:organization) { instance_double(Organization) }
|
|
|
|
let(:organization_id) { 1337 }
|
|
|
|
|
2016-12-16 10:12:15 +00:00
|
|
|
context 'regular user' do
|
2016-11-25 16:10:37 +00:00
|
|
|
|
|
|
|
let(:object_structure) { load_customer_json('default') }
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:zammad_structure) do
|
2016-11-25 16:10:37 +00:00
|
|
|
{
|
|
|
|
created_by_id: '1',
|
|
|
|
updated_by_id: '1',
|
|
|
|
active: true,
|
|
|
|
source: 'OTRS Import',
|
|
|
|
organization_id: 1337,
|
|
|
|
role_ids: [3],
|
|
|
|
updated_at: '2014-06-07 02:31:31',
|
|
|
|
created_at: '2014-06-07 02:31:31',
|
|
|
|
note: '',
|
|
|
|
email: 'qa100@t-online.de',
|
|
|
|
firstname: 'test669673',
|
|
|
|
lastname: 'test669673',
|
|
|
|
login: 'test669673',
|
|
|
|
password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee',
|
|
|
|
phone: nil,
|
|
|
|
fax: nil,
|
|
|
|
mobile: nil,
|
|
|
|
street: nil,
|
|
|
|
zip: nil,
|
|
|
|
city: nil,
|
|
|
|
country: nil
|
2017-10-01 12:25:52 +00:00
|
|
|
}
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
|
|
|
|
it 'creates' do
|
|
|
|
creates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates' do
|
|
|
|
updates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 10:12:15 +00:00
|
|
|
|
|
|
|
context 'no timestamps' do
|
|
|
|
|
|
|
|
let(:object_structure) { load_customer_json('no_timestamps') }
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:zammad_structure) do
|
2016-12-16 10:12:15 +00:00
|
|
|
{
|
|
|
|
created_by_id: '1',
|
|
|
|
updated_by_id: '1',
|
|
|
|
active: true,
|
|
|
|
source: 'OTRS Import',
|
|
|
|
organization_id: 1337,
|
|
|
|
role_ids: [3],
|
|
|
|
updated_at: DateTime.current,
|
|
|
|
created_at: DateTime.current,
|
|
|
|
note: '',
|
|
|
|
email: 'qa100@t-online.de',
|
|
|
|
firstname: 'test669673',
|
|
|
|
lastname: 'test669673',
|
|
|
|
login: 'test669673',
|
|
|
|
password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee',
|
|
|
|
phone: nil,
|
|
|
|
fax: nil,
|
|
|
|
mobile: nil,
|
|
|
|
street: nil,
|
|
|
|
zip: nil,
|
|
|
|
city: nil,
|
|
|
|
country: nil
|
2017-10-01 12:25:52 +00:00
|
|
|
}
|
|
|
|
end
|
2016-12-16 10:12:15 +00:00
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
before do
|
2016-12-16 10:12:15 +00:00
|
|
|
travel_to DateTime.current
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates' do
|
|
|
|
creates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates' do
|
|
|
|
updates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
end
|
2017-05-14 16:33:30 +00:00
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
context 'regular user with capitalized email' do
|
2017-05-14 16:33:30 +00:00
|
|
|
|
|
|
|
let(:object_structure) { load_customer_json('capital_email') }
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:zammad_structure) do
|
2017-05-14 16:33:30 +00:00
|
|
|
{
|
|
|
|
created_by_id: '1',
|
|
|
|
updated_by_id: '1',
|
|
|
|
active: true,
|
|
|
|
source: 'OTRS Import',
|
|
|
|
organization_id: 1337,
|
|
|
|
role_ids: [3],
|
|
|
|
updated_at: '2014-06-07 02:31:31',
|
|
|
|
created_at: '2014-06-07 02:31:31',
|
|
|
|
note: '',
|
|
|
|
email: 'qa100@t-online.de',
|
|
|
|
firstname: 'test669673',
|
|
|
|
lastname: 'test669673',
|
|
|
|
login: 'test669673',
|
|
|
|
password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee',
|
|
|
|
phone: nil,
|
|
|
|
fax: nil,
|
|
|
|
mobile: nil,
|
|
|
|
street: nil,
|
|
|
|
zip: nil,
|
|
|
|
city: nil,
|
|
|
|
country: nil
|
2017-10-01 12:25:52 +00:00
|
|
|
}
|
|
|
|
end
|
2017-05-14 16:33:30 +00:00
|
|
|
|
|
|
|
it 'creates' do
|
|
|
|
creates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates' do
|
|
|
|
updates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
end
|
2017-11-24 16:49:40 +00:00
|
|
|
|
|
|
|
context 'regular user with camelcase login' do
|
|
|
|
|
|
|
|
let(:object_structure) { load_customer_json('camel_case_login') }
|
|
|
|
let(:zammad_structure) do
|
|
|
|
{
|
|
|
|
created_by_id: '1',
|
|
|
|
updated_by_id: '1',
|
|
|
|
active: true,
|
|
|
|
source: 'OTRS Import',
|
|
|
|
organization_id: 1337,
|
|
|
|
role_ids: [3],
|
|
|
|
updated_at: '2014-06-07 02:31:31',
|
|
|
|
created_at: '2014-06-07 02:31:31',
|
|
|
|
note: '',
|
|
|
|
email: 'qa100@t-online.de',
|
|
|
|
firstname: 'test669673',
|
|
|
|
lastname: 'test669673',
|
|
|
|
login: 'test669673',
|
|
|
|
password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee',
|
|
|
|
phone: nil,
|
|
|
|
fax: nil,
|
|
|
|
mobile: nil,
|
|
|
|
street: nil,
|
|
|
|
zip: nil,
|
|
|
|
city: nil,
|
|
|
|
country: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates' do
|
|
|
|
creates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates' do
|
|
|
|
updates_with(zammad_structure)
|
|
|
|
end
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|