priority_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Import::OTRS::Priority 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_priority_json(file)
  17. json_fixture("import/otrs/priority/#{file}")
  18. end
  19. let(:import_object) { Ticket::Priority }
  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_priority_json('default') }
  24. let(:zammad_structure) do
  25. {
  26. created_by_id: 1,
  27. updated_by_id: 1,
  28. active: true,
  29. updated_at: '2014-04-28 10:53:18',
  30. created_at: '2014-04-28 10:53:18',
  31. ui_color: 'high-priority',
  32. ui_icon: 'important',
  33. name: '4 high',
  34. id: '4'
  35. }
  36. end
  37. it 'creates' do
  38. creates_with(zammad_structure)
  39. end
  40. it 'updates' do
  41. updates_with(zammad_structure)
  42. end
  43. end
  44. context 'normal' do
  45. let(:object_structure) { load_priority_json('normal') }
  46. let(:zammad_structure) do
  47. {
  48. created_by_id: 1,
  49. updated_by_id: 1,
  50. active: true,
  51. updated_at: '2014-04-28 10:53:18',
  52. created_at: '2014-04-28 10:53:18',
  53. ui_color: nil,
  54. ui_icon: nil,
  55. name: '3 normal',
  56. id: '3'
  57. }
  58. end
  59. it 'updates' do
  60. updates_with(zammad_structure)
  61. end
  62. end
  63. context 'low' do
  64. let(:object_structure) { load_priority_json('low') }
  65. let(:zammad_structure) do
  66. {
  67. created_by_id: 1,
  68. updated_by_id: 1,
  69. active: true,
  70. updated_at: '2014-04-28 10:53:18',
  71. created_at: '2014-04-28 10:53:18',
  72. ui_color: 'low-priority',
  73. ui_icon: 'low-priority',
  74. name: '2 low',
  75. id: '2'
  76. }
  77. end
  78. it 'updates' do
  79. updates_with(zammad_structure)
  80. end
  81. end
  82. end