organization_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'zendesk_api'
  4. RSpec.describe Sequencer::Sequence::Import::Zendesk::Organization, db_strategy: :reset, sequencer: :sequence do
  5. context 'when importing organizations from Zendesk' do
  6. let(:resource) do
  7. ZendeskAPI::Organization.new(
  8. nil,
  9. {
  10. 'id' => 154_755_561,
  11. 'name' => 'Test Foundation',
  12. 'shared_tickets' => false,
  13. 'shared_comments' => false,
  14. 'external_id' => nil,
  15. 'created_at' => '2015-07-19 22:41:40 UTC',
  16. 'updated_at' => '2016-05-19 12:24:21 UTC',
  17. 'domain_names' => [],
  18. 'details' => '',
  19. 'notes' => '',
  20. 'group_id' => nil,
  21. 'tags' => ['b'],
  22. 'organization_fields' => {
  23. 'api_key' => 'my api öäüß',
  24. 'custom_dropdown' => 'b',
  25. 'test::example' => '1',
  26. },
  27. 'deleted_at' => nil
  28. }
  29. )
  30. end
  31. let(:field_map) do
  32. {
  33. 'Organization' => {
  34. 'api_key' => 'api_key',
  35. 'custom_dropdown' => 'custom_dropdown',
  36. 'test::example' => 'test_example',
  37. }
  38. }
  39. end
  40. let(:process_payload) do
  41. {
  42. import_job: build_stubbed(:import_job, name: 'Import::Zendesk', payload: {}),
  43. dry_run: false,
  44. resource: resource,
  45. field_map: field_map,
  46. }
  47. end
  48. let(:imported_organization) do
  49. {
  50. name: 'Test Foundation',
  51. note: nil,
  52. domain: '',
  53. api_key: 'my api öäüß',
  54. custom_dropdown: 'b',
  55. test_example: '1',
  56. }
  57. end
  58. before do
  59. create(:object_manager_attribute_select, object_name: 'Organization', name: 'custom_dropdown')
  60. create(:object_manager_attribute_text, object_name: 'Organization', name: 'api_key')
  61. create(:object_manager_attribute_text, object_name: 'Organization', name: 'test_example')
  62. ObjectManager::Attribute.migration_execute
  63. end
  64. it 'increased organization count' do
  65. expect { process(process_payload) }.to change(Organization, :count).by(1)
  66. end
  67. it 'adds correct organization data' do
  68. process(process_payload)
  69. expect(Organization.last).to have_attributes(imported_organization)
  70. end
  71. end
  72. end