Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Improve test coverage for Magento\AuthorizenetGraphQl\Model\Authorize…
Browse files Browse the repository at this point in the history
…netDataProvider

Cover exceptions:
 - `Required parameter "opaque_data_value" for "authorizenet_acceptjs" is missing.`
 - `Required parameter "cc_last_4" for "authorizenet_acceptjs" is missing.`

Signed-off-by: Tomash Khamlai <[email protected]>
  • Loading branch information
TomashKhamlai committed Sep 30, 2019
1 parent f35c6eb commit 052c035
Showing 1 changed file with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testSetPaymentInvalidInput(\Closure $getMutationClosure, string
$this->expectExceptionMessage($expectedMessage);
$this->graphQlMutation($setPaymentMutation, [], '', $this->getHeaderMap());
}

/**
* Data provider for testSetPaymentInvalidInput
*
Expand All @@ -156,9 +156,25 @@ function (string $maskedQuoteId) {
],
[
function (string $maskedQuoteId) {
return $this->getInvalidAcceptJsInput($maskedQuoteId);
return $this->getEmptyAcceptJsInput($maskedQuoteId);
},
'for "authorizenet_acceptjs" is missing.',
],
[
function (string $maskedQuoteId) {
return $this->getMissingCcLastFourAcceptJsInput(
$maskedQuoteId,
static::VALID_DESCRIPTOR,
static::VALID_NONCE
);
},
'parameter "cc_last_4" for "authorizenet_acceptjs" is missing',
],
[
function (string $maskedQuoteId) {
return $this->getMissingOpaqueDataValueAcceptJsInput($maskedQuoteId, static::VALID_DESCRIPTOR);
},
'for "authorizenet_acceptjs" is missing.'
'parameter "opaque_data_value" for "authorizenet_acceptjs" is missing',
],
];
}
Expand Down Expand Up @@ -190,12 +206,12 @@ private function getInvalidSetPaymentMutation(string $maskedQuoteId): string
}

/**
* Get setPaymentMethodOnCart missing require additional data properties
* Get setPaymentMethodOnCart missing required additional data properties
*
* @param string $maskedQuoteId
* @return string
*/
private function getInvalidAcceptJsInput(string $maskedQuoteId): string
private function getEmptyAcceptJsInput(string $maskedQuoteId): string
{
return <<<QUERY
mutation {
Expand All @@ -216,6 +232,66 @@ private function getInvalidAcceptJsInput(string $maskedQuoteId): string
QUERY;
}

/**
* Get setPaymentMethodOnCart missing required additional data properties
*
* @param string $maskedQuoteId
* @return string
*/
private function getMissingCcLastFourAcceptJsInput(string $maskedQuoteId, string $descriptor, string $nonce): string
{
return <<<QUERY
mutation {
setPaymentMethodOnCart(input:{
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"authorizenet_acceptjs"
authorizenet_acceptjs:{
opaque_data_descriptor: "{$descriptor}"
opaque_data_value: "{$nonce}"
}
}
}) {
cart {
selected_payment_method {
code
}
}
}
}
QUERY;
}

/**
* Get setPaymentMethodOnCart missing required additional data properties
*
* @param string $maskedQuoteId
* @return string
*/
private function getMissingOpaqueDataValueAcceptJsInput(string $maskedQuoteId, string $descriptor): string
{
return <<<QUERY
mutation {
setPaymentMethodOnCart(input:{
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"authorizenet_acceptjs"
authorizenet_acceptjs:{
opaque_data_descriptor: "{$descriptor}"
cc_last_4: 1111
}
}
}) {
cart {
selected_payment_method {
code
}
}
}
}
QUERY;
}

private function assertPlaceOrderResponse(array $response, string $reservedOrderId): void
{
self::assertArrayHasKey('placeOrder', $response);
Expand Down

0 comments on commit 052c035

Please sign in to comment.