company_field_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::CompanyField, sequencer: :sequence do
  4. context 'when trying to import company 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. 'id' => 80_000_387_409,
  19. 'name' => 'custom_dropdown',
  20. 'label' => 'custom_dropdown',
  21. 'position' => 9,
  22. 'required_for_agents' => false,
  23. 'type' => 'custom_dropdown',
  24. 'default' => false,
  25. 'created_at' => '2021-04-12T20:24:41Z',
  26. 'updated_at' => '2021-04-12T20:24:41Z',
  27. 'choices' => [
  28. 'First Choice',
  29. 'Second Choice',
  30. ],
  31. }
  32. end
  33. it 'adds custom fields' do
  34. expect { process(process_payload) }.to change(Organization, :column_names).by(['custom_dropdown'])
  35. end
  36. end
  37. context 'when fields are invalid' do
  38. let(:resource) do
  39. {
  40. 'id' => 80_000_382_712,
  41. 'name' => 'name',
  42. 'label' => 'Company Name',
  43. 'position' => 1,
  44. 'required_for_agents' => true,
  45. 'type' => 'default_name',
  46. 'default' => true,
  47. 'created_at' => '2021-04-09T13:23:59Z',
  48. 'updated_at' => '2021-04-09T13:23:59Z'
  49. }
  50. end
  51. it 'ignores other fields' do
  52. expect { process(process_payload) }.not_to change(Organization, :column_names)
  53. end
  54. end
  55. end
  56. end