customer_spec.rb 2.1 KB

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