queue_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Import::OTRS::Queue do
  4. def creates_with(zammad_structure)
  5. allow(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. allow(import_object).to receive(:find_by).and_return(existing_object)
  12. expect(existing_object).to receive(:update!).with(zammad_structure)
  13. expect(import_object).not_to receive(:new)
  14. start_import_test
  15. end
  16. def load_queue_json(file)
  17. json_fixture("import/otrs/queue/#{file}")
  18. end
  19. let(:import_object) { Group }
  20. let(:existing_object) { instance_double(import_object) }
  21. let(:start_import_test) { described_class.new(object_structure) }
  22. context 'default' do
  23. let(:object_structure) { load_queue_json('default') }
  24. let(:zammad_structure) do
  25. {
  26. created_by_id: 1,
  27. updated_by_id: 1,
  28. active: false,
  29. updated_at: '2014-05-13 10:54:11',
  30. created_at: '2014-05-13 10:54:11',
  31. name: 'UnitTestQueue45699',
  32. id: '11',
  33. note: 'Some comment'
  34. }
  35. end
  36. it 'creates' do
  37. creates_with(zammad_structure)
  38. end
  39. it 'updates' do
  40. updates_with(zammad_structure)
  41. end
  42. end
  43. end