From 569ccf8647c4be707b34639f6897851d5c3828b3 Mon Sep 17 00:00:00 2001 From: khushboos Date: Fri, 18 Oct 2024 10:09:46 +0200 Subject: [PATCH] Updating unit test --- Helper/PaymentResponseHandler.php | 3 +- .../Helper/PaymentResponseHandlerTest.php | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Helper/PaymentResponseHandler.php b/Helper/PaymentResponseHandler.php index bf346c263..81963ab05 100644 --- a/Helper/PaymentResponseHandler.php +++ b/Helper/PaymentResponseHandler.php @@ -291,7 +291,6 @@ public function handlePaymentsDetailsResponse( case self::REFUSED: case self::CANCELLED: $getGiftcardDetails = $this->hasActiveGiftCardPayments( - $order, $paymentsDetailsResponse['merchantReference'] ); if (!empty($getGiftcardDetails)) { @@ -410,7 +409,7 @@ private function isValidMerchantReference(array $paymentsDetailsResponse, OrderI } // Method to check for existing Gift Card payments - private function hasActiveGiftCardPayments(OrderInterface $order, $merchantReference) + private function hasActiveGiftCardPayments($merchantReference) { $paymentResponseCollection = $this->paymentResponseCollectionFactory->create() ->addFieldToFilter('merchant_reference', $merchantReference) diff --git a/Test/Unit/Helper/PaymentResponseHandlerTest.php b/Test/Unit/Helper/PaymentResponseHandlerTest.php index 288aee3c0..5bb9739bd 100644 --- a/Test/Unit/Helper/PaymentResponseHandlerTest.php +++ b/Test/Unit/Helper/PaymentResponseHandlerTest.php @@ -30,6 +30,7 @@ use Adyen\Payment\Model\ResourceModel\PaymentResponse\Collection; use Adyen\Payment\Model\ResourceModel\PaymentResponse\CollectionFactory; use Adyen\Payment\Helper\Config as Config; +use ReflectionClass; class PaymentResponseHandlerTest extends AbstractAdyenTestCase { @@ -475,4 +476,38 @@ public function testHandlePaymentsDetailsResponseInvalidMerchantReference(){ $this->assertFalse($result); } + + public function testHandlePaymentsDetailsResponseValidMerchantReference() + { + $paymentsDetailsResponse = [ + 'resultCode' => PaymentResponseHandler::AUTHORISED, + 'pspReference' => 'ABC123456789', + 'paymentMethod' => [ + 'brand' => 'ideal' + ], + 'merchantReference' => '00123456' // assuming this is a valid reference + ]; + // Mock the isValidMerchantReference to return true + $reflectionClass = new ReflectionClass(PaymentResponseHandler::class); + $method = $reflectionClass->getMethod('isValidMerchantReference'); + $method->setAccessible(true); + $isValidMerchantReference = $method->invokeArgs($this->paymentResponseHandler, [$paymentsDetailsResponse,$this->orderMock]); + $this->assertTrue($isValidMerchantReference); + } + + public function testPaymentDetailsCallFailureLogsError() + { + $resultCode = 'some_result_code'; + $paymentsDetailsResponse = ['error' => 'some error message']; + + // Expect the logger to be called with the specific message + $this->adyenLoggerMock->expects($this->once()) + ->method('error'); + + // Call the method that triggers the logging, e.g., handlePaymentDetailsFailure() + $this->paymentResponseHandler->handlePaymentsDetailsResponse( + $paymentsDetailsResponse, + $this->orderMock + ); + } }