Skip to content

feat(cts): add requestOptions tests #501

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

Merged
merged 4 commits into from
May 17, 2022
Merged

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented May 12, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-470

Changes included:

This PR adds tests for the requestOptions parameter, available on every methods of every clients:

  • The requestOptions parameter is available at the same level as the parameters in a CTS file
    • It was the easiest way to implement it and make it work for me, but we can definitely change how it's done, please provide feedbacks!
  • It only consider values under the queryParameters or headers option

I've leveraged the common tests added for the customRequest, so we can have tests generated on every clients under the same method.

What's next

Docs will be updated in https://algolia.atlassian.net/browse/APIC-484

🧪 Test

CI :D

@shortcuts shortcuts requested a review from a team May 12, 2022 16:20
@shortcuts shortcuts self-assigned this May 12, 2022
@shortcuts shortcuts requested review from eunjae-lee and millotp and removed request for a team May 12, 2022 16:20
@netlify
Copy link

netlify bot commented May 12, 2022

Deploy Preview for api-clients-automation ready!

Name Link
🔨 Latest commit 76c778a
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6283898e7be0340008c8a478
😎 Deploy Preview https://deploy-preview-501--api-clients-automation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 12, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

Nice ! Hope this will be enough to catch all the bugs :)

@shortcuts shortcuts force-pushed the feat/cts-requestOptions branch from 2e76ad4 to fd515f2 Compare May 16, 2022 16:26
@shortcuts shortcuts changed the base branch from main to fix/serialize-query-parameters May 16, 2022 16:26
@shortcuts shortcuts requested a review from millotp May 16, 2022 16:27
@shortcuts shortcuts force-pushed the feat/cts-requestOptions branch from fd515f2 to 55f1ead Compare May 16, 2022 16:29
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

Just minor comments, GG !

Base automatically changed from fix/serialize-query-parameters to main May 17, 2022 09:54
@shortcuts shortcuts force-pushed the feat/cts-requestOptions branch from 311ea83 to 81c74e9 Compare May 17, 2022 11:36
@@ -63,39 +63,19 @@ private function normalize($options)
];

foreach ($options as $optionName => $value) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@damcou @millotp

After adding boolean tests, I realized PHP formatted booleans array like [true, true, false] to [1,1,], which would have been wrong in our case

I also realized that we were handling query parameters twice (here, and in buildQuery), so I've moved all the logic there

Could you please confirm it's correct to you? Tests pass correctly but better safe than sorry

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine ... But I'm pretty sure at some point I had the issue with the attributesToRetrieve param not being formatted correctly in the CTS so now I'm quite lost why it's working :D .

Copy link
Member Author

Choose a reason for hiding this comment

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

It's now done directly here in the buildQuery method, looking at the CTS it's still formatted correctly. Do you have any other stuff in mind we should check?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this is the only issue of that type, I think we're good.

Comment on lines 23 to +36
$args = array_map(function ($value) {
if (is_array($value)) {
return json_encode($value);
// PHP converts `true,false` in arrays to `1,`, so we create strings instead
// to avoid sending wrong values
$values = array_map(function ($v) {
if (is_bool($v)) {
return $v ? 'true' : 'false';
}

return $v;
}, $value);

// We then return the array as a string comma separated
return implode(',', $values);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is what was duplicated in the RequestOptionFactory that I commented above

@shortcuts shortcuts requested a review from millotp May 17, 2022 12:56
@shortcuts shortcuts merged commit ba2689a into main May 17, 2022
@shortcuts shortcuts deleted the feat/cts-requestOptions branch May 17, 2022 13:47
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.

5 participants