email_process_sender_name_update_if_needed.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class EmailProcessSenderNameUpdateIfNeeded < ActiveSupport::TestCase
  4. test 'basic' do
  5. email_raw_string = "From: customer@example.com
  6. To: myzammad@example.com
  7. Subject: test sender name update 1
  8. Some Text"
  9. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  10. ticket = Ticket.find(ticket_p.id)
  11. article = Ticket::Article.find(article_p.id)
  12. assert_equal('test sender name update 1', ticket.title)
  13. assert_equal('new', ticket.state.name)
  14. assert_equal('Customer', ticket.create_article_sender.name)
  15. assert_equal('Customer', article.sender.name)
  16. assert_equal('customer@example.com', ticket.customer.email)
  17. assert_equal('', ticket.customer.firstname)
  18. assert_equal('', ticket.customer.lastname)
  19. email_raw_string = "From: Max Smith <customer@example.com>
  20. To: myzammad@example.com
  21. Subject: test sender name update 2
  22. Some Text"
  23. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  24. ticket = Ticket.find(ticket_p.id)
  25. article = Ticket::Article.find(article_p.id)
  26. assert_equal('test sender name update 2', ticket.title)
  27. assert_equal('new', ticket.state.name)
  28. assert_equal('Customer', ticket.create_article_sender.name)
  29. assert_equal('Customer', article.sender.name)
  30. assert_equal('customer@example.com', ticket.customer.email)
  31. assert_equal('Max', ticket.customer.firstname)
  32. assert_equal('Smith', ticket.customer.lastname)
  33. end
  34. end