Skip to content

Commit

Permalink
Improve deserialization unit testing (#1421)
Browse files Browse the repository at this point in the history
* Rename to ideal

* Add scheme deserialization test

* Improve unit tests

* Update returnUrl in unit test
  • Loading branch information
gcatanese authored Jan 24, 2025
1 parent b9ba24d commit b49b20f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
48 changes: 37 additions & 11 deletions src/test/java/com/adyen/CheckoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,49 @@ public void TestPaymentSuccess() throws Exception {
* Should be able to stringify and parse paymentMethod in CheckoutPaymentRequest (test oneOf serialization and deserialization)
*/
@Test
public void TestCheckoutPaymentRequestSerialization() throws Exception {
String paymentRequestJson = getFileContents("mocks/checkout/paymentRequest.json");
IdealDetails idealDetails = new IdealDetails();
idealDetails.setIssuer("issuerName");
Amount amount = new Amount().currency("EUR").value(1000L);
PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setAmount(amount);
paymentRequest.setMerchantAccount("myMerchantAccount");
paymentRequest.setReference("merchantReference");
paymentRequest.setReturnUrl("http://return.com");
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(idealDetails));
public void TestDeserializePaymentRequestIdeal() throws Exception {
String paymentRequestJson = getFileContents("mocks/checkout/paymentRequestIdeal.json");

PaymentRequest parsedCheckoutPaymentRequest = PaymentRequest.fromJson(paymentRequestJson);

// paymentMethod
assertEquals(IdealDetails.TypeEnum.IDEAL, parsedCheckoutPaymentRequest.getPaymentMethod().getIdealDetails().getType());
assertEquals("issuerName", parsedCheckoutPaymentRequest.getPaymentMethod().getIdealDetails().getIssuer());
// amount
assertEquals(1000L, parsedCheckoutPaymentRequest.getAmount().getValue().longValue());
assertEquals("EUR", parsedCheckoutPaymentRequest.getAmount().getCurrency());
// merchant account
assertEquals("myMerchantAccount", parsedCheckoutPaymentRequest.getMerchantAccount());
// reference
assertEquals("merchantReference", parsedCheckoutPaymentRequest.getReference());
// return url
assertEquals("https://your-company.com/..", parsedCheckoutPaymentRequest.getReturnUrl());
}

/**
* Deserialise CardDetails (scheme)
* @throws Exception
*/
@Test
public void TestDeserializePaymentRequestScheme() throws Exception {
String paymentRequestJson = getFileContents("mocks/checkout/paymentRequestScheme.json");

PaymentRequest parsedCheckoutPaymentRequest = PaymentRequest.fromJson(paymentRequestJson);
assertNotNull(parsedCheckoutPaymentRequest.getPaymentMethod());
assertEquals(CardDetails.TypeEnum.SCHEME, parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getType());
assertEquals("2.4.2", parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getThreeDS2SdkVersion());
// verify un-encrypted fields are empty
assertNull(parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getNumber());
assertNull(parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getCvc());
// verify encrypted fields are correct
assertNotNull(parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getEncryptedCardNumber());
assertEquals("eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwidmVyc2lvbiI6IjEifQ.DXQDEl3M" +
"dyyW_ZrJoF2Kt3P1H2wWaP1z-FgI6SuDv96lN7e_0ki0mUkI8AL2USS_iiMbG5W4NtD4Ut5TqCBPlgOZfN6vDyM8O6Df-" +
"qNbX7rnW9iQQUue_21oo6U9K2tpFEQ9rYgUVIFhfLdFmLZ4q8ejmXFSGuTh-iC06APs2zWdUn0v-S4q4ltAzhee_5yOvff" +
"oSCWOWiGltUqViVOnrllheH-POp4qfL9GbaIkjixPyLNLRizQTrOO_j3m0gczeiORcrjXI2NSouSkPP9M1K9nwUWX-jpVTf" +
"1PkqLTYRzGQwZCoL9JU9HabRXYdM_eLMtNaIfiBo_4wPq5Iocmww",
parsedCheckoutPaymentRequest.getPaymentMethod().getCardDetails().getEncryptedCardNumber());
}
/**
* Should make paymentMethods call
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"type":"ideal"
},
"reference":"merchantReference",
"returnUrl":"http://return.com"
"returnUrl":"https://your-company.com/.."
}
28 changes: 28 additions & 0 deletions src/test/resources/mocks/checkout/paymentRequestScheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"paymentMethod": {
"brand": null,
"checkoutAttemptId": null,
"cvc": null,
"encryptedCard": null,
"encryptedCardNumber": "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwidmVyc2lvbiI6IjEifQ.DXQDEl3MdyyW_ZrJoF2Kt3P1H2wWaP1z-FgI6SuDv96lN7e_0ki0mUkI8AL2USS_iiMbG5W4NtD4Ut5TqCBPlgOZfN6vDyM8O6Df-qNbX7rnW9iQQUue_21oo6U9K2tpFEQ9rYgUVIFhfLdFmLZ4q8ejmXFSGuTh-iC06APs2zWdUn0v-S4q4ltAzhee_5yOvffoSCWOWiGltUqViVOnrllheH-POp4qfL9GbaIkjixPyLNLRizQTrOO_j3m0gczeiORcrjXI2NSouSkPP9M1K9nwUWX-jpVTf1PkqLTYRzGQwZCoL9JU9HabRXYdM_eLMtNaIfiBo_4wPq5Iocmww",
"encryptedExpiryMonth": "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwidmVyc2lvbiI6IjEifQ.MtVkIf8d7nh22lpyf5QgnNWQnGGrjyk06qA5l-jGG0t5n2eLMRwoxEIq-U7XnWERGzZcmTKhJx31Li7rHOsKUimakfimrGdQVjBFmayf0Uq0mg74SW8Z2bG4ll1TKicPefjDVI1vG0zbOfBcHAWHH8D-xeZM7UqKnuVFErKGgJR84DcCLx8Ue5r7n1NftOYTlVWC65jC-h17c6Q9nvtF2-or-ln3lbK7aIomJO7prmFRJi4NzgCfdvdskrYaHQ-Cmbetl6WYk061KMfGovaUbFIKdzzqp1VIiJ5PBsmz3_poL9G_ZIbbMYomO7HQ5qpn2PZy5XEFV5unPSnAMgj0lw.VDKN7ExyIs2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i26AHweWKcPWlgl6B1g3z9pL__i46dG8BCd3LDX8ETmgurbbq8chObI-h7FYEZrmLfeTJcRfE0uW7GXvT9ZojIGA.QKdUIrCAsDoNOD3qN7dEqA.LmmCr1q5vKMt_m_ZkQbho7E-28H0N7Hxc8XVrX4yQXkZRqSaGLCOR4MiYV0uFFeV5qzBt6jpTHFANmT9DXQgsg.k9zkNnkggMuHdcpwsLvfmPTDhrw3zF00FXsw7p9QC_Q",
"expiryMonth": null,
"expiryYear": null,
"fundingSource": null,
"holderName": null,
"networkPaymentReference": null,
"number": null,
"shopperNotificationReference": null,
"srcCorrelationId": null,
"srcDigitalCardId": null,
"srcScheme": null,
"srcTokenReference": null,
"storedPaymentMethodId": null,
"threeDS2SdkVersion": "2.4.2",
"type": "scheme"
},
"isNullable": false,
"schemaType": "oneOf"
}

0 comments on commit b49b20f

Please sign in to comment.