123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- require 'test_helper'
- class EmailProcessStateOpenSet < ActiveSupport::TestCase
- setup do
- groups = Group.all
- roles = Role.where(name: 'Agent')
- @agent1 = User.create_or_update(
- login: 'agent-ticket-state-open-set@example.com',
- firstname: 'StateOpenSet',
- lastname: 'Agent1',
- email: 'agent-ticket-state-open-set@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: groups,
- updated_by_id: 1,
- created_by_id: 1,
- )
- roles = Role.where(name: 'Customer')
- @customer1 = User.create_or_update(
- login: 'customer-ticket-state-open-set@example.com',
- firstname: 'StateOpenSet',
- lastname: 'Customer',
- email: 'customer-ticket-state-open-set@example.com',
- password: 'customerpw',
- active: true,
- roles: roles,
- updated_by_id: 1,
- created_by_id: 1,
- )
- end
- test 'new as agent' do
- email_raw_string = "From: agent-ticket-state-open-set@example.com
- To: customer-ticket-state-open-set@example.com
- Subject: test sender is agent
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- ticket = Ticket.find(ticket_p.id)
- article = Ticket::Article.find(article_p.id)
- assert_equal('test sender is agent', ticket.title)
- assert_equal('new', ticket.state.name)
- assert_equal('Agent', ticket.create_article_sender.name)
- assert_equal('Agent', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.find_by(name: 'email').id,
- sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
- body: 'test',
- internal: false,
- updated_by_id: @customer1.id,
- created_by_id: @customer1.id,
- )
- ticket.reload
- assert_equal('test sender is agent', ticket.title)
- assert_equal('new', ticket.state.name)
- assert_equal('Agent', ticket.create_article_sender.name)
- assert_equal('Customer', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.find_by(name: 'email').id,
- sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
- body: 'test',
- internal: false,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- ticket.reload
- assert_equal('test sender is agent', ticket.title)
- assert_equal('open', ticket.state.name)
- assert_equal('Agent', ticket.create_article_sender.name)
- assert_equal('Agent', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- end
- test 'new as customer' do
- email_raw_string = "From: customer-ticket-state-open-set@example.com
- To: agent-ticket-state-open-set@example.com
- Subject: test sender is customer
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- ticket = Ticket.find(ticket_p.id)
- article = Ticket::Article.find(article_p.id)
- assert_equal('test sender is customer', ticket.title)
- assert_equal('new', ticket.state.name)
- assert_equal('Customer', ticket.create_article_sender.name)
- assert_equal('Customer', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.find_by(name: 'email').id,
- sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
- body: 'test',
- internal: false,
- updated_by_id: @customer1.id,
- created_by_id: @customer1.id,
- )
- ticket.reload
- assert_equal('test sender is customer', ticket.title)
- assert_equal('new', ticket.state.name)
- assert_equal('Customer', ticket.create_article_sender.name)
- assert_equal('Customer', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.find_by(name: 'email').id,
- sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
- body: 'test',
- internal: false,
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- ticket.reload
- assert_equal('test sender is customer', ticket.title)
- assert_equal('open', ticket.state.name)
- assert_equal('Customer', ticket.create_article_sender.name)
- assert_equal('Agent', article.sender.name)
- assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
- assert_equal('StateOpenSet', ticket.customer.firstname)
- assert_equal('Customer', ticket.customer.lastname)
- end
- end
|