diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 8a4c06ece..4b8ac988c 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -86,7 +86,7 @@ class TicketsController < ApplicationController if clean_params[:customer_id] && clean_params[:customer_id] =~ /^guess:(.+?)$/ email = $1 if email !~ /@/ || email =~ /(>|<|\||\!|"|ยง|'|\$|%|&|\(|\)|\?|\s)/ - render json: { error: 'Invalid email' }, status: :unprocessable_entity + render json: { error: 'Invalid email of customer' }, status: :unprocessable_entity return end customer = User.find_by(email: email) diff --git a/test/controllers/tickets_controller_test.rb b/test/controllers/tickets_controller_test.rb index 4b7cab4f0..c07826e98 100644 --- a/test/controllers/tickets_controller_test.rb +++ b/test/controllers/tickets_controller_test.rb @@ -127,6 +127,29 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest assert_equal(@agent.id, result['created_by_id']) end + test '01.04 ticket create with agent - minimal article with guess customer' do + credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw') + params = { + title: 'a new ticket #4', + group: 'Users', + priority: '2 normal', + state: 'new', + customer_id: 'guess:some_new_customer@example.com', + article: { + body: 'some test 123', + }, + } + post '/api/v1/tickets', params.to_json, @headers.merge('Authorization' => credentials) + assert_response(201) + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id']) + assert_equal('a new ticket #4', result['title']) + assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id']) + assert_equal(@agent.id, result['updated_by_id']) + assert_equal(@agent.id, result['created_by_id']) + end + test '02.02 ticket create with agent' do credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw') params = {