state_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Import::OTRS::State do
  4. def creates_with(zammad_structure)
  5. allow(import_object).to receive(:find_by).and_return(nil)
  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(import_object).to receive(:find_by).and_return(existing_object)
  13. expect(existing_object).to receive(:update!).with(zammad_structure)
  14. expect(import_object).not_to receive(:new)
  15. start_import_test
  16. end
  17. def load_state_json(file)
  18. json_fixture("import/otrs/state/#{file}")
  19. end
  20. let(:import_object) { Ticket::State }
  21. let(:existing_object) { instance_double(import_object) }
  22. let(:start_import_test) { described_class.new(object_structure) }
  23. context 'closed' do
  24. let(:object_structure) { load_state_json('default') }
  25. let(:zammad_structure) do
  26. {
  27. created_by_id: 1,
  28. updated_by_id: 1,
  29. active: '1',
  30. state_type_id: 5,
  31. updated_at: '2014-04-28 10:53:18',
  32. created_at: '2014-04-28 10:53:18',
  33. name: 'closed successful',
  34. id: '2',
  35. note: 'Ticket is closed successful.'
  36. }
  37. end
  38. it 'creates' do
  39. creates_with(zammad_structure)
  40. end
  41. it 'updates' do
  42. updates_with(zammad_structure)
  43. end
  44. end
  45. end