sla_assets_test.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'test_helper'
  2. class SlaAssetsTest < 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_sla1@example.org',
  8. firstname: 'assets_sla1',
  9. lastname: 'assets_sla1',
  10. email: 'assets_sla1@example.org',
  11. password: 'some_pass',
  12. active: true,
  13. roles: roles,
  14. )
  15. user2 = User.create_or_update(
  16. login: 'assets_sla2@example.org',
  17. firstname: 'assets_sla2',
  18. lastname: 'assets_sla2',
  19. email: 'assets_sla2@example.org',
  20. password: 'some_pass',
  21. active: true,
  22. roles: roles,
  23. )
  24. calendar1 = Calendar.create_or_update(
  25. name: 'US 1',
  26. timezone: 'America/Los_Angeles',
  27. business_hours: {
  28. mon: { '09:00' => '17:00' },
  29. tue: { '09:00' => '17:00' },
  30. wed: { '09:00' => '17:00' },
  31. thu: { '09:00' => '17:00' },
  32. fri: { '09:00' => '17:00' }
  33. },
  34. default: true,
  35. ical_url: nil,
  36. updated_by_id: 1,
  37. created_by_id: 1,
  38. )
  39. ticket_state1 = Ticket::State.find_by(name: 'new')
  40. ticket_state2 = Ticket::State.find_by(name: 'open')
  41. sla = Sla.create_or_update(
  42. name: 'my asset test',
  43. calendar_id: calendar1.id,
  44. condition: {
  45. 'ticket.state_id' => {
  46. operator: 'is',
  47. value: [ ticket_state1.id, ticket_state2.id ],
  48. },
  49. 'ticket.owner_id' => {
  50. operator: 'is',
  51. pre_condition: 'specific',
  52. value: user1.id,
  53. value_completion: 'John Smith <john.smith@example.com>'
  54. },
  55. },
  56. )
  57. assets = sla.assets({})
  58. assert(assets[:User][user1.id], 'check assets')
  59. assert_not(assets[:User][user2.id], 'check assets')
  60. assert(assets[:TicketState][ticket_state1.id], 'check assets')
  61. assert(assets[:TicketState][ticket_state2.id], 'check assets')
  62. assert(assets[:Calendar][calendar1.id], 'check assets')
  63. end
  64. end