Majority of create ticket logic done. Just need to add attachments(?) and retriever SQL-specific fields

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 1a8a989e87
commit 489f191a13

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: mkoch
* Date: 2/12/2017
* Time: 4:54 PM
*/
namespace BusinessLogic\Tickets;
class Autoassigner {
/**
* @param $categoryId int
* @param $heskSettings array
* @return int|null The user ID, or null if no user found
*/
function getNextUserForTicket($categoryId, $heskSettings) {
return 0;
}
}

@ -3,7 +3,6 @@
namespace BusinessLogic\Tickets;
class CreateTicketByCustomerModel {
// Metadata
/**
* @var string
*/
@ -24,7 +23,6 @@ class CreateTicketByCustomerModel {
*/
public $category;
// Message
/**
* @var string
*/
@ -35,13 +33,18 @@ class CreateTicketByCustomerModel {
*/
public $message;
/**
* @var bool
*/
public $html;
/**
* @var array
*/
public $customFields;
/**
* @var double[]|null
* @var string[]|null The latitude/longitude pair, or relevant error code (E-#)
*/
public $location;

@ -112,7 +112,7 @@ class Ticket {
public $name;
/**
* @var string
* @var string|null
*/
public $email;
@ -127,12 +127,12 @@ class Ticket {
public $priorityId;
/**
* @var string
* @var string|null
*/
public $subject;
/**
* @var string
* @var string|null
*/
public $message;
@ -202,7 +202,7 @@ class Ticket {
public $numberOfStaffReplies;
/**
* @var int
* @var int|null
*/
public $ownerId;

@ -16,14 +16,20 @@ class TicketCreator {
*/
private $trackingIdGenerator;
/**
* @var $autoassigner Autoassigner
*/
private $autoassigner;
/**
* @var $ticketGateway TicketGateway
*/
private $ticketGateway;
function __construct($newTicketValidator, $trackingIdGenerator, $ticketGateway) {
function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, $ticketGateway) {
$this->newTicketValidator = $newTicketValidator;
$this->trackingIdGenerator = $trackingIdGenerator;
$this->autoassigner = $autoassigner;
$this->ticketGateway = $ticketGateway;
}
@ -50,15 +56,27 @@ class TicketCreator {
$ticket = new Ticket();
$ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings);
//-- TODO suggested kb articles
//-- TODO owner/autoassign logic
if ($heskSettings['autoassign']) {
$ticket->ownerId = $this->autoassigner->getNextUserForTicket($ticketRequest->category, $heskSettings);
}
//-- TODO latitude/longitude
// Transform one-to-one properties
$ticket->name = $ticketRequest->name;
$ticket->email = $ticketRequest->email;
$ticket->priorityId = $ticketRequest->priority;
$ticket->categoryId = $ticketRequest->category;
$ticket->subject = $ticketRequest->subject;
$ticket->message = $ticketRequest->message;
$ticket->usesHtml = $ticketRequest->html;
$ticket->customFields = $ticketRequest->customFields;
$ticket->location = $ticketRequest->location;
$ticket->suggestedArticles = $ticketRequest->suggestedKnowledgebaseArticleIds;
$ticket->userAgent = $ticketRequest->userAgent;
$ticket->screenResolution = $ticketRequest->screenResolution;
//-- TODO HTML flag
$ticket = $this->ticketGateway->createTicket($ticket, $heskSettings);
$this->ticketGateway->createTicket($ticket, $heskSettings);
//-- TODO get SQL-generated fields
return $ticket;
}

@ -86,6 +86,7 @@ class TicketGateway extends CommonDao {
/**
* @param $ticket Ticket
* @param $heskSettings
* @return Ticket
*/
function createTicket($ticket, $heskSettings) {
global $hesklang;
@ -186,5 +187,7 @@ class TicketGateway extends CommonDao {
{$customWhat}
)
";
return $ticket;
}
}

@ -10,6 +10,7 @@ namespace BusinessLogic\Tickets\TicketCreatorTests;
use BusinessLogic\Security\UserContext;
use BusinessLogic\Tickets\Autoassigner;
use BusinessLogic\Tickets\CreateTicketByCustomerModel;
use BusinessLogic\Tickets\NewTicketValidator;
use BusinessLogic\Tickets\TicketCreator;
@ -36,6 +37,11 @@ class CreateTicketTest extends TestCase {
*/
private $trackingIdGenerator;
/**
* @var $autoassigner \PHPUnit_Framework_MockObject_MockObject
*/
private $autoassigner;
/**
* @var $ticketRequest CreateTicketByCustomerModel
*/
@ -65,8 +71,9 @@ class CreateTicketTest extends TestCase {
$this->ticketGateway = $this->createMock(TicketGateway::class);
$this->newTicketValidator = $this->createMock(NewTicketValidator::class);
$this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::class);
$this->autoassigner = $this->createMock(Autoassigner::class);
$this->ticketCreator = new TicketCreator($this->newTicketValidator, $this->trackingIdGenerator, $this->ticketGateway);
$this->ticketCreator = new TicketCreator($this->newTicketValidator, $this->trackingIdGenerator, $this->autoassigner, $this->ticketGateway);
$this->ticketRequest = new CreateTicketByCustomerModel();
$this->ticketRequest->name = 'Name';
@ -82,12 +89,15 @@ class CreateTicketTest extends TestCase {
'require_subject' => 1,
'require_message' => 1,
'custom_fields' => array(),
'autoassign' => 0,
);
$this->modsForHeskSettings = array();
$this->userContext = new UserContext();
$this->newTicketValidator->method('validateNewTicketForCustomer')->willReturn(new ValidationModel());
$this->trackingIdGenerator->method('generateTrackingId')->willReturn('123-456-7890');
$this->autoassigner->method('getNextUserForTicket')->willReturn(1);
$this->ticketGateway->method('createTicket')->will($this->returnArgument(0));
}
function testItSavesTheTicketToTheDatabase() {
@ -105,4 +115,58 @@ class CreateTicketTest extends TestCase {
//-- Assert
self::assertThat($ticket->trackingId, self::equalTo('123-456-7890'));
}
function testItSetsTheNextUserForAutoassign() {
//-- Arrange
$this->heskSettings['autoassign'] = 1;
//-- Act
$ticket = $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext);
//-- Assert
self::assertThat($ticket->ownerId, self::equalTo(1));
}
function testItDoesntCallTheAutoassignerWhenDisabledInHesk() {
//-- Act
$ticket = $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext);
//-- Assert
self::assertThat($ticket->ownerId, self::equalTo(null));
}
function testItTransformsTheBasicProperties() {
//-- Arrange
$this->ticketRequest->name = 'Name';
$this->ticketRequest->email = 'some@email.test';
$this->ticketRequest->priority = Priority::MEDIUM;
$this->ticketRequest->category = 1;
$this->ticketRequest->subject = 'Subject';
$this->ticketRequest->message = 'Message';
$this->ticketRequest->html = false;
$this->ticketRequest->customFields = array(
1 => 'something'
);
$this->ticketRequest->location = ['10.157', '-10.177'];
$this->ticketRequest->suggestedKnowledgebaseArticleIds = [1, 2, 3];
$this->ticketRequest->userAgent = 'UserAgent';
$this->ticketRequest->screenResolution = [1400, 900];
//-- Act
$ticket = $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext);
//-- Assert
self::assertThat($ticket->name, self::equalTo($this->ticketRequest->name));
self::assertThat($ticket->email, self::equalTo($this->ticketRequest->email));
self::assertThat($ticket->priorityId, self::equalTo($this->ticketRequest->priority));
self::assertThat($ticket->categoryId, self::equalTo($this->ticketRequest->category));
self::assertThat($ticket->subject, self::equalTo($this->ticketRequest->subject));
self::assertThat($ticket->message, self::equalTo($this->ticketRequest->message));
self::assertThat($ticket->usesHtml, self::equalTo($this->ticketRequest->html));
self::assertThat($ticket->customFields[1], self::equalTo($this->ticketRequest->customFields[1]));
self::assertThat($ticket->location, self::equalTo($this->ticketRequest->location));
self::assertThat($ticket->suggestedArticles, self::equalTo($this->ticketRequest->suggestedKnowledgebaseArticleIds));
self::assertThat($ticket->userAgent, self::equalTo($this->ticketRequest->userAgent));
self::assertThat($ticket->screenResolution, self::equalTo($this->ticketRequest->screenResolution));
}
}

Loading…
Cancel
Save