Skip to content

Conversation

millotp
Copy link
Collaborator

@millotp millotp commented Jun 1, 2022

🧭 What and Why

🎟 JIRA Ticket: APIC-467

Move the client tests generation from ts to java, to be able to reuse the type enhancement code, which is mandatory for typed languages like java, and useful for php too.

Changes included:

  • Remove hasRegionalHost from openapitools.json (can be derived from the spec)
  • Use camelize and capitalize for consistency with ts
  • Add the client test generator is Java
  • Remove the client test generator from ts
  • Harmonize the parameters between requests and client tests, to always be an array
  • Simplify the client test template a bit for js (still the same functionality)

🧪 Test

CI

@millotp millotp self-assigned this Jun 1, 2022
@netlify
Copy link

netlify bot commented Jun 1, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 57974d1
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6299fbe614858300088f1132

@algolia-bot
Copy link
Collaborator

algolia-bot commented Jun 1, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@millotp millotp requested review from damcou and eunjae-lee June 2, 2022 10:35
Copy link
Contributor

@damcou damcou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting to harmonize all the test generation, I'll let @eunjae-lee and @shortcuts validate the js part.
I let some questions regarding the format of the parameters in the tests. I thought we wanted to respect the number of parameters for languages like PHP and Java, and I think there are some differences, did I miss something ?

"endAt": "2022-02-01T13:37:01Z"
}
],
"parameters": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a little confused with this example: how can I know that this is one parameter containing name, variant and endAt indexes here and not 3 distinct parameters ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled by the generator (not in the PR but working in my upcoming one) where based on the name of the method, we look in the spec what the type should be and enhance the type accordingly, the same way it's done in the CTS. As this currently works for js java and php I assume it will work here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention here is to always have named parameter, that we can look up in the spec, and then based on the language we either provide the name parameters directly or just iterate on each one.

],
"parameters": {},
"expected": {
"error": "Parameter `index` is required when calling `getClickPositions`."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for PHP, we can only know that the given number of parameters wasn't correct (0 instead of 1) but can we know that the name of this parameter was actually index ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In php if the parameter is not provided it will be equal to null right ? at least this is what's tested for in AnalyticsClient.php:203

}
],
"parameters": {
"events": []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, when I look at that example, I would expect having a method with only one events param expected, but the param is actually an insightEvents array with an events index.

Copy link
Collaborator Author

@millotp millotp Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you managed to make it work for the CTS it will be the same here, the parameters object is the same as in pushEvents.json, and the transformation through the generator is the same, so the template can reuse the same generateParams.mustache file

"object": "$client",
"path": "getPersonalizationStrategy",
"parameters": [],
"parameters": {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are we ok that {} means no params, and {"whatever" : []} means one param with an empty array, and we shouldn't encounter the case{[]}anymore ?

Copy link
Collaborator Author

@millotp millotp Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's basically it for typed languages, there is a distinction for js between parameters: {} and parameters: undefined but it doesn't affect php or java

"parameters": [
{}
],
"parameters": {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a mandatory param here ? I see no expected error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I don't really know how it will handle this case, I'm checking with the java

"requests": []
}
],
"parameters": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the param should be getRecommendationsParams with a requests index no ?

@millotp
Copy link
Collaborator Author

millotp commented Jun 3, 2022

Some tests will have to change for the java and php to work, but this is not related to this PR, do you have want me to change something before merging @damcou ?

Copy link
Contributor

@damcou damcou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No let's merge so we can work on the java and php templates for client tests directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants