email_process_state_open_set.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. require 'test_helper'
  2. class EmailProcessStateOpenSet < ActiveSupport::TestCase
  3. setup do
  4. groups = Group.all
  5. roles = Role.where(name: 'Agent')
  6. @agent1 = User.create_or_update(
  7. login: 'agent-ticket-state-open-set@example.com',
  8. firstname: 'StateOpenSet',
  9. lastname: 'Agent1',
  10. email: 'agent-ticket-state-open-set@example.com',
  11. password: 'agentpw',
  12. active: true,
  13. roles: roles,
  14. groups: groups,
  15. updated_by_id: 1,
  16. created_by_id: 1,
  17. )
  18. roles = Role.where(name: 'Customer')
  19. @customer1 = User.create_or_update(
  20. login: 'customer-ticket-state-open-set@example.com',
  21. firstname: 'StateOpenSet',
  22. lastname: 'Customer',
  23. email: 'customer-ticket-state-open-set@example.com',
  24. password: 'customerpw',
  25. active: true,
  26. roles: roles,
  27. updated_by_id: 1,
  28. created_by_id: 1,
  29. )
  30. end
  31. test 'new as agent' do
  32. email_raw_string = "From: agent-ticket-state-open-set@example.com
  33. To: customer-ticket-state-open-set@example.com
  34. Subject: test sender is agent
  35. Some Text"
  36. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  37. ticket = Ticket.find(ticket_p.id)
  38. article = Ticket::Article.find(article_p.id)
  39. assert_equal('test sender is agent', ticket.title)
  40. assert_equal('new', ticket.state.name)
  41. assert_equal('Agent', ticket.create_article_sender.name)
  42. assert_equal('Agent', article.sender.name)
  43. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  44. assert_equal('StateOpenSet', ticket.customer.firstname)
  45. assert_equal('Customer', ticket.customer.lastname)
  46. article = Ticket::Article.create!(
  47. ticket_id: ticket.id,
  48. type_id: Ticket::Article::Type.find_by(name: 'email').id,
  49. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  50. body: 'test',
  51. internal: false,
  52. updated_by_id: @customer1.id,
  53. created_by_id: @customer1.id,
  54. )
  55. ticket.reload
  56. assert_equal('test sender is agent', ticket.title)
  57. assert_equal('new', ticket.state.name)
  58. assert_equal('Agent', ticket.create_article_sender.name)
  59. assert_equal('Customer', article.sender.name)
  60. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  61. assert_equal('StateOpenSet', ticket.customer.firstname)
  62. assert_equal('Customer', ticket.customer.lastname)
  63. article = Ticket::Article.create!(
  64. ticket_id: ticket.id,
  65. type_id: Ticket::Article::Type.find_by(name: 'email').id,
  66. sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
  67. body: 'test',
  68. internal: false,
  69. updated_by_id: @agent1.id,
  70. created_by_id: @agent1.id,
  71. )
  72. ticket.reload
  73. assert_equal('test sender is agent', ticket.title)
  74. assert_equal('open', ticket.state.name)
  75. assert_equal('Agent', ticket.create_article_sender.name)
  76. assert_equal('Agent', article.sender.name)
  77. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  78. assert_equal('StateOpenSet', ticket.customer.firstname)
  79. assert_equal('Customer', ticket.customer.lastname)
  80. end
  81. test 'new as customer' do
  82. email_raw_string = "From: customer-ticket-state-open-set@example.com
  83. To: agent-ticket-state-open-set@example.com
  84. Subject: test sender is customer
  85. Some Text"
  86. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  87. ticket = Ticket.find(ticket_p.id)
  88. article = Ticket::Article.find(article_p.id)
  89. assert_equal('test sender is customer', ticket.title)
  90. assert_equal('new', ticket.state.name)
  91. assert_equal('Customer', ticket.create_article_sender.name)
  92. assert_equal('Customer', article.sender.name)
  93. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  94. assert_equal('StateOpenSet', ticket.customer.firstname)
  95. assert_equal('Customer', ticket.customer.lastname)
  96. article = Ticket::Article.create!(
  97. ticket_id: ticket.id,
  98. type_id: Ticket::Article::Type.find_by(name: 'email').id,
  99. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  100. body: 'test',
  101. internal: false,
  102. updated_by_id: @customer1.id,
  103. created_by_id: @customer1.id,
  104. )
  105. ticket.reload
  106. assert_equal('test sender is customer', ticket.title)
  107. assert_equal('new', ticket.state.name)
  108. assert_equal('Customer', ticket.create_article_sender.name)
  109. assert_equal('Customer', article.sender.name)
  110. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  111. assert_equal('StateOpenSet', ticket.customer.firstname)
  112. assert_equal('Customer', ticket.customer.lastname)
  113. article = Ticket::Article.create!(
  114. ticket_id: ticket.id,
  115. type_id: Ticket::Article::Type.find_by(name: 'email').id,
  116. sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
  117. body: 'test',
  118. internal: false,
  119. updated_by_id: @agent1.id,
  120. created_by_id: @agent1.id,
  121. )
  122. ticket.reload
  123. assert_equal('test sender is customer', ticket.title)
  124. assert_equal('open', ticket.state.name)
  125. assert_equal('Customer', ticket.create_article_sender.name)
  126. assert_equal('Agent', article.sender.name)
  127. assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
  128. assert_equal('StateOpenSet', ticket.customer.firstname)
  129. assert_equal('Customer', ticket.customer.lastname)
  130. end
  131. end