Skip to content

Commit

Permalink
tests - more test coverage for interpos
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Aug 10, 2024
1 parent dfd4063 commit b27a4d5
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Factory\CryptFactory;
use Mews\Pos\Gateways\InterPos;
use Mews\Pos\PosInterface;
Expand Down Expand Up @@ -171,6 +172,18 @@ public function testMapCancelResponse(array $responseData, array $expectedData):
$this->assertSame($expectedData, $actualData);
}

public function testMapHistoryResponse(): void
{
$this->expectException(NotImplementedException::class);
$this->responseDataMapper->mapHistoryResponse([]);
}

public function testMapOrderHistoryResponse(): void
{
$this->expectException(NotImplementedException::class);
$this->responseDataMapper->mapOrderHistoryResponse([]);
}

public function threeDHashCheckDataProvider(): array
{
return [
Expand Down
48 changes: 48 additions & 0 deletions tests/Unit/Gateways/InterPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Mews\Pos\Entity\Account\InterPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Exceptions\HashMismatchException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
Expand Down Expand Up @@ -193,6 +194,16 @@ public function testMake3DPayment(
->willReturn(true);
}

$this->responseMapperMock->expects(self::once())
->method('extractMdStatus')
->with($request->request->all())
->willReturn('3d-status');

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->with('3d-status')
->willReturn($is3DSuccess);

$create3DPaymentRequestData = [
'create3DPaymentRequestData',
];
Expand Down Expand Up @@ -240,6 +251,33 @@ public function testMake3DPayment(
$this->assertSame($isSuccess, $this->pos->isSuccess());
}

public function testMake3DPaymentHashMismatchException(): void
{
$request = Request::create(
'',
'POST',
['data']
);
$this->cryptMock->expects(self::once())
->method('check3DHash')
->with($this->account, $request->request->all())
->willReturn(false);

$this->responseMapperMock->expects(self::once())
->method('extractMdStatus')
->with($request->request->all())
->willReturn('3d-status');

$this->responseMapperMock->expects(self::once())
->method('is3dAuthSuccess')
->with('3d-status')
->willReturn(true);

$this->expectException(HashMismatchException::class);

$this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @return void
*/
Expand Down Expand Up @@ -490,6 +528,16 @@ public static function make3DPaymentDataProvider(): array
'is3DSuccess' => false,
'isSuccess' => false,
],
'success' => [
'order' => ['order'],
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'request' => Request::create('', 'POST', ['gateway_response']),
'paymentResponse' => ['paymentResponse'],
'expected' => ['status' => 'approved'],
'check_hash' => true,
'is3DSuccess' => true,
'isSuccess' => true,
],
];
}

Expand Down
59 changes: 59 additions & 0 deletions tests/Unit/Serializer/InterPosSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,63 @@ public function testEncode(): void

$this->assertSame($data, $result);
}

/**
* @dataProvider decodeDataProvider
*/
public function testDecode(string $input, array $expected): void
{
$result = $this->serializer->decode($input);

$this->assertSame($expected, $result);
}

public static function decodeDataProvider(): array
{
return [
'success_payment' => [
'input' => 'OrderId=33554969;;ProcReturnCode=00;;HostRefNum=hostid;;AuthCode=gizlendi;;TxnResult=Success;;ErrorMessage=;;CampanyId=;;CampanyInstallCount=0;;CampanyShiftDateCount=0;;CampanyTxnId=;;CampanyType=;;CampanyInstallment=0;;CampanyDate=0;;CampanyAmnt=0;;TRXDATE=09.08.2024 10:40:34;;TransId=gizlendi;;ErrorCode=;;EarnedBonus=0,00;;UsedBonus=0,00;;AvailableBonus=0,00;;BonusToBonus=0;;CampaignBonus=0,00;;FoldedBonus=0;;SurchargeAmount=0;;Amount=1,00;;CardHolderName=gizlendi;;QrReferenceNumber=;;QrCardToken=;;QrData=;;QrPayIsSucess=False;;QrIssuerPaymentMethod=;;QrFastMessageReferenceNo=;;QrFastParticipantReceiverCode=;;QrFastParticipantReceiverName=;;QrFastParticipantSenderCode=;;QrFastSenderIban=;;QrFastParticipantSenderName=;;QrFastPaymentResultDesc=',
'expected' => [
'OrderId' => '33554969',
'ProcReturnCode' => '00',
'HostRefNum' => 'hostid',
'AuthCode' => 'gizlendi',
'TxnResult' => 'Success',
'ErrorMessage' => '',
'CampanyId' => '',
'CampanyInstallCount' => '0',
'CampanyShiftDateCount' => '0',
'CampanyTxnId' => '',
'CampanyType' => '',
'CampanyInstallment' => '0',
'CampanyDate' => '0',
'CampanyAmnt' => '0',
'TRXDATE' => '09.08.2024 10:40:34',
'TransId' => 'gizlendi',
'ErrorCode' => '',
'EarnedBonus' => '0,00',
'UsedBonus' => '0,00',
'AvailableBonus' => '0,00',
'BonusToBonus' => '0',
'CampaignBonus' => '0,00',
'FoldedBonus' => '0',
'SurchargeAmount' => '0',
'Amount' => '1,00',
'CardHolderName' => 'gizlendi',
'QrReferenceNumber' => '',
'QrCardToken' => '',
'QrData' => '',
'QrPayIsSucess' => 'False',
'QrIssuerPaymentMethod' => '',
'QrFastMessageReferenceNo' => '',
'QrFastParticipantReceiverCode' => '',
'QrFastParticipantReceiverName' => '',
'QrFastParticipantSenderCode' => '',
'QrFastSenderIban' => '',
'QrFastParticipantSenderName' => '',
'QrFastPaymentResultDesc' => '',
],
],
];
}
}

0 comments on commit b27a4d5

Please sign in to comment.