customer_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'rails_helper'
  2. RSpec.describe Import::OTRS::Customer do
  3. def creates_with(zammad_structure)
  4. expect(import_object).to receive(:create).with(zammad_structure).and_return(existing_object)
  5. expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
  6. start_import_test
  7. end
  8. def updates_with(zammad_structure)
  9. expect(import_object).to receive(:find_by).and_return(existing_object)
  10. expect(existing_object).to receive(:update!).with(zammad_structure)
  11. expect(import_object).not_to receive(:new)
  12. start_import_test
  13. end
  14. def load_customer_json(file)
  15. json_fixture("import/otrs/customer/#{file}")
  16. end
  17. let(:import_object) { Organization }
  18. let(:existing_object) { instance_double(import_object) }
  19. let(:start_import_test) { described_class.new(object_structure) }
  20. context 'Organization' do
  21. let(:object_structure) { load_customer_json('default') }
  22. let(:zammad_structure) do
  23. {
  24. created_by_id: '1',
  25. updated_by_id: '1',
  26. active: false,
  27. updated_at: '2014-06-06 12:41:03',
  28. created_at: '2014-06-06 12:41:03',
  29. name: 'test922896',
  30. note: 'test922896'
  31. }
  32. end
  33. it 'creates' do
  34. creates_with(zammad_structure)
  35. end
  36. it 'updates' do
  37. updates_with(zammad_structure)
  38. end
  39. end
  40. context 'OTRS CustomerID' do
  41. let(:customer_id) { 'test922896' }
  42. let(:object_structure) { load_customer_json('default') }
  43. let(:otrs_dummy_response) do
  44. [
  45. object_structure
  46. ]
  47. end
  48. it 'responds to by_customer_id' do
  49. expect(described_class).to respond_to('by_customer_id')
  50. end
  51. it 'finds Organizations by OTRS CustomerID' do
  52. expect(Import::OTRS::Requester).to receive(:load).and_return(otrs_dummy_response)
  53. expect(import_object).to receive(:find_by).with(name: customer_id).and_return(existing_object)
  54. expect(described_class.by_customer_id(customer_id)).to be(existing_object)
  55. end
  56. end
  57. end