-
Notifications
You must be signed in to change notification settings - Fork 147
test(terminal): validate if boxed flags will be passed as nullable #1732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d749774
9fe4c40
548eb09
77afdde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,11 +38,13 @@ | |
| import com.adyen.model.nexo.PaymentReceipt; | ||
| import com.adyen.model.nexo.PaymentRequest; | ||
| import com.adyen.model.nexo.PaymentResult; | ||
| import com.adyen.model.nexo.PaymentTransaction; | ||
| import com.adyen.model.nexo.Response; | ||
| import com.adyen.model.nexo.ResultType; | ||
| import com.adyen.model.nexo.SaleData; | ||
| import com.adyen.model.nexo.SaleToPOIRequest; | ||
| import com.adyen.model.nexo.SaleToPOIResponse; | ||
| import com.adyen.model.nexo.TransactionConditions; | ||
| import com.adyen.model.terminal.SaleToAcquirerData; | ||
| import com.adyen.model.terminal.TerminalAPIRequest; | ||
| import com.adyen.model.terminal.TerminalAPIResponse; | ||
|
|
@@ -299,6 +301,50 @@ public void syncInputRequestSuccess() throws Exception { | |
| assertFalse(requestAsJson.contains(": null"), "Found null value"); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * <p>When {@code setDebitPreferredFlag} is never called, the backing field stays {@code null} and | ||
| * Gson must omit it from the serialized JSON entirely. This allows the terminal to choose the | ||
| * payment type freely (DEBIT, CREDIT, or VOUCHER) rather than being forced to CREDIT by a | ||
| * spurious {@code "DebitPreferredFlag": false}. | ||
| */ | ||
| @Test | ||
| public void debitPreferredFlagOmittedFromJsonWhenNotSet() throws Exception { | ||
| Client client = createMockClientFromFile("mocks/terminal-api/payment-async-success"); | ||
| TerminalCloudAPI terminalCloudApi = new TerminalCloudAPI(client); | ||
|
|
||
| TerminalAPIRequest terminalAPIRequest = createTerminalAPIPaymentRequest(); | ||
|
|
||
| TransactionConditions transactionConditions = new TransactionConditions(); | ||
| // Deliberately do NOT call transactionConditions.setDebitPreferredFlag(...) | ||
|
|
||
| PaymentTransaction paymentTransaction = new PaymentTransaction(); | ||
| paymentTransaction.setTransactionConditions(transactionConditions); | ||
|
|
||
| terminalAPIRequest | ||
| .getSaleToPOIRequest() | ||
| .getPaymentRequest() | ||
| .setPaymentTransaction(paymentTransaction); | ||
|
Comment on lines
+321
to
+327
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of creating a new terminalAPIRequest
.getSaleToPOIRequest()
.getPaymentRequest()
.getPaymentTransaction()
.setTransactionConditions(transactionConditions); |
||
|
|
||
| terminalCloudApi.async(terminalAPIRequest); | ||
|
|
||
| final ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); | ||
| verify(client.getHttpClient()) | ||
| .request( | ||
| isNotNull(), | ||
| captor.capture(), | ||
| any(com.adyen.Config.class), | ||
| eq(true), | ||
| isNull(), | ||
| eq(ApiConstants.HttpMethod.POST), | ||
| isNull()); | ||
|
|
||
| String requestAsJson = captor.getValue(); | ||
| assertFalse( | ||
| requestAsJson.contains("DebitPreferredFlag"), | ||
| "DebitPreferredFlag must be absent from JSON when setter is never called"); | ||
| } | ||
|
|
||
| /** Mocked response for stored value type for POST /sync */ | ||
| @Test | ||
| public void syncPaymentRequestStoredValueSuccess() throws Exception { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Javadoc comment has some minor formatting issues. There's an unnecessary blank line at the beginning, and the
<p>tag is not needed for a single-paragraph comment. For better readability and adherence to standard Java conventions, you can simplify the comment block.