organization_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/sequencer/sequence/import/kayako/examples/object_custom_field_values_examples'
  4. RSpec.describe Sequencer::Sequence::Import::Kayako::Organization, db_strategy: :reset, sequencer: :sequence do
  5. context 'when importing organizations from Kayako' do
  6. let(:resource) do
  7. {
  8. 'id' => 80_000_602_705,
  9. 'name' => 'Test Foundation',
  10. 'legacy_id' => nil,
  11. 'is_shared' => false,
  12. 'domains' => [
  13. {
  14. 'id' => 3,
  15. 'domain' => 'test-foundation.com',
  16. 'is_primary' => true,
  17. 'is_validated' => false,
  18. 'created_at' => '2021-08-16T09:01:14+00:00',
  19. 'updated_at' => '2021-08-16T09:01:14+00:00',
  20. 'resource_type' => 'identity_domain',
  21. }
  22. ],
  23. 'is_validated' => nil,
  24. 'phone' => [],
  25. 'addresses' => [],
  26. 'websites' => [],
  27. 'pinned_notes_count' => 0,
  28. 'created_at' => '2021-08-16T09:01:14+00:00',
  29. 'updated_at' => '2021-08-18T20:37:52+00:00',
  30. 'resource_type' => 'organization',
  31. }
  32. end
  33. let(:process_payload) do
  34. {
  35. import_job: build_stubbed(:import_job, name: 'Import::Kayako', payload: {}),
  36. dry_run: false,
  37. resource: resource,
  38. field_map: {},
  39. id_map: {},
  40. default_language: 'en-us',
  41. }
  42. end
  43. let(:imported_organization) do
  44. {
  45. name: 'Test Foundation',
  46. domain: 'test-foundation.com',
  47. domain_assignment: true,
  48. }
  49. end
  50. it 'increased organization count' do
  51. expect { process(process_payload) }.to change(Organization, :count).by(1)
  52. end
  53. it 'adds correct organization data' do
  54. process(process_payload)
  55. expect(Organization.last).to have_attributes(imported_organization)
  56. end
  57. context 'when importing custom fields' do
  58. include_examples 'Object custom field values', object_name: 'Organization', klass: Organization
  59. end
  60. context 'when resource has no domains' do
  61. let(:resource) do
  62. super().merge('domains' => [])
  63. end
  64. before do
  65. imported_organization[:domain] = nil
  66. imported_organization[:domain_assignment] = false
  67. end
  68. it 'adds organizations' do
  69. process(process_payload)
  70. expect(Organization.last).to have_attributes(imported_organization)
  71. end
  72. end
  73. end
  74. end