user_field_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'zendesk_api'
  4. RSpec.describe Sequencer::Sequence::Import::Zendesk::UserField, sequencer: :sequence do
  5. let(:process_payload) do
  6. {
  7. import_job: build_stubbed(:import_job, name: 'Import::Zendesk', payload: {}),
  8. dry_run: false,
  9. resource: resource,
  10. field_map: {},
  11. }
  12. end
  13. context 'when trying to import user fields from Zendesk', db_strategy: :reset do
  14. let(:resource) do
  15. ZendeskAPI::UserField.new(
  16. nil,
  17. {
  18. 'id' => 206_315,
  19. 'type' => 'text',
  20. 'key' => 'lieblingstier',
  21. 'title' => 'Lieblingstier',
  22. 'description' => "Hund,
  23. Katze oder Maus?",
  24. 'raw_title' => 'Lieblingstier',
  25. 'raw_description' => "Hund,
  26. Katze oder Maus?",
  27. 'position' => 0,
  28. 'active' => true,
  29. 'system' => false,
  30. 'regexp_for_validation' => nil,
  31. 'created_at' => '2015-12-04 11:05:45 UTC',
  32. 'updated_at' => '2015-12-04 11:05:45 UTC'
  33. }
  34. )
  35. end
  36. it 'adds user fields' do
  37. expect { process(process_payload) }.to change(User, :column_names).by(['lieblingstier'])
  38. end
  39. end
  40. context 'when trying to import an existing internal field on zammad side' do
  41. let(:resource) do
  42. ZendeskAPI::UserField.new(
  43. nil,
  44. {
  45. 'id' => 206_415,
  46. 'type' => 'text',
  47. 'key' => 'phone',
  48. 'title' => 'Phone',
  49. 'description' => '',
  50. 'raw_title' => 'Phone',
  51. 'raw_description' => ",
  52. Katze oder Maus?",
  53. 'position' => 0,
  54. 'active' => false,
  55. 'system' => false,
  56. 'regexp_for_validation' => nil,
  57. 'created_at' => '2015-12-04 11:05:45 UTC',
  58. 'updated_at' => '2015-12-04 11:05:45 UTC'
  59. }
  60. )
  61. end
  62. it 'does not try to add a existing field' do
  63. expect { process(process_payload) }.not_to raise_error
  64. end
  65. end
  66. end