Skip to content

Commit

Permalink
Revert "AT-2952: use http method delete when cancelling a program cal…
Browse files Browse the repository at this point in the history
…lback"

This reverts commit bebf1ee.
  • Loading branch information
fentosi committed Jan 13, 2022
1 parent bcec066 commit 9e6323a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
44 changes: 18 additions & 26 deletions src/Suite/Api/AC/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class Program
{
const CALLBACK_STATUS_DONE = 'done';
const CALLBACK_STATUS_CANCELED = 'canceled';

/* @var Client */
private $apiClient;

Expand All @@ -21,45 +24,34 @@ public function __construct(Client $apiClient, EndPoints $endPoints)
$this->endPoints = $endPoints;
}

public function programCallbackWithUserId(int $customerId, string $triggerId, int $userId)
{
$this->programCallback($customerId, $triggerId, $userId, null);
}

public function programCallbackWithListId(int $customerId, string $triggerId, int $listId)
{
$this->programCallback($customerId, $triggerId, null, $listId);
}

public function programCallbackCancel(int $customerId, string $triggerId)
{
try
{
$this->apiClient->delete($this->endPoints->programCallbackUrl($customerId, $triggerId), []);
}
catch (Error $ex)
{
$this->throwRequestFailedException($ex);
}
}

private function programCallback(int $customerId, string $triggerId, $userId, $listId)
private function programCallback(int $customerId, string $triggerId, $userId, $listId, string $status = self::CALLBACK_STATUS_DONE)
{
try
{
$this->apiClient->post($this->endPoints->programCallbackUrl($customerId, $triggerId),[
'user_id' => $userId,
'list_id' => $listId,
'status' => $status,
]);
}
catch (Error $ex)
{
$this->throwRequestFailedException($ex);
throw new RequestFailed('Program callback failed: ' . $ex->getMessage(), $ex->getCode(), $ex);
}
}

private function throwRequestFailedException($ex)
public function programCallbackWithUserId(int $customerId, string $triggerId, int $userId)
{
$this->programCallback($customerId, $triggerId, $userId, null);
}

public function programCallbackWithListId(int $customerId, string $triggerId, int $listId)
{
$this->programCallback($customerId, $triggerId, null, $listId);
}

public function programCallbackCancel(int $customerId, string $triggerId)
{
throw new RequestFailed('Program callback failed: ' . $ex->getMessage(), $ex->getCode(), $ex);
$this->programCallback($customerId, $triggerId, null, null, Program::CALLBACK_STATUS_CANCELED);
}
}
14 changes: 11 additions & 3 deletions test/unit/Suite/Api/AC/ProgramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function programCallbackWithUserId_Perfect_Perfect()
[
'user_id' => self::USER_ID,
'list_id' => null,
'status' => Program::CALLBACK_STATUS_DONE,
]
);

Expand All @@ -59,6 +60,7 @@ public function programCallbackWithListId_Perfect_Perfect()
[
'user_id' => null,
'list_id' => self::LIST_ID,
'status' => Program::CALLBACK_STATUS_DONE
]
);

Expand All @@ -81,14 +83,20 @@ public function programCallbackWithListId_postThrowsError_ThrowsRequestFailExcep
*/
public function programCallbackCancel_Perfect_Perfect()
{
$this->expectApiCallSuccess([], 'delete');
$this->expectApiCallSuccess(
[
'user_id' => 0,
'list_id' => null,
'status' => Program::CALLBACK_STATUS_CANCELED
]
);

$this->program->programCallbackCancel($this->customerId, self::TRIGGER_ID);
}

private function expectApiCallSuccess(array $postParams, string $httpVerb = 'post')
private function expectApiCallSuccess(array $postParams)
{
$this->apiClient->expects($this->once())->method($httpVerb)->with(
$this->apiClient->expects($this->once())->method('post')->with(
$this->endPoints->programCallbackUrl($this->customerId, self::TRIGGER_ID), $postParams
)->willReturn($this->apiSuccess());
}
Expand Down

0 comments on commit 9e6323a

Please sign in to comment.