Getting started on retrieving ticket customer-side

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent b03312f73c
commit 54cb77b136

@ -9,7 +9,10 @@ class Ticket {
$ticket->id = intval($row['id']);
$ticket->trackingId = $row['trackid'];
$ticket->name = $row['name'];
$ticket->email = $row['email'];
if ($row['email'] !== null) {
$emails = str_replace(';', ',', $row['email']);
$ticket->email = explode(',', strtolower($emails));
}
$ticket->categoryId = intval($row['category']);
$ticket->priorityId = intval($row['priority']);
$ticket->subject = $row['subject'];
@ -37,7 +40,6 @@ class Ticket {
$ticket->lastReplier = $row['replierid'] === null ? null : intval($row['replierid']);
$ticket->archived = intval($row['archive']) === 1;
$ticket->locked = intval($row['locked']) === 1;
$ticket->attachments = array();
if (trim($row['attachments']) !== '') {
$attachments = explode(',', $row['attachments']);
@ -72,7 +74,6 @@ class Ticket {
}
}
$ticket->linkedTicketIds = array();
while ($linkedTicketsRow = hesk_dbFetchAssoc($linkedTicketsRs)) {
$ticket->linkedTicketIds[] = $linkedTicketsRow['id'];
}
@ -155,7 +156,7 @@ class Ticket {
public $name;
/**
* @var string|null
* @var array|null
*/
public $email;
@ -200,9 +201,9 @@ class Ticket {
public $closedDate;
/**
* @var string[]|null
* @var string[]
*/
public $suggestedArticles;
public $suggestedArticles = array();
/**
* @var string
@ -275,9 +276,9 @@ class Ticket {
public $locked;
/**
* @var Attachment[]|null
* @var Attachment[]
*/
public $attachments;
public $attachments = array();
function getAttachmentsForDatabase() {
$attachmentArray = array();
@ -292,9 +293,9 @@ class Ticket {
}
/**
* @var int[]|null
* @var int[]
*/
public $mergedTicketIds;
public $mergedTicketIds = array();
/**
* @var string
@ -309,7 +310,7 @@ class Ticket {
/**
* @var int[]
*/
public $linkedTicketIds;
public $linkedTicketIds = array();
/**
* @var float[]|null
@ -347,5 +348,5 @@ class Ticket {
/**
* @var Reply[]
*/
public $replies;
public $replies = array();
}

@ -3,6 +3,8 @@
namespace BusinessLogic\Tickets;
use BusinessLogic\Exceptions\ValidationException;
use BusinessLogic\ValidationModel;
use DataAccess\Tickets\TicketGateway;
class TicketRetriever {
@ -18,4 +20,32 @@ class TicketRetriever {
function getTicketById($id, $heskSettings, $userContext) {
return $this->ticketGateway->getTicketById($id, $heskSettings);
}
function getTicketByTrackingIdAndEmail($trackingId, $emailAddress, $heskSettings) {
$this->validate($trackingId, $emailAddress, $heskSettings);
$ticket = $this->ticketGateway->getTicketByTrackingId($trackingId, $heskSettings);
if ($heskSettings['email_view_ticket'] && !in_array($emailAddress, $ticket->email)) {
throw new \Exception("Email '{$emailAddress}' entered in for ticket '{$trackingId}' does not match!");
}
return $ticket;
}
private function validate($trackingId, $emailAddress, $heskSettings) {
$validationModel = new ValidationModel();
if ($trackingId === null || trim($trackingId) === '') {
$validationModel->errorKeys[] = 'MISSING_TRACKING_ID';
}
if ($heskSettings['email_view_ticket'] && ($emailAddress === null || trim($emailAddress) === '')) {
$validationModel->errorKeys[] = 'EMAIL_REQUIRED_AND_MISSING';
}
if (count($validationModel->errorKeys) > 0) {
throw new ValidationException($validationModel);
}
}
}

@ -0,0 +1,73 @@
<?php
namespace BusinessLogic\Tickets;
use DataAccess\Tickets\TicketGateway;
use PHPUnit\Framework\TestCase;
class TicketRetrieverTest extends TestCase {
/* @var $ticketRetriever TicketRetriever */
private $ticketRetriever;
/* @var $ticketGateway \PHPUnit_Framework_MockObject_MockObject */
private $ticketGateway;
/* @var $heskSettings array */
private $heskSettings;
protected function setUp() {
$this->ticketGateway = $this->createMock(TicketGateway::class);
$this->heskSettings = array('email_view_ticket' => 0);
$this->ticketRetriever = new TicketRetriever($this->ticketGateway);
}
function testItGetsTheTicketByTrackingId() {
//-- Arrange
$ticket = new Ticket();
$trackingId = '12345';
$this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket);
//-- Act
$actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, null, $this->heskSettings);
//-- Assert
self::assertThat($actual, self::equalTo($ticket));
}
function testItChecksTheTicketsEmailIfThePageRequiresIt() {
//-- Arrange
$ticket = new Ticket();
$email = 'email@example.com';
$ticket->email = array('email2@example.com;email3@example.com,email4@example.com');
$trackingId = '12345';
$this->heskSettings['email_view_ticket'] = 1;
$this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket);
//-- Assert
$this->expectException(\Exception::class);
$this->expectExceptionMessage("Email 'email@example.com' entered in for ticket '12345' does not match!");
//-- Act
$this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $email, $this->heskSettings);
}
function testItCanHandleTicketsWithMultipleEmails() {
//-- Arrange
$ticket = new Ticket();
$email = 'email2@example.com';
$ticket->email = array('email2@example.com','email3@example.com','email4@example.com');
$trackingId = '12345';
$this->heskSettings['email_view_ticket'] = 1;
$this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket);
//-- Act
$actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $email, $this->heskSettings);
//-- Assert
self::assertThat($actual, self::equalTo($ticket));
}
//-- TODO Validation tests
}
Loading…
Cancel
Save