Skip to content

Commit

Permalink
add unit test to assert the headers in the request
Browse files Browse the repository at this point in the history
  • Loading branch information
RokPopov committed Jan 18, 2024
1 parent e78482f commit 0a7ed4d
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion Test/Unit/Gateway/Http/Client/TransactionPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,49 @@ public function testPlaceRequestGeneratesIdempotencyKey()

$this->adyenHelperMock->method('createAdyenCheckoutService')->willReturn($serviceMock);

$this->transactionPayment->placeRequest($transferObjectMock);
$response = $this->transactionPayment->placeRequest($transferObjectMock);

$this->assertArrayHasKey('resultCode', $response);
$this->assertEquals('Authorised', $response['resultCode']);
}

public function testRequestHeadersAreAddedToPaymentsCall()
{
$requestBody = ['reference' => 'ABC12345', 'amount' => ['value' => 1000]];
$expectedHeaders = ['header1' => 'value1', 'header2' => 'value2'];

$transferObjectMock = $this->createConfiguredMock(TransferInterface::class, [
'getBody' => ['reference' => 'ABC12345', 'amount' => ['value' => 1000]],
'getHeaders' => ['header1' => 'value1', 'header2' => 'value2'],
'getClientConfig' => []
]);

$this->adyenHelperMock->expects($this->once())
->method('buildRequestHeaders')
->willReturn($expectedHeaders);

$mockedPaymentResponse = [
'reference' => 'ABC12345',
'amount' => ['value' => 100],
'resultCode' => 'Authorised'
];

$serviceMock = $this->createMock(Checkout::class);
$serviceMock->expects($this->once())
->method('payments')
->with(
$this->equalTo($requestBody),
$this->callback(function ($requestOptions) use ($expectedHeaders) {
return isset($requestOptions['headers']) && $requestOptions['headers'] === $expectedHeaders;
})
)
->willReturn($mockedPaymentResponse);

$this->adyenHelperMock->method('createAdyenCheckoutService')->willReturn($serviceMock);

$response = $this->transactionPayment->placeRequest($transferObjectMock);

$this->assertArrayHasKey('resultCode', $response);
$this->assertEquals('Authorised', $response['resultCode']);
}
}

0 comments on commit 0a7ed4d

Please sign in to comment.