Added test for automatically customer creation via guess:new_customer@example.com as customer_id.

This commit is contained in:
Martin Edenhofer 2016-08-26 10:30:37 +02:00
parent 7dad383c07
commit 00f9c47839
2 changed files with 24 additions and 1 deletions

View file

@ -86,7 +86,7 @@ class TicketsController < ApplicationController
if clean_params[:customer_id] && clean_params[:customer_id] =~ /^guess:(.+?)$/ if clean_params[:customer_id] && clean_params[:customer_id] =~ /^guess:(.+?)$/
email = $1 email = $1
if email !~ /@/ || email =~ /(>|<|\||\!|"|§|'|\$|%|&|\(|\)|\?|\s)/ if email !~ /@/ || email =~ /(>|<|\||\!|"|§|'|\$|%|&|\(|\)|\?|\s)/
render json: { error: 'Invalid email' }, status: :unprocessable_entity render json: { error: 'Invalid email of customer' }, status: :unprocessable_entity
return return
end end
customer = User.find_by(email: email) customer = User.find_by(email: email)

View file

@ -127,6 +127,29 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
assert_equal(@agent.id, result['created_by_id']) assert_equal(@agent.id, result['created_by_id'])
end 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 test '02.02 ticket create with agent' do
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw') credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
params = { params = {