customer_user_spec.rb 5.7 KB

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