Skip to content

Commit

Permalink
Added Unit test cases for replace PPC and removed IT test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Rrathinasabapath committed Oct 22, 2020
1 parent 650bb8d commit dbd9a27
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 78 deletions.
16 changes: 14 additions & 2 deletions src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,20 @@ public function createPrepaidCard($userToken, PrepaidCard $prepaidCard) {
return new PrepaidCard($body);
}

/**
* Replace a prepaid card
*
* @param string $userToken The user token
* @param PrepaidCard $prepaidCard The prepaid card data
* @return PrepaidCard
*/
public function replacePrepaidCard($userToken, PrepaidCard $prepaidCard) {
if (empty($prepaidCard->getReplacementReason())) {
throw new HyperwalletArgumentException('replacementReason is required!');
}
return $this->createPrepaidCard($userToken, $prepaidCard);
}

/**
* Get a prepaid card
*
Expand All @@ -795,8 +809,6 @@ public function createPrepaidCard($userToken, PrepaidCard $prepaidCard) {
* @throws HyperwalletApiException
*/
public function getPrepaidCard($userToken, $prepaidCardToken) {
echo("======User Token=======".$userToken);
echo("======PPC Token=======".$prepaidCardToken);
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
Expand Down
48 changes: 48 additions & 0 deletions src/Hyperwallet/Model/PrepaidCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @property string $cardType The prepaid card type
*
* @property String $replacementOf The token of prepaid card to be replaced
* @property String $replacementReason The prepaid card replacement reason
* @property string $cardPackage The prepaid card package
* @property string $cardNumber The prepaid card number
* @property string $cardBrand The prepaid card brand
Expand Down Expand Up @@ -52,6 +54,11 @@ class PrepaidCard extends BaseModel {
const CARD_BRAND_VISA = 'VISA';
const CARD_BRAND_MASTERCARD = 'MASTERCARD';

const REPLACEMENT_REASON_LOST_STOLEN= 'LOST_STOLEN';
const REPLACEMENT_REASON_DAMAGED= 'DAMAGED';
const REPLACEMENT_REASON_COMPROMISED= 'COMPROMISED';
const REPLACEMENT_REASON_EXPIRED= 'EXPIRED';

public static function FILTERS_ARRAY() {
return array('status');
}
Expand Down Expand Up @@ -197,4 +204,45 @@ public function getDateOfExpiry() {
return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null;
}


/**
* Get the prepaid card token to be replaced
*
* @return string
*/
public function getReplacementOf() {
return $this->replacementOf;
}

/**
* Set the prepaid card token to be replaced
*
* @param string $token
* @return PrepaidCard
*/
public function setReplacementOf($replacementOf) {
$this->replacementOf = $replacementOf;
return $this;
}

/**
* Get the prepaid card's replacement reason
*
* @return string
*/
public function getReplacementReason() {
return $this->replacementReason;
}

/**
* set the prepaid card's replacement reason
*
* @param string $token
* @return PrepaidCard
*/
public function setReplacementReason($replacementReason) {
$this->replacementReason = $replacementReason;
return $this;
}

}
5 changes: 1 addition & 4 deletions src/Hyperwallet/Util/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ApiClient {
public function __construct($username, $password, $server, $clientOptions = array(), $encryptionData = array()) {
// Setup http client if not specified
$this->client = new Client(array_merge_recursive(array(
'verify'=>false,
'base_uri' => $server,
'auth' => array($username, $password),
'headers' => array(
Expand Down Expand Up @@ -85,7 +84,7 @@ public function __construct($username, $password, $server, $clientOptions = arra
* @throws HyperwalletApiException
*/
public function doPost($partialUrl, array $uriParams, BaseModel $data = null, array $query = array(), array $headers = array()) {
return $this->doRequest('POST', $partialUrl, $uriParams, array(
return $this->doRequest('POST', $partialUrl, $uriParams, array(
'query' => $query,
'body' => $data ? \GuzzleHttp\json_encode($data->getPropertiesForCreate(), JSON_FORCE_OBJECT) : '{}',
'headers' => array_merge($headers, array(
Expand Down Expand Up @@ -161,8 +160,6 @@ private function doRequest($method, $url, array $urlParams, array $options) {
return array();
}
$this->checkResponseHeaderContentType($response);
var_dump('------URL PARAMS--------',$urlParams);
var_dump('------RESPONSE--------',$response);
$body = $this->isEncrypted ? \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($this->encryption->decrypt($response->getBody())), true) :
\GuzzleHttp\json_decode($response->getBody(), true);

Expand Down
110 changes: 38 additions & 72 deletions tests/Hyperwallet/Tests/HyperwalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,44 @@ public function testCreatePrepaidCard_allParameters() {
\Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array());
}

public function testReplacePrepaidCard_noReplacementReason() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$prepaidCard = new PrepaidCard();
$prepaidCard->setType(PrepaidCard::TYPE_PREPAID_CARD);
$prepaidCard->setCardPackage("test-card-package");
$prepaidCard->setReplacementOf("test-prepaid-card-token");

try {
$client->replacePrepaidCard('test-user-token', $prepaidCard);
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('replacementReason is required!', $e->getMessage());
}
}

public function testReplacePrepaidCard_allParameters() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$prepaidCard = new PrepaidCard();
$prepaidCard->setType(PrepaidCard::TYPE_PREPAID_CARD);
$prepaidCard->setCardPackage("test-card-package");
$prepaidCard->setReplacementOf("test-prepaid-card-token");
$prepaidCard->setReplacementReason(PrepaidCard::REPLACEMENT_REASON_DAMAGED);

\Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array())->thenReturn(array('success' => 'true'));

// Run test
$replacedPrepaidCard = $client->replacePrepaidCard('test-user-token', $prepaidCard);
$this->assertNotNull($replacedPrepaidCard);
$this->assertEquals(array('success' => 'true'), $replacedPrepaidCard->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array());
}

public function testGetPrepaidCard_noUserToken() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
Expand Down Expand Up @@ -4967,77 +5005,5 @@ public function testuploadDocumentsForBusinessStakeholder() {

// Validate mock
\Phake::verify($apiClientMock)->putMultipartData('/rest/v4/users/{user-token}/business-stakeholders/{business-token}', array('user-token' => $userToken,'business-token' => $businessToken), $options);

}

//IT tests

/*
public function testListUsers_successfulIT() {
$newStatusTransition = "";
$username = "selrestuser@1861681";
$password = "Password1!";
$programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78";
$server = "https://localhost-hyperwallet.aws.paylution.net:8181";
$hyperwallet = new Hyperwallet($username, $password, $programToken, $server);
$listedUsers = $hyperwallet->listUsers(array('status'=>User::STATUS_ACTIVATED));
$this->assertNotNull($listedUsers);
var_dump("Listed users",$listedUsers);
$this->assertEquals('ACTIVATED', $listedUsers->getData()[0]->getProperties()['status']);
}
public function testListPrepaidCards_withParametersIT() {
// Setup
$username = "selrestuser@1861681";
$password = "Password1!";
//$programToken = "prg-82499161-57d3-4160-8209-85db18d62c02";
$programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78";
$userToken = "usr-f12e77ad-c938-4f72-9121-c25442795f05";
$server = "https://localhost-hyperwallet.aws.paylution.net:8181";
$client = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server);
// Run test
$prepaidCardList = $client->listPrepaidCards($userToken);
var_dump('Prepaid card list--------',$prepaidCardList);
$this->assertNotNull($prepaidCardList);
$this->assertCount(1, $prepaidCardList);
$this->assertEquals(1, $prepaidCardList->getLimit());
$this->assertEquals(array('success' => 'true'), $prepaidCardList[0]->getProperties());
}
public function testCreatePrepaidCard_allParametersIT() {
// Setup
$username = "selrestuser@1861681";
$password = "Password1!";
//$programToken = "prg-82499161-57d3-4160-8209-85db18d62c02";
$programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78";
$userToken = "usr-8f999d85-6e4d-4349-97a5-793a875b44f5";
$server = "https://localhost-hyperwallet.aws.paylution.net:8181";
$prepaidCard = new PrepaidCard();
$prepaidCard->setType(PrepaidCard::TYPE_PREPAID_CARD);
$client = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server);
// Run test
$newPrepaidCard = $client->createPrepaidCard($userToken, $prepaidCard);
var_dump('-------new prepaid card-----',$newPrepaidCard);
$this->assertNotNull($newPrepaidCard);
}
*/
public function testGetPrepaidCard_allParametersIT() {
// Setup
$username = "selrestuser@1861681";
$password = "Password1!";
//$programToken = "prg-82499161-57d3-4160-8209-85db18d62c02";
$programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78";
$userToken = "usr-8f999d85-6e4d-4349-97a5-793a875b44f5";
$prepaidCardToken = "trm-53cb72f0-a28e-47ba-bf33-a3f093399529";
$server = "https://localhost-hyperwallet.aws.paylution.net:8181";
$client = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server);

// Run test
$prepaidCard = $client->getPrepaidCard($userToken, $prepaidCardToken);
var_dump('======Prepaid card======',$prepaidCard);
$this->assertNotNull($prepaidCard);
}
}

0 comments on commit dbd9a27

Please sign in to comment.