company_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Sequencer::Sequence::Import::Freshdesk::Company, db_strategy: :reset, sequencer: :sequence do
  4. context 'when importing companies from Freshdesk' do
  5. let(:resource) do
  6. { 'id' => 80_000_602_705,
  7. 'name' => 'Test Foundation',
  8. 'description' => nil,
  9. 'note' => nil,
  10. 'domains' => ['acmecorp.com'],
  11. 'created_at' => '2021-04-09T13:24:00Z',
  12. 'updated_at' => '2021-04-12T20:25:36Z',
  13. 'custom_fields' => {
  14. 'cf_test_checkbox' => true,
  15. 'cf_custom_integer' => 999,
  16. 'cf_custom_dropdown' => 'key_2',
  17. 'cf_custom_decimal' => '1.1',
  18. },
  19. 'health_score' => nil,
  20. 'account_tier' => 'Basic',
  21. 'renewal_date' => nil,
  22. 'industry' => nil }
  23. end
  24. let(:field_map) do
  25. {
  26. 'Organization' => {
  27. 'cf_test_checkbox' => 'cf_test_checkbox',
  28. 'cf_custom_integer' => 'cf_custom_integer',
  29. 'cf_custom_dropdown' => 'cf_custom_dropdown',
  30. 'cf_custom_decimal' => 'cf_custom_decimal'
  31. }
  32. }
  33. end
  34. let(:process_payload) do
  35. {
  36. import_job: build_stubbed(:import_job, name: 'Import::Freshdesk', payload: {}),
  37. dry_run: false,
  38. resource: resource,
  39. field_map: field_map,
  40. id_map: {},
  41. }
  42. end
  43. let(:imported_organization) do
  44. {
  45. name: 'Test Foundation',
  46. note: nil,
  47. domain: 'acmecorp.com',
  48. cf_custom_dropdown: 'key_2',
  49. cf_custom_integer: 999,
  50. cf_test_checkbox: true,
  51. cf_custom_decimal: '1.1',
  52. }
  53. end
  54. before do
  55. create(:object_manager_attribute_select, object_name: 'Organization', name: 'cf_custom_dropdown')
  56. create(:object_manager_attribute_integer, object_name: 'Organization', name: 'cf_custom_integer')
  57. create(:object_manager_attribute_boolean, object_name: 'Organization', name: 'cf_test_checkbox')
  58. create(:object_manager_attribute_text, object_name: 'Organization', name: 'cf_custom_decimal')
  59. ObjectManager::Attribute.migration_execute
  60. end
  61. it 'increased organization count' do
  62. expect { process(process_payload) }.to change(Organization, :count).by(1)
  63. end
  64. it 'adds correct organization data' do
  65. process(process_payload)
  66. expect(Organization.last).to have_attributes(imported_organization)
  67. end
  68. context 'when resource has no domains' do
  69. let(:resource) do
  70. { 'id' => 80_000_602_705,
  71. 'name' => 'Test Foundation',
  72. 'description' => nil,
  73. 'note' => nil,
  74. 'domains' => [],
  75. 'created_at' => '2021-04-09T13:24:00Z',
  76. 'updated_at' => '2021-04-12T20:25:36Z',
  77. 'custom_fields' => {
  78. 'cf_test_checkbox' => true,
  79. 'cf_custom_integer' => 999,
  80. 'cf_custom_dropdown' => 'key_2',
  81. 'cf_custom_decimal' => '1.1',
  82. },
  83. 'health_score' => nil,
  84. 'account_tier' => 'Basic',
  85. 'renewal_date' => nil,
  86. 'industry' => nil }
  87. end
  88. before do
  89. imported_organization[:domain] = nil
  90. end
  91. it 'adds organizations' do
  92. process(process_payload)
  93. expect(Organization.last).to have_attributes(imported_organization)
  94. end
  95. end
  96. end
  97. end