dropdown_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. require 'rails_helper'
  2. RSpec.describe Import::Zendesk::ObjectAttribute::Dropdown do
  3. it 'imports select object attribute from dropdown object field' do
  4. attribute = double(
  5. title: 'Example attribute',
  6. description: 'Example attribute description',
  7. removable: false,
  8. active: true,
  9. position: 12,
  10. visible_in_portal: true,
  11. required_in_portal: true,
  12. required: true,
  13. type: 'dropdown',
  14. custom_field_options: [
  15. {
  16. 'id' => 1,
  17. 'value' => 'Key 1',
  18. 'name' => 'Value 1'
  19. },
  20. {
  21. 'id' => 2,
  22. 'value' => 'Key 2',
  23. 'name' => 'Value 2'
  24. },
  25. ]
  26. )
  27. expected_structure = {
  28. object: 'Ticket',
  29. name: 'example_field',
  30. display: 'Example attribute',
  31. data_type: 'select',
  32. data_option: {
  33. null: false,
  34. note: 'Example attribute description',
  35. default: '',
  36. options: {
  37. 'Key 1' => 'Value 1',
  38. 'Key 2' => 'Value 2'
  39. },
  40. },
  41. editable: true,
  42. active: true,
  43. screens: {
  44. edit: {
  45. Customer: {
  46. shown: true,
  47. null: false
  48. },
  49. view: {
  50. '-all-' => {
  51. shown: true
  52. }
  53. }
  54. }
  55. },
  56. position: 12,
  57. created_by_id: 1,
  58. updated_by_id: 1
  59. }
  60. expect(ObjectManager::Attribute).to receive(:add).with(expected_structure)
  61. expect(ObjectManager::Attribute).to receive(:migration_execute)
  62. created_instance = described_class.new('Ticket', 'example_field', attribute)
  63. end
  64. end