Skip to content

Commit

Permalink
Merge pull request #205 from zendesk/mio/ticket-merge
Browse files Browse the repository at this point in the history
[MI-320] Add support for ticket merging.
  • Loading branch information
miogalang committed Oct 1, 2015
2 parents 7552d14 + 7e27c72 commit 09d3301
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Zendesk/API/Resources/Core/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected function setUpRoutes()
'deleteMany' => 'tickets/destroy_many.json',
'collaborators' => 'tickets/{id}/collaborators.json',
'incidents' => 'tickets/{id}/incidents.json',
'merge' => 'tickets/{id}/merge.json',
'problems' => 'problems.json',
'export' => 'exports/tickets.json',
'problemAutoComplete' => 'problems/autocomplete.json'
Expand Down Expand Up @@ -378,7 +379,7 @@ public function export(array $params)
$response = Http::send(
$this->client,
$this->getRoute('export'),
["queryParams" => $queryParams]
['queryParams' => $queryParams]
);

return $response;
Expand Down Expand Up @@ -406,4 +407,34 @@ public function attach(array $params = [])

return $this;
}

/**
* @param array $params
*
* @throws MissingParametersException
* @throws ResponseException
* @return Tickets
*/
public function merge(array $params = [])
{
$params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);

if (! $this->hasKeys($params, ['id', 'ids'])) {
throw new MissingParametersException(__METHOD__, ['id', 'ids']);
}

$route = $this->getRoute(__FUNCTION__, ['id' => $params['id']]);
unset($params['id']);

$response = Http::send(
$this->client,
$route,
[
'method' => 'POST',
'postFields' => $params,
]
);

return $response;
}
}
16 changes: 16 additions & 0 deletions tests/Zendesk/API/UnitTests/Core/TicketsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,20 @@ public function testMarkManyAsSpam()
$this->client->tickets()->markAsSpam([12345, 54321]);
}, 'tickets/mark_many_as_spam.json', 'PUT', ['queryParams' => ['ids' => '12345,54321']]);
}

/**
* Tests if the client can call the merge endpoint.
*/
public function testMerge()
{
$params = [
'ids' => [123, 234],
'target_comment' => 'Closing in favor of #345',
'source_comment' => 'Combining with #123, #234',
];
$ticketId = 345;
$this->assertEndpointCalled(function () use ($ticketId, $params) {
$this->client->tickets($ticketId)->merge($params);
}, "tickets/{$ticketId}/merge.json", 'POST', $params);
}
}

0 comments on commit 09d3301

Please sign in to comment.