contact_field_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::ContactField, sequencer: :sequence do
  4. context 'when tryping to import contact fields from Freshdesk', db_strategy: :reset do
  5. let(:process_payload) do
  6. {
  7. import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
  8. dry_run: false,
  9. resource: resource,
  10. field_map: {},
  11. id_map: {},
  12. }
  13. end
  14. # Other field types are checked in ticket_field_spec.rb.
  15. context 'when fields are valid' do
  16. let(:resource) do
  17. {
  18. 'editable_in_signup' => false,
  19. 'id' => 80_000_776_200,
  20. 'name' => 'custom_dropdown',
  21. 'label' => 'custom_dropdown',
  22. 'position' => 16,
  23. 'required_for_agents' => false,
  24. 'type' => 'custom_dropdown',
  25. 'default' => false,
  26. 'customers_can_edit' => true,
  27. 'label_for_customers' => 'custom_dropdown',
  28. 'required_for_customers' => false,
  29. 'displayed_for_customers' => true,
  30. 'created_at' => '2021-04-12T20:19:46Z',
  31. 'updated_at' => '2021-04-12T20:19:46Z',
  32. 'choices' => [ 'First Choice', 'Second Choice']
  33. }
  34. end
  35. it 'adds custom fields' do
  36. expect { process(process_payload) }.to change(User, :column_names).by(['custom_dropdown'])
  37. end
  38. end
  39. context 'when fields are invalid' do
  40. let(:resource) do
  41. {
  42. 'editable_in_signup' => false,
  43. 'id' => 80_000_766_844,
  44. 'name' => 'twitter_followers_count',
  45. 'label' => 'Twitter Follower Count',
  46. 'position' => 15,
  47. 'required_for_agents' => false,
  48. 'type' => 'default_twitter_followers_count',
  49. 'default' => true,
  50. 'customers_can_edit' => false,
  51. 'label_for_customers' => 'Twitter Follower Count',
  52. 'required_for_customers' => false,
  53. 'displayed_for_customers' => false,
  54. 'created_at' => '2021-04-09T13:24:02Z',
  55. 'updated_at' => '2021-04-09T13:24:02Z'
  56. }
  57. end
  58. it 'ignores other fields' do
  59. expect { process(process_payload) }.not_to change(User, :column_names)
  60. end
  61. end
  62. end
  63. end