Skip to content

Commit d25ee7d

Browse files
committed
Add tests for PaymentsApp
1 parent 40bc07d commit d25ee7d

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"boardingToken": "eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
3+
"installationId": "mockedInstallationId"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": 403,
3+
"errorCode": "PA001",
4+
"message": "Merchant not permitted for this action.",
5+
"errorType": "security"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": 500,
3+
"errorCode": "PA002",
4+
"message": "An internal server error occurred.",
5+
"errorType": "api"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"paymentsApps": [
3+
{ "installationId": "app1", "merchantAccountCode": "merchantAccountCode", "status": "BOARDED" },
4+
{ "installationId": "app2", "merchantAccountCode": "merchantAccountCode", "status": "BOARDING" }
5+
]
6+
}

tests/Unit/PaymentsAppTest.php

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
<?php
2+
/**
3+
* ######
4+
* ######
5+
* ############ ####( ###### #####. ###### ############ ############
6+
* ############# #####( ###### #####. ###### ############# #############
7+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
9+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
10+
* ############# ############# ############# ############# ##### ######
11+
* ############ ############ ############# ############ ##### ######
12+
* ######
13+
* #############
14+
* ############
15+
*
16+
* Adyen API Library for PHP
17+
*
18+
* Copyright (c) 2023 Adyen N.V.
19+
* This file is open source and available under the MIT license.
20+
* See the LICENSE file for more info.
21+
*
22+
*/
23+
24+
namespace Adyen\Tests\Unit;
25+
26+
use Adyen\Service\PaymentsApp\PaymentsAppApi;
27+
use Adyen\AdyenException;
28+
29+
class PaymentsAppTest extends TestCaseMock
30+
{
31+
/**
32+
* @dataProvider boardingTokenSuccess
33+
*/
34+
public function testGeneratePaymentsAppBoardingTokenForMerchantSuccess($jsonFile, $httpStatus)
35+
{
36+
$client = $this->createMockClient($jsonFile, $httpStatus);
37+
38+
$paymentsAppApi = new PaymentsAppApi($client);
39+
40+
$requestParams = [
41+
'boardingRequestToken' => 'mockedRequestToken'
42+
];
43+
44+
$response = $paymentsAppApi->generatePaymentsAppBoardingTokenForMerchant(
45+
"MerchantAccount123",
46+
$requestParams
47+
);
48+
49+
$this->assertNotNull($response);
50+
$this->assertEquals("eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", $response['boardingToken']);
51+
$this->assertEquals("mockedInstallationId", $response['installationId']);
52+
}
53+
54+
/**
55+
* @dataProvider boardingTokenError
56+
*/
57+
public function testGeneratePaymentsAppBoardingTokenForMerchantError($jsonFile, $httpStatus)
58+
{
59+
$client = $this->createMockClient($jsonFile, $httpStatus);
60+
$paymentsAppApi = new PaymentsAppApi($client);
61+
62+
$requestParams = [
63+
'boardingRequestToken' => 'mockedRequestToken'
64+
];
65+
66+
try {
67+
$paymentsAppApi->generatePaymentsAppBoardingTokenForMerchant(
68+
"MerchantAccount123",
69+
$requestParams
70+
);
71+
$this->fail(AdyenException::class . " expected");
72+
} catch (AdyenException $e) {
73+
$this->assertEquals(403, $e->getStatus()); // Assuming AdyenException has getStatus() or public status $status
74+
// Assumes the error message from boardingToken-error-403.json contains "PA001"
75+
$this->assertStringContainsString("PA001", $e->getMessage());
76+
}
77+
}
78+
79+
/**
80+
* @dataProvider boardingTokenSuccess
81+
*/
82+
public function testGeneratePaymentsAppBoardingTokenForStoreSuccess($jsonFile, $httpStatus)
83+
{
84+
$client = $this->createMockClient($jsonFile, $httpStatus);
85+
$paymentsAppApi = new PaymentsAppApi($client);
86+
87+
$requestParams = [
88+
'boardingRequestToken' => 'mockedRequestToken'
89+
];
90+
91+
$response = $paymentsAppApi->generatePaymentsAppBoardingTokenForStore(
92+
"MerchantAccount123",
93+
"StoreEU",
94+
$requestParams
95+
);
96+
97+
$this->assertNotNull($response);
98+
$this->assertEquals("eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", $response['boardingToken']);
99+
$this->assertEquals("mockedInstallationId", $response['installationId']);
100+
}
101+
102+
/**
103+
* @dataProvider boardingTokenError
104+
*/
105+
public function testGeneratePaymentsAppBoardingTokenForStoreError($jsonFile, $httpStatus)
106+
{
107+
$client = $this->createMockClient($jsonFile, $httpStatus);
108+
$paymentsAppApi = new PaymentsAppApi($client);
109+
110+
$requestParams = [
111+
'boardingRequestToken' => 'mockedRequestToken'
112+
];
113+
114+
try {
115+
$paymentsAppApi->generatePaymentsAppBoardingTokenForStore(
116+
"MerchantAccount123",
117+
"StoreEU",
118+
$requestParams
119+
);
120+
$this->fail(AdyenException::class . " expected");
121+
} catch (AdyenException $e) {
122+
$this->assertEquals(403, $e->getStatus());
123+
$this->assertStringContainsString("PA001", $e->getMessage());
124+
}
125+
}
126+
127+
/**
128+
* @dataProvider appListSuccess
129+
*/
130+
public function testListPaymentsAppForMerchantSuccess($jsonFile, $httpStatus)
131+
{
132+
$client = $this->createMockClient($jsonFile, $httpStatus);
133+
$paymentsAppApi = new PaymentsAppApi($client);
134+
135+
$response = $paymentsAppApi->listPaymentsAppForMerchant("MerchantAccount123");
136+
137+
$this->assertNotNull($response);
138+
$this->assertArrayHasKey('paymentsApps', $response);
139+
$this->assertNotNull($response['paymentsApps']);
140+
$this->assertCount(2, $response['paymentsApps']);
141+
}
142+
143+
/**
144+
* @dataProvider appListError
145+
*/
146+
public function testListPaymentsAppForMerchantError($jsonFile, $httpStatus)
147+
{
148+
$client = $this->createMockClient($jsonFile, $httpStatus);
149+
$paymentsAppApi = new PaymentsAppApi($client);
150+
151+
try {
152+
$paymentsAppApi->listPaymentsAppForMerchant("MerchantAccount123");
153+
$this->fail(AdyenException::class . " expected");
154+
} catch (AdyenException $e) {
155+
$this->assertEquals(500, $e->getStatus());
156+
// Assumes the error message from paymentsAppList-error-500.json contains "PA002"
157+
$this->assertStringContainsString("PA002", $e->getMessage());
158+
}
159+
}
160+
161+
/**
162+
* @dataProvider appListSuccess
163+
*/
164+
public function testListPaymentsAppForStoreSuccess($jsonFile, $httpStatus)
165+
{
166+
$client = $this->createMockClient($jsonFile, $httpStatus);
167+
$paymentsAppApi = new PaymentsAppApi($client);
168+
169+
// Assuming the PHP method signature is:
170+
// listPaymentsAppForStore($merchantId, $storeId, array $queryParameters = null, array $requestOptions = null)
171+
// For this test, no queryParameters or requestOptions are passed beyond the required ones.
172+
$response = $paymentsAppApi->listPaymentsAppForStore("MerchantAccount123", "StoreEU");
173+
174+
$this->assertNotNull($response);
175+
$this->assertArrayHasKey('paymentsApps', $response);
176+
$this->assertNotNull($response['paymentsApps']);
177+
$this->assertCount(2, $response['paymentsApps']);
178+
}
179+
180+
public function testRevokePaymentsAppSuccess()
181+
{
182+
// Mocking a successful response with no content (HTTP 204)
183+
$client = $this->createMockClient(
184+
null, // No response body
185+
204 // HTTP 204 No Content status
186+
);
187+
$paymentsAppApi = new PaymentsAppApi($client);
188+
189+
// The Adyen PHP client's request method typically returns null if the response body is empty
190+
// and successfully decoded (json_decode('') === null).
191+
// The service method for a void operation might return null.
192+
$result = $paymentsAppApi->revokePaymentsApp("MerchantAccount123", "StoreEU");
193+
194+
// Assert that no exception was thrown (implicit by reaching this line)
195+
// and optionally assert the result if a specific return value (like null) is expected.
196+
$this->assertNull($result);
197+
}
198+
199+
public static function boardingTokenSuccess()
200+
{
201+
return array(
202+
array('tests/Resources/PaymentsApp/authorise-success.json', 200),
203+
);
204+
}
205+
206+
public static function boardingTokenError()
207+
{
208+
return array(
209+
array('tests/Resources/PaymentsApp/boardingToken-error-403.json', 403, "Invalid Merchant Account")
210+
);
211+
}
212+
213+
public static function appListSuccess()
214+
{
215+
return array(
216+
array('tests/Resources/PaymentsApp/paymentsAppList-success.json', 200),
217+
);
218+
}
219+
220+
public static function appListError()
221+
{
222+
return array(
223+
array('tests/Resources/PaymentsApp/paymentsAppList-error-500.json', 500, "Error")
224+
);
225+
}
226+
}

0 commit comments

Comments
 (0)