-
Notifications
You must be signed in to change notification settings - Fork 116
Add test for JSON serialisation #777
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
Conversation
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.
Summary of Changes
Hello @gcatanese, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new unit test to validate the JSON serialization logic for request models within the Adyen Checkout SDK. The primary goal is to ensure that complex data structures, such as CreateCheckoutSessionRequest with nested Amount and LineItem objects, are correctly transformed into their expected JSON representation, confirming proper attribute inclusion and formatting.
Highlights
- Comprehensive Serialization Validation: The test constructs a sample
CreateCheckoutSessionRequestwith various populated fields and asserts that itsjson_encoded output precisely matches a predefined expected JSON string, ensuring correct structure and data representation. - Dependency Addition: The
Adyen\Model\Checkout\LineItemclass has been imported to support the creation ofLineItemobjects within the new test case.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request adds a test case to verify the JSON serialization of the CreateCheckoutSessionRequest model, ensuring that attributes with default values are not included in the serialized output. Suggestions were made to improve the test's readability and maintainability by adding a comment explaining the test's purpose, extracting common parameters to constants, and using json_encode to generate the expected JSON string.
| public function testJsonSerializationMatchesExpected() | ||
| { |
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.
It's good to see a test for JSON serialization. Consider adding a comment explaining the purpose of this test, specifically that it verifies attributes with default values are not included in the JSON output. This enhances readability and maintainability.
/**
* Test request JSON payload serialization
* Verifies that attributes with default values are not included in the JSON output.
*/
public function testJsonSerializationMatchesExpected()| ->setMerchantAccount('YOUR_MERCHANT_ACCOUNT') | ||
| ->setReference('YOUR_PAYMENT_REFERENCE') | ||
| ->setReturnUrl('https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE') | ||
| ->setLineItems([$lineItem1, $lineItem2]); |
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.
Consider extracting the common parameters used in the CreateCheckoutSessionRequest to constants. This improves readability and maintainability, especially if these values are used in other tests as well.
$merchantAccount = 'YOUR_MERCHANT_ACCOUNT';
$paymentReference = 'YOUR_PAYMENT_REFERENCE';
$request = new CreateCheckoutSessionRequest();
$request
->setChannel('Web')
->setAmount($amount)
->setCountryCode('NL')
->setMerchantAccount($merchantAccount)
->setReference($paymentReference)
->setReturnUrl('https://mycompany.example.org/redirect?orderRef=' . $paymentReference)
->setLineItems([$lineItem1, $lineItem2]);| $expectedJson = <<<JSON | ||
| { | ||
| "channel": "Web", | ||
| "amount": { | ||
| "currency": "EUR", | ||
| "value": 10000 | ||
| }, | ||
| "countryCode": "NL", | ||
| "merchantAccount": "YOUR_MERCHANT_ACCOUNT", | ||
| "reference": "YOUR_PAYMENT_REFERENCE", | ||
| "returnUrl": "https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE", | ||
| "lineItems": [ | ||
| { | ||
| "quantity": 1, | ||
| "amountIncludingTax": 5000, | ||
| "description": "Sunglasses" | ||
| }, | ||
| { | ||
| "quantity": 1, | ||
| "amountIncludingTax": 5000, | ||
| "description": "Headphones" | ||
| } | ||
| ] | ||
| } | ||
| JSON; |
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 expectedJson is defined as a HEREDOC string. While this is valid, consider using json_encode with the JSON_PRETTY_PRINT option to generate the expected JSON string from a PHP array. This approach can improve readability and reduce the risk of syntax errors in the JSON string.
$expectedJson = json_encode([
"channel" => "Web",
"amount" => [
"currency" => "EUR",
"value" => 10000
],
"countryCode" => "NL",
"merchantAccount" => 'YOUR_MERCHANT_ACCOUNT',
"reference" => 'YOUR_PAYMENT_REFERENCE',
"returnUrl" => "https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE",
"lineItems" => [
[
"quantity" => 1,
"amountIncludingTax" => 5000,
"description" => "Sunglasses"
],
[
"quantity" => 1,
"amountIncludingTax" => 5000,
"description" => "Headphones"
]
]
], JSON_PRETTY_PRINT);
|



Add test to verify JSON serialisation (i.e. attributes with default value are not included)