2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Import::OTRS::ArticleCustomer do
|
|
|
|
|
|
|
|
def load_article_json(file)
|
|
|
|
json_fixture("import/otrs/article/#{file}")
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:instance_id) { 1337 }
|
|
|
|
let(:existing_object) { instance_double(import_object) }
|
|
|
|
let(:import_object) { User }
|
|
|
|
let(:object_structure) { load_article_json('customer_phone') }
|
|
|
|
let(:start_import_test) { described_class.new(object_structure) }
|
|
|
|
|
|
|
|
it 'finds customers by email' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(import_object).to receive(:find_by).with(email: 'kunde2@kunde.de').and_return(existing_object)
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
expect(import_object).not_to receive(:create)
|
|
|
|
start_import_test
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds customers by login' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(import_object).to receive(:find_by)
|
|
|
|
allow(import_object).to receive(:find_by).with(login: 'kunde2@kunde.de').and_return(existing_object)
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
expect(import_object).not_to receive(:create)
|
|
|
|
start_import_test
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates customers' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(import_object).to receive(:create).and_return(existing_object)
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
expect(import_object).to receive(:find_by).at_least(:once)
|
|
|
|
start_import_test
|
|
|
|
end
|
2017-03-16 14:06:24 +00:00
|
|
|
|
|
|
|
it 'creates customers with special encoding in name' do
|
2019-04-15 01:41:17 +00:00
|
|
|
expect { described_class.new(load_article_json('customer_special_chars')) }.to change(User, :count).by(1)
|
2017-03-16 14:06:24 +00:00
|
|
|
expect(User.last.login).to eq('user.hernandez@example.com')
|
|
|
|
end
|
|
|
|
|
2017-03-27 10:47:33 +00:00
|
|
|
it 'creates customers with special from email syntax' do
|
2019-04-15 01:41:17 +00:00
|
|
|
expect { described_class.new(load_article_json('from_bracket_email_syntax')) }.to change(User, :count).by(1)
|
2017-03-16 14:06:24 +00:00
|
|
|
expect(User.last.login).to eq('user@example.com')
|
|
|
|
end
|
2017-03-27 10:47:33 +00:00
|
|
|
|
|
|
|
it 'converts emails to downcase' do
|
|
|
|
Setting.set('import_mode', true)
|
2019-04-15 01:41:17 +00:00
|
|
|
expect { described_class.new(load_article_json('from_capital_case')) }.to change(User, :count).by(1)
|
2017-03-27 10:47:33 +00:00
|
|
|
expect(User.last.email).to eq('user@example.com')
|
|
|
|
expect(User.last.login).to eq('user@example.com')
|
|
|
|
end
|
2017-03-28 09:28:07 +00:00
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.find' do
|
2017-03-28 09:28:07 +00:00
|
|
|
|
|
|
|
it 'returns nil if no email could be found' do
|
|
|
|
expect(described_class.find({})).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.local_email' do
|
2017-03-28 09:28:07 +00:00
|
|
|
|
|
|
|
it 'returns nil if no email could be found' do
|
|
|
|
expect(described_class.local_email(nil)).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the parameter if no email could be found' do
|
|
|
|
not_an_email = 'thisisnotanemail'
|
|
|
|
expect(described_class.local_email(not_an_email)).to eq(not_an_email)
|
|
|
|
end
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|