trigger_assets_test.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require 'test_helper'
  2. class TriggerAssetsTest < ActiveSupport::TestCase
  3. test 'assets' do
  4. UserInfo.current_user_id = 1
  5. roles = Role.where(name: %w[Customer])
  6. user1 = User.create_or_update(
  7. login: 'assets_trigger1@example.org',
  8. firstname: 'assets_trigger1',
  9. lastname: 'assets_trigger1',
  10. email: 'assets_trigger1@example.org',
  11. password: 'some_pass',
  12. active: true,
  13. roles: roles,
  14. )
  15. user2 = User.create_or_update(
  16. login: 'assets_trigger2@example.org',
  17. firstname: 'assets_trigger2',
  18. lastname: 'assets_trigger2',
  19. email: 'assets_trigger2@example.org',
  20. password: 'some_pass',
  21. active: true,
  22. roles: roles,
  23. )
  24. user3 = User.create_or_update(
  25. login: 'assets_trigger3@example.org',
  26. firstname: 'assets_trigger3',
  27. lastname: 'assets_trigger3',
  28. email: 'assets_trigger3@example.org',
  29. password: 'some_pass',
  30. active: true,
  31. roles: roles,
  32. )
  33. group1 = Group.create_or_update(
  34. name: 'group1_trigger',
  35. active: true,
  36. )
  37. ticket_state1 = Ticket::State.find_by(name: 'new')
  38. ticket_state2 = Ticket::State.find_by(name: 'open')
  39. ticket_priority2 = Ticket::Priority.find_by(name: '2 normal')
  40. trigger = Trigger.create_or_update(
  41. name: 'my trigger',
  42. condition: {
  43. 'ticket.state_id' => {
  44. operator: 'is',
  45. value: [ ticket_state1.id ],
  46. },
  47. 'ticket.owner_id' => {
  48. operator: 'is',
  49. pre_condition: 'specific',
  50. value: user1.id,
  51. value_completion: 'John Smith <john.smith@example.com>'
  52. },
  53. },
  54. perform: {
  55. 'ticket.group_id' => {
  56. value: group1.id.to_s,
  57. },
  58. },
  59. disable_notification: true,
  60. )
  61. assets = trigger.assets({})
  62. assert(assets[:User][user1.id])
  63. assert_not(assets[:User][user2.id])
  64. assert_not(assets[:User][user3.id])
  65. assert(assets[:TicketState][ticket_state1.id])
  66. assert_not(assets[:TicketState][ticket_state2.id])
  67. assert_not(assets[:TicketPriority])
  68. assert(assets[:Group][group1.id])
  69. end
  70. end