Skip to content

Commit 2a4de17

Browse files
authored
feat: add ticket message PUT and DELETE endpoints (#204)
* feat: add ticket message PUT and DELETE endpoints * fix
1 parent 7305250 commit 2a4de17

File tree

10 files changed

+224
-44
lines changed

10 files changed

+224
-44
lines changed

src/Api/Ticket/Messages.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SupportPal\ApiClient\Model\Collection;
99
use SupportPal\ApiClient\Model\Ticket\Message;
1010
use SupportPal\ApiClient\Model\Ticket\Request\CreateMessage;
11+
use SupportPal\ApiClient\Model\Ticket\Request\UpdateMessage;
1112

1213
use function array_map;
1314

@@ -48,6 +49,26 @@ public function createMessage(CreateMessage $data): Message
4849
return $this->createMessageModel($this->decodeBody($response)['data']);
4950
}
5051

52+
/**
53+
* @throws HttpResponseException
54+
*/
55+
public function updateMessage(int $id, UpdateMessage $data): Message
56+
{
57+
$response = $this->getApiClient()->putMessage($id, $data->toArray());
58+
59+
return $this->createMessageModel($this->decodeBody($response)['data']);
60+
}
61+
62+
/**
63+
* @throws HttpResponseException
64+
*/
65+
public function deleteMessage(int $id): bool
66+
{
67+
$response = $this->getApiClient()->deleteMessage($id);
68+
69+
return $this->decodeBody($response)['status'] === 'success';
70+
}
71+
5172
/**
5273
* @param array<mixed> $data
5374
*/

src/Api/Ticket/Tickets.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function createTicket(CreateTicket $data): Ticket
4949
}
5050

5151
/**
52-
* @throws InvalidArgumentException
5352
* @throws HttpResponseException
5453
*/
5554
public function updateTicket(int $id, UpdateTicket $data): Ticket

src/Http/Ticket/MessageApis.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,25 @@ public function postMessage(array $body): ResponseInterface
3838

3939
return $this->sendRequest($request);
4040
}
41+
42+
/**
43+
* @param array<mixed> $body
44+
* @throws HttpResponseException
45+
*/
46+
public function putMessage(int $id, array $body): ResponseInterface
47+
{
48+
$request = $this->getRequest()->create('PUT', ApiDictionary::TICKET_MESSAGE . '/' . $id, [], $body);
49+
50+
return $this->sendRequest($request);
51+
}
52+
53+
/**
54+
* @throws HttpResponseException
55+
*/
56+
public function deleteMessage(int $id): ResponseInterface
57+
{
58+
$request = $this->getRequest()->create('DELETE', ApiDictionary::TICKET_MESSAGE . '/' . $id);
59+
60+
return $this->sendRequest($request);
61+
}
4162
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SupportPal\ApiClient\Model\Ticket\Request;
4+
5+
use SupportPal\ApiClient\Model\Model;
6+
7+
class UpdateMessage extends Model
8+
{
9+
/** @var array<string, string> */
10+
protected array $casts = ['text' => 'string'];
11+
}

test/DataFixtures/ApiCalls/TicketApisData.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\PriorityData;
1313
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request\CreateMessageData;
1414
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request\CreateTicketData;
15+
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request\UpdateMessageData;
1516
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request\UpdateTicketData;
1617
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\StatusData;
1718
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\TicketCustomFieldData;
@@ -30,8 +31,8 @@ public function getApiCalls(): array
3031
$ticketCustomFieldData = new TicketCustomFieldData;
3132
$priorityData = new PriorityData;
3233
$statusData = new StatusData;
33-
$attachmentData = new AttachmentData;
3434
$ticketData = new TicketData;
35+
$attachmentData = new AttachmentData;
3536
$messageData = new MessageData;
3637

3738
return [
@@ -45,12 +46,12 @@ public function getApiCalls(): array
4546
'getPriority' => [$priorityData->getResponse(), [1]],
4647
'getStatuses' => [$statusData->getAllResponse(), []],
4748
'getStatus' => [$statusData->getResponse(), [1]],
48-
'getAttachments' => [$attachmentData->getAllResponse(), []],
49-
'getAttachment' => [$attachmentData->getResponse(), [1]],
5049
'getTickets' => [$ticketData->getAllResponse(), []],
5150
'getTicket' => [$ticketData->getResponse(), [1]],
52-
'getMessage' => [$messageData->getResponse(), [1]],
51+
'getAttachments' => [$attachmentData->getAllResponse(), []],
52+
'getAttachment' => [$attachmentData->getResponse(), [1]],
5353
'getMessages' => [$messageData->getAllResponse(), [1]],
54+
'getMessage' => [$messageData->getResponse(), [1]],
5455
];
5556
}
5657

@@ -76,9 +77,11 @@ public function postApiCalls(): array
7677
public function putApiCalls(): array
7778
{
7879
$updateTicketData = new UpdateTicketData;
80+
$updateMessageData = new UpdateMessageData;
7981

8082
return [
8183
'updateTicket' => [1, $updateTicketData->getFilledInstance(), $updateTicketData->getResponse()],
84+
'updateMessage' => [1, $updateMessageData->getFilledInstance(), $updateMessageData->getResponse()],
8285
];
8386
}
8487

@@ -89,6 +92,7 @@ public function deleteApiCalls(): array
8992
{
9093
return [
9194
'deleteTicket' => 1,
95+
'deleteMessage' => 1,
9296
];
9397
}
9498

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request;
4+
5+
use SupportPal\ApiClient\Model\Ticket\Request\UpdateMessage;
6+
use SupportPal\ApiClient\Tests\DataFixtures\BaseModelData;
7+
8+
class UpdateMessageData extends BaseModelData
9+
{
10+
public const DATA = ['text' => 'test'];
11+
12+
/**
13+
* @inheritDoc
14+
*/
15+
public function getModel(): string
16+
{
17+
return UpdateMessage::class;
18+
}
19+
}

test/E2E/TicketApisTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class TicketApisTest extends BaseTestCase
1313
protected function getGetAllEndpoints(): array
1414
{
1515
return [
16-
ApiDictionary::TICKET_TICKET => 'getTickets',
17-
ApiDictionary::TICKET_ATTACHMENT => 'getAttachments',
18-
ApiDictionary::TICKET_STATUS => 'getStatuses',
19-
ApiDictionary::TICKET_PRIORITY => 'getPriorities',
2016
ApiDictionary::TICKET_CUSTOMFIELD => 'getCustomFields',
2117
ApiDictionary::TICKET_DEPARTMENT => 'getDepartments',
18+
ApiDictionary::TICKET_STATUS => 'getStatuses',
19+
ApiDictionary::TICKET_PRIORITY => 'getPriorities',
20+
ApiDictionary::TICKET_TICKET => 'getTickets',
21+
ApiDictionary::TICKET_ATTACHMENT => 'getAttachments',
22+
ApiDictionary::TICKET_MESSAGE => 'getMessage',
2223
];
2324
}
2425

@@ -28,12 +29,13 @@ protected function getGetAllEndpoints(): array
2829
protected function getGetOneEndpoints(): array
2930
{
3031
return [
32+
ApiDictionary::TICKET_CUSTOMFIELD => 'getCustomField',
3133
ApiDictionary::TICKET_DEPARTMENT => 'getDepartment' ,
3234
ApiDictionary::TICKET_PRIORITY => 'getPriority',
3335
ApiDictionary::TICKET_STATUS => 'getStatus',
34-
ApiDictionary::TICKET_ATTACHMENT => 'getAttachment',
3536
ApiDictionary::TICKET_TICKET => 'getTicket',
36-
ApiDictionary::TICKET_CUSTOMFIELD => 'getCustomField',
37+
ApiDictionary::TICKET_ATTACHMENT => 'getAttachment',
38+
ApiDictionary::TICKET_MESSAGE => 'getMessage',
3739
];
3840
}
3941

test/Unit/Api/Ticket/MessageApisTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use SupportPal\ApiClient\Model\Ticket\Message;
66
use SupportPal\ApiClient\Model\Ticket\Request\CreateMessage;
7+
use SupportPal\ApiClient\Model\Ticket\Request\UpdateMessage;
78
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\MessageData;
9+
use SupportPal\ApiClient\Tests\DataFixtures\Ticket\Request\UpdateMessageData;
810

911
class MessageApisTest extends BaseTicketApiTest
1012
{
@@ -52,4 +54,33 @@ public function testCreateMessage(): void
5254
$message = $this->api->createMessage(new CreateMessage($arrayData));
5355
self::assertEquals($messageOutput, $message);
5456
}
57+
58+
public function testUpdateMessage(): void
59+
{
60+
$ticketData = new MessageData;
61+
$updateMessage = new UpdateMessage(UpdateMessageData::DATA);
62+
63+
[$output, $response] = $this->makeCommonExpectations($ticketData->getResponse(), Message::class);
64+
65+
$this->apiClient
66+
->putMessage(self::TEST_ID, $updateMessage->toArray())
67+
->willReturn($response->reveal())
68+
->shouldBeCalled();
69+
70+
$ticket = $this->api->updateMessage(self::TEST_ID, $updateMessage);
71+
self::assertEquals($output, $ticket);
72+
}
73+
74+
public function testDeleteMessage(): void
75+
{
76+
$response = $this->makeSuccessResponse();
77+
78+
$this->apiClient
79+
->deleteMessage(1)
80+
->shouldBeCalled()
81+
->willReturn($response->reveal());
82+
83+
$apiResponse = $this->api->deleteMessage(1);
84+
self::assertTrue($apiResponse);
85+
}
5586
}

test/Unit/Api/Ticket/TicketApisTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testUpdateTicket(): void
6969
self::assertEquals($output, $ticket);
7070
}
7171

72-
public function testDeleteArticle(): void
72+
public function testDeleteTicket(): void
7373
{
7474
$response = $this->makeSuccessResponse();
7575

0 commit comments

Comments
 (0)