Skip to content
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

feat(cts): add tests for Predict #480

Merged
merged 1 commit into from
May 10, 2022
Merged

feat(cts): add tests for Predict #480

merged 1 commit into from
May 10, 2022

Conversation

shortcuts
Copy link
Member

🧭 What and Why

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

Changes included:

This PR adds tests for the Predict client to the CTS, with some tweaking around this client.

  • Our types were wrong, it's actually a kind-of complicated oneOf/allOf, which should be good now.
  • The CTS gen defaulted regions to us, which is wrong in that case.

🧪 Test

CI :D

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

netlify bot commented May 6, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit bdc5448
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6275286a65bef40008e38b46

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 6, 2022

✗ The generated branch has been deleted.

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

@@ -145,6 +145,7 @@ public Map<String, Object> postProcessSupportingFileData(
bundle.put("clientPrefix", Utils.createClientName(client, language));
bundle.put("import", createImportName());
bundle.put("hasRegionalHost", hasRegionalHost);
bundle.put("defaultRegion", client.equals("predict") ? "ew" : "us");
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 basic but should be enough for now, lmk if you want to change that to read the default field for example

@@ -101,6 +101,7 @@ export async function generateClientTests(
client: `${createClientName(client, language)}Client`,
blocks: modifyForMustache(testsBlocks),
hasRegionalHost: hasRegionalHost ? true : undefined,
defaultRegion: client === 'predict' ? 'ew' : 'us',
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as in the CTS

Base automatically changed from feat/predict-server-region to main May 6, 2022 13:42
@shortcuts shortcuts force-pushed the feat/add-predict-tests branch from 571111c to bdc5448 Compare May 6, 2022 13:53
@shortcuts shortcuts marked this pull request as ready for review May 6, 2022 13:53
Comment on lines +1 to +5
params:
oneOf:
- $ref: '#/modelsToRetrieve'
- $ref: '#/typesToRetrieve'
- $ref: '#/allParams'
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 the param that was wrong, we were accepting empty object while it should be either of them or both

@@ -11,7 +11,7 @@ const apiKey =
const userId = 'user1';

// Init client with appId and apiKey
const client = predictClient(appId, apiKey);
const client = predictClient(appId, apiKey, 'ew');
Copy link
Contributor

Choose a reason for hiding this comment

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

why 'ew' when it's default?

Copy link
Member Author

Choose a reason for hiding this comment

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

'ew' is the default value of the Predict spec servers

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, do we know why they chose that region ?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC they have a staging env that is defaulted to that for now, it might change in the future

@@ -11,7 +11,7 @@ const apiKey =
const userId = 'user1';

// Init client with appId and apiKey
const client = predictClient(appId, apiKey);
const client = predictClient(appId, apiKey, 'ew');
Copy link
Contributor

Choose a reason for hiding this comment

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

why 'ew' when it's default?

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

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

Looks good to me :)

(How was it to write client tests?)

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.

Good job 🚀

]
},
{
"testName": "does not throw when region is given",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test with no "region" param passed at all ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The test above should do the same as it's an empty string

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok so the param is mandatory in any case ?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this client yes, but in the insights one for example, no region parameters will fallback to their fallback host.

@shortcuts
Copy link
Member Author

(How was it to write client tests?)

Quite easy actually :D

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.

4 participants