checks_human_changes_examples.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'ChecksHumanChanges' do
  3. describe 'checks human changes' do
  4. subject { described_class.new(item).human_changes(item_changes, ticket, agent) }
  5. let(:agent) { create(:agent) }
  6. let(:ticket) { create(:ticket) }
  7. let(:item) do
  8. {
  9. object: 'Ticket',
  10. type: 'update',
  11. object_id: ticket.id,
  12. interface_handle: 'application_server',
  13. changes: item_changes,
  14. created_at: Time.zone.now,
  15. user_id: 1,
  16. }
  17. end
  18. let(:item_changes) { {} }
  19. context 'without human changes' do
  20. it 'check for changes' do
  21. expect(subject).to eq({})
  22. end
  23. end
  24. context 'with human changes' do
  25. let(:item_changes) do
  26. {
  27. 'priority_id' => [Ticket::Priority.find_by(name: '2 normal').id, Ticket::Priority.find_by(name: '3 high').id],
  28. 'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
  29. }
  30. end
  31. before do
  32. ticket.update!(priority_id: Ticket::Priority.find_by(name: '3 high').id)
  33. end
  34. it 'check for changes' do
  35. expect(subject).to eq({
  36. 'Priority' => ['2 normal', '3 high'],
  37. 'Pending till' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
  38. })
  39. end
  40. context 'without a user' do
  41. let(:agent) { nil }
  42. it 'check for changes' do
  43. expect(subject).to eq({
  44. 'Priority' => ['2 normal', '3 high'],
  45. 'Pending till' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
  46. })
  47. end
  48. end
  49. end
  50. end
  51. end