folder_spec.rb 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'viewpoint' # Only load this gem when it is really used.
  4. RSpec.describe Import::Exchange::Folder do
  5. # see https://github.com/zammad/zammad/issues/2152
  6. describe '#display_path (#2152)', :use_vcr do
  7. subject(:folder) { described_class.new(ews_connection) }
  8. let(:ews_connection) { Viewpoint::EWSClient.new(endpoint, user, pass) }
  9. let(:endpoint) { 'https://exchange.example.com/EWS/Exchange.asmx' }
  10. let(:user) { 'user@example.com' }
  11. let(:pass) { 'password' }
  12. let(:grandchild_of_root) { ews_connection.get_folder_by_name('Inbox') }
  13. let(:child_of_root) { ews_connection.get_folder(grandchild_of_root.parent_folder_id) }
  14. context 'when server returns valid UTF-8' do
  15. context 'and target folder is in root directory' do
  16. it 'returns the display name of the folder' do
  17. expect(folder.display_path(child_of_root))
  18. .to eq('Top of Information Store')
  19. end
  20. end
  21. context 'and target folder is in subfolder of root' do
  22. it 'returns the full path from root to target' do
  23. expect(folder.display_path(grandchild_of_root))
  24. .to eq('Top of Information Store -> Inbox')
  25. end
  26. end
  27. context 'and walking up directory tree raises EwsError' do
  28. it 'returns the partial path from error to target folder' do
  29. allow(folder)
  30. .to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
  31. expect(folder.display_path(grandchild_of_root))
  32. .to eq('Inbox')
  33. end
  34. end
  35. end
  36. context 'when server returns invalid UTF-8' do
  37. context 'and target folder is in root directory' do
  38. it 'returns the display name of the folder in valid UTF-8' do
  39. allow(child_of_root)
  40. .to receive(:display_name).and_return('你好'.b)
  41. expect { folder.display_path(child_of_root).to_json }.not_to raise_error
  42. end
  43. end
  44. context 'and target folder is in subfolder of root' do
  45. it 'returns the full path from root to target in valid UTF-8' do
  46. allow(grandchild_of_root)
  47. .to receive(:display_name).and_return('你好'.b)
  48. expect { folder.display_path(grandchild_of_root).to_json }.not_to raise_error
  49. end
  50. end
  51. context 'and walking up directory tree raises EwsError' do
  52. it 'returns the partial path from error to target folder in valid UTF-8' do
  53. allow(grandchild_of_root)
  54. .to receive(:display_name).and_return('你好'.b)
  55. allow(folder)
  56. .to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
  57. expect { folder.display_path(grandchild_of_root).to_json }.not_to raise_error
  58. end
  59. end
  60. end
  61. end
  62. end