contact_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::Contact, db_strategy: :reset, sequencer: :sequence do
  4. context 'when importing customers from Freshdesk' do
  5. let(:resource) do
  6. {
  7. 'active' => false,
  8. 'address' => nil,
  9. 'company_id' => 1001,
  10. 'description' => nil,
  11. 'email' => 'sam.ozzy@freshdesk.com',
  12. 'id' => 80_014_400_819,
  13. 'job_title' => nil,
  14. 'language' => 'en',
  15. 'mobile' => nil,
  16. 'name' => 'Sam Osborne',
  17. 'phone' => nil,
  18. 'time_zone' => 'Eastern Time (US & Canada)',
  19. 'twitter_id' => nil,
  20. 'custom_fields' => {
  21. 'cf_test_checkbox' => true,
  22. 'cf_custom_integer' => 999,
  23. 'cf_custom_dropdown' => 'key_2',
  24. 'cf_custom_decimal' => '1.1',
  25. },
  26. 'facebook_id' => nil,
  27. 'created_at' => '2021-04-09T13:29:43Z',
  28. 'updated_at' => '2021-04-09T13:29:43Z',
  29. 'csat_rating' => 103,
  30. 'preferred_source' => 'email',
  31. }
  32. end
  33. let(:field_map) do
  34. {
  35. 'User' => {
  36. 'cf_test_checkbox' => 'cf_test_checkbox',
  37. 'cf_custom_integer' => 'cf_custom_integer',
  38. 'cf_custom_dropdown' => 'cf_custom_dropdown',
  39. 'cf_custom_decimal' => 'cf_custom_decimal'
  40. }
  41. }
  42. end
  43. let(:id_map) do
  44. {
  45. 'Organization' => { 1001 => 1 }
  46. }
  47. end
  48. let(:process_payload) do
  49. {
  50. import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
  51. dry_run: false,
  52. resource: resource,
  53. field_map: field_map,
  54. id_map: id_map,
  55. }
  56. end
  57. let(:imported_user) do
  58. {
  59. firstname: 'Sam',
  60. lastname: 'Osborne',
  61. login: 'sam.ozzy@freshdesk.com',
  62. email: 'sam.ozzy@freshdesk.com',
  63. active: true,
  64. cf_custom_dropdown: 'key_2',
  65. cf_custom_integer: 999,
  66. cf_test_checkbox: true,
  67. cf_custom_decimal: '1.1',
  68. }
  69. end
  70. before do
  71. create(:object_manager_attribute_select, object_name: 'User', name: 'cf_custom_dropdown')
  72. create(:object_manager_attribute_integer, object_name: 'User', name: 'cf_custom_integer')
  73. create(:object_manager_attribute_boolean, object_name: 'User', name: 'cf_test_checkbox')
  74. create(:object_manager_attribute_text, object_name: 'User', name: 'cf_custom_decimal')
  75. ObjectManager::Attribute.migration_execute
  76. end
  77. it 'imports customer correctly (increased user count)' do
  78. expect { process(process_payload) }.to change(User, :count).by(1)
  79. end
  80. it 'imports customer data correctly' do
  81. process(process_payload)
  82. expect(User.last).to have_attributes(imported_user)
  83. end
  84. context 'with deleted flag in resource' do
  85. before do
  86. resource['deleted'] = true
  87. imported_user[:active] = false
  88. end
  89. it 'imports customer data correctly' do
  90. process(process_payload)
  91. expect(User.last).to have_attributes(imported_user)
  92. end
  93. end
  94. context 'without organizations' do
  95. let(:id_map) do
  96. {}
  97. end
  98. it 'imports customer correctly (increased user count)' do
  99. expect { process(process_payload) }.to change(User, :count).by(1)
  100. end
  101. end
  102. end
  103. end