2018-08-13 07:10:24 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Import::Exchange::Folder do
|
|
|
|
# see https://github.com/zammad/zammad/issues/2152
|
|
|
|
describe '#display_path (#2152)' do
|
2018-09-04 09:49:44 +00:00
|
|
|
let(:subject) { described_class.new(ews_connection) }
|
|
|
|
let(:ews_connection) { Viewpoint::EWSClient.new(endpoint, user, pass) }
|
|
|
|
let(:endpoint) { 'https://exchange.example.com/EWS/Exchange.asmx' }
|
|
|
|
let(:user) { 'user@example.com' }
|
|
|
|
let(:pass) { 'password' }
|
|
|
|
let(:grandchild_of_root) { ews_connection.get_folder_by_name('Inbox') }
|
|
|
|
let(:child_of_root) { ews_connection.get_folder(grandchild_of_root.parent_folder_id) }
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
cassette_name = example.description.gsub(/[^0-9A-Za-z.\-]+/, '_')
|
|
|
|
VCR.use_cassette("lib/import/exchange/folder/#{cassette_name}") { example.run }
|
2018-09-03 01:36:24 +00:00
|
|
|
end
|
|
|
|
|
2018-08-22 10:33:17 +00:00
|
|
|
context 'when server returns valid UTF-8' do
|
2018-09-04 09:49:44 +00:00
|
|
|
context 'and target folder is in root directory' do
|
2018-08-23 05:02:09 +00:00
|
|
|
it 'returns the display name of the folder' do
|
2018-09-04 09:49:44 +00:00
|
|
|
expect(subject.display_path(child_of_root))
|
|
|
|
.to eq('Top of Information Store')
|
2018-08-23 05:02:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-04 09:49:44 +00:00
|
|
|
context 'and target folder is in subfolder of root' do
|
2018-08-23 05:02:09 +00:00
|
|
|
it 'returns the full path from root to target' do
|
2018-09-04 09:49:44 +00:00
|
|
|
expect(subject.display_path(grandchild_of_root))
|
|
|
|
.to eq('Top of Information Store -> Inbox')
|
2018-08-23 05:02:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and walking up directory tree raises EwsError' do
|
|
|
|
it 'returns the partial path from error to target folder' do
|
2018-09-04 09:49:44 +00:00
|
|
|
allow(subject)
|
|
|
|
.to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
|
|
|
|
|
|
|
|
expect(subject.display_path(grandchild_of_root))
|
|
|
|
.to eq('Inbox')
|
2018-08-23 05:02:09 +00:00
|
|
|
end
|
2018-08-22 10:33:17 +00:00
|
|
|
end
|
2018-08-13 07:10:24 +00:00
|
|
|
end
|
|
|
|
|
2018-08-22 10:33:17 +00:00
|
|
|
context 'when server returns invalid UTF-8' do
|
2018-09-04 09:49:44 +00:00
|
|
|
context 'and target folder is in root directory' do
|
|
|
|
it 'returns the display name of the folder in valid UTF-8' do
|
|
|
|
allow(child_of_root)
|
|
|
|
.to receive(:display_name).and_return('你好'.b)
|
2018-08-22 10:33:17 +00:00
|
|
|
|
2018-09-04 09:49:44 +00:00
|
|
|
expect { subject.display_path(child_of_root).to_json }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2018-08-22 10:33:17 +00:00
|
|
|
|
2018-09-04 09:49:44 +00:00
|
|
|
context 'and target folder is in subfolder of root' do
|
|
|
|
it 'returns the full path from root to target in valid UTF-8' do
|
|
|
|
allow(grandchild_of_root)
|
|
|
|
.to receive(:display_name).and_return('你好'.b)
|
2018-08-22 10:33:17 +00:00
|
|
|
|
2018-09-04 09:49:44 +00:00
|
|
|
expect { subject.display_path(grandchild_of_root).to_json }.not_to raise_error
|
|
|
|
end
|
2018-08-22 10:33:17 +00:00
|
|
|
end
|
|
|
|
|
2018-09-04 09:49:44 +00:00
|
|
|
context 'and walking up directory tree raises EwsError' do
|
|
|
|
it 'returns the partial path from error to target folder in valid UTF-8' do
|
|
|
|
allow(grandchild_of_root)
|
|
|
|
.to receive(:display_name).and_return('你好'.b)
|
|
|
|
allow(subject)
|
|
|
|
.to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
|
|
|
|
|
|
|
|
expect { subject.display_path(grandchild_of_root).to_json }.not_to raise_error
|
|
|
|
end
|
2018-08-22 10:33:17 +00:00
|
|
|
end
|
2018-08-13 07:10:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|