customer_user_spec.rb 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Import::OTRS::CustomerUser do
  4. def creates_with(zammad_structure)
  5. allow_organization_lookup
  6. allow(import_object).to receive(:new).with(zammad_structure).and_call_original
  7. expect_any_instance_of(import_object).to receive(:save)
  8. expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
  9. start_import_test
  10. end
  11. def updates_with(zammad_structure)
  12. allow_organization_lookup
  13. allow(import_object).to receive(:find_by).and_return(existing_object)
  14. # we delete the :role_ids from the zammad_structure to make sure that
  15. # a) role_ids call returns the initial role_ids
  16. # b) and update! gets called without them
  17. allow(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once)
  18. expect(existing_object).to receive(:update!).with(zammad_structure)
  19. expect(import_object).not_to receive(:new)
  20. start_import_test
  21. end
  22. def allow_organization_lookup
  23. allow(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization)
  24. allow(organization).to receive(:id).and_return(organization_id)
  25. end
  26. def load_customer_json(file)
  27. json_fixture("import/otrs/customer_user/#{file}")
  28. end
  29. let(:import_object) { User }
  30. let(:existing_object) { instance_double(import_object) }
  31. let(:start_import_test) { described_class.new(object_structure) }
  32. let(:organization) { instance_double(Organization) }
  33. let(:organization_id) { 1337 }
  34. context 'regular user' do
  35. let(:object_structure) { load_customer_json('default') }
  36. let(:zammad_structure) do
  37. {
  38. created_by_id: '1',
  39. updated_by_id: '1',
  40. active: true,
  41. source: 'OTRS Import',
  42. organization_id: 1337,
  43. role_ids: [3],
  44. updated_at: '2014-06-07 02:31:31',
  45. created_at: '2014-06-07 02:31:31',
  46. note: '',
  47. email: 'qa100@t-online.de',
  48. firstname: 'test669673',
  49. lastname: 'test669673',
  50. login: 'test669673',
  51. password: 'secret_password',
  52. phone: nil,
  53. fax: nil,
  54. mobile: nil,
  55. street: nil,
  56. zip: nil,
  57. city: nil,
  58. country: nil
  59. }
  60. end
  61. it 'creates' do
  62. creates_with(zammad_structure)
  63. end
  64. it 'updates' do
  65. updates_with(zammad_structure)
  66. end
  67. end
  68. context 'no timestamps' do
  69. let(:object_structure) { load_customer_json('no_timestamps') }
  70. let(:zammad_structure) do
  71. {
  72. created_by_id: '1',
  73. updated_by_id: '1',
  74. active: true,
  75. source: 'OTRS Import',
  76. organization_id: 1337,
  77. role_ids: [3],
  78. updated_at: DateTime.current,
  79. created_at: DateTime.current,
  80. note: '',
  81. email: 'qa100@t-online.de',
  82. firstname: 'test669673',
  83. lastname: 'test669673',
  84. login: 'test669673',
  85. password: 'secret_password',
  86. phone: nil,
  87. fax: nil,
  88. mobile: nil,
  89. street: nil,
  90. zip: nil,
  91. city: nil,
  92. country: nil
  93. }
  94. end
  95. before do
  96. freeze_time
  97. end
  98. it 'creates' do
  99. creates_with(zammad_structure)
  100. end
  101. it 'updates' do
  102. updates_with(zammad_structure)
  103. end
  104. end
  105. context 'regular user with capitalized email' do
  106. let(:object_structure) { load_customer_json('capital_email') }
  107. let(:zammad_structure) do
  108. {
  109. created_by_id: '1',
  110. updated_by_id: '1',
  111. active: true,
  112. source: 'OTRS Import',
  113. organization_id: 1337,
  114. role_ids: [3],
  115. updated_at: '2014-06-07 02:31:31',
  116. created_at: '2014-06-07 02:31:31',
  117. note: '',
  118. email: 'qa100@t-online.de',
  119. firstname: 'test669673',
  120. lastname: 'test669673',
  121. login: 'test669673',
  122. password: 'secret_password',
  123. phone: nil,
  124. fax: nil,
  125. mobile: nil,
  126. street: nil,
  127. zip: nil,
  128. city: nil,
  129. country: nil
  130. }
  131. end
  132. it 'creates' do
  133. creates_with(zammad_structure)
  134. end
  135. it 'updates' do
  136. updates_with(zammad_structure)
  137. end
  138. end
  139. context 'regular user with camelcase login' do
  140. let(:object_structure) { load_customer_json('camel_case_login') }
  141. let(:zammad_structure) do
  142. {
  143. created_by_id: '1',
  144. updated_by_id: '1',
  145. active: true,
  146. source: 'OTRS Import',
  147. organization_id: 1337,
  148. role_ids: [3],
  149. updated_at: '2014-06-07 02:31:31',
  150. created_at: '2014-06-07 02:31:31',
  151. note: '',
  152. email: 'qa100@t-online.de',
  153. firstname: 'test669673',
  154. lastname: 'test669673',
  155. login: 'test669673',
  156. password: 'secret_password',
  157. phone: nil,
  158. fax: nil,
  159. mobile: nil,
  160. street: nil,
  161. zip: nil,
  162. city: nil,
  163. country: nil
  164. }
  165. end
  166. it 'creates' do
  167. creates_with(zammad_structure)
  168. end
  169. it 'updates' do
  170. updates_with(zammad_structure)
  171. end
  172. end
  173. end