-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add client testing * chore: skip when template is missing * chore: skip when tests for client don't exist * test region WIP * fix tests * remove unnecessary url from echo requester * fix: update template to check region * fix: add hasReigonalHost to generators * fix: make regional optional in client testing * fix: test asynchronous errors * update tests * fix: remove duplicated import statements * chore: remove unused part * chore: format cts output * fix: remove createIndex * chore: do not use post- script in package.json * fix: type issues * Update tests/CTS/client/templates/javascript/suite.mustache Co-authored-by: Pierre Millot <[email protected]> * chore: add eslint to tests * chore: update output * run java cts on the CI * Revert "run java cts on the CI" This reverts commit 7a0358d. Co-authored-by: Pierre Millot <[email protected]>
- Loading branch information
Showing
28 changed files
with
614 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"testName": "does not throw when region is not given", | ||
"autoCreateClient": false, | ||
"steps": [ | ||
{ | ||
"type": "createClient", | ||
"parameters": { | ||
"appId": "my-app-id", | ||
"apiKey": "my-api-key", | ||
"region": "" | ||
}, | ||
"expected": { | ||
"error": false | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"testName": "getAverageClickPosition throws without index", | ||
"steps": [ | ||
{ | ||
"type": "method", | ||
"object": "$client", | ||
"path": "getClickPositions", | ||
"parameters": [{}], | ||
"expected": { | ||
"error": "Parameter `index` is required when calling `getClickPositions`." | ||
} | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"testName": "client throws with invalid parameters", | ||
"autoCreateClient": false, | ||
"steps": [ | ||
{ | ||
"type": "createClient", | ||
"parameters": { | ||
"apiKey": "blah" | ||
}, | ||
"expected": { | ||
"error": "`appId` is missing." | ||
} | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
new {{client}}( | ||
'{{parameters.appId}}', | ||
'{{parameters.apiKey}}', | ||
{{#hasRegionalHost}}'{{parameters.region}}',{{/hasRegionalHost}} | ||
{ | ||
requester: new EchoRequester() | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{#length}} | ||
expect(actual).toHaveLength({{length}}); | ||
{{/length}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{object}}{{#path}}.{{.}}{{/path}}({{{parameters}}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{#isCreateClient}} | ||
const $client = {{> createClient}} | ||
actual = $client; | ||
{{/isCreateClient}} | ||
|
||
{{#isVariable}} | ||
actual = {{> variable}} | ||
{{/isVariable}} | ||
|
||
{{#isMethod}} | ||
actual = {{> method}} | ||
{{/isMethod}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable require-await */ | ||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
// @ts-nocheck | ||
import { {{client}}, EchoRequester } from '{{{import}}}'; | ||
|
||
const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; | ||
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; | ||
|
||
function createClient(): {{client}} { | ||
return new {{client}}(appId, apiKey, {{#hasRegionalHost}}'us', {{/hasRegionalHost}}{ requester: new EchoRequester() }); | ||
} | ||
|
||
{{#blocks}} | ||
describe('{{operationId}}', () => { | ||
{{#tests}} | ||
test('{{testName}}', async () => { | ||
{{#autoCreateClient}} | ||
const $client = createClient(); | ||
{{/autoCreateClient}} | ||
|
||
let actual; | ||
{{#steps}} | ||
{{#expectedError}} | ||
await expect(new Promise((resolve, reject) => { | ||
{{> step}} | ||
if (actual instanceof Promise) { | ||
actual.then(resolve).catch(reject); | ||
} else { | ||
resolve(); | ||
} | ||
})).rejects.toThrow("{{{expectedError}}}") | ||
{{/expectedError}} | ||
|
||
{{^expectedError}} | ||
{{#expectedNoError}} | ||
await expect(new Promise((resolve, reject) => { | ||
{{> step}} | ||
if (actual instanceof Promise) { | ||
actual.then(resolve).catch(reject); | ||
} else { | ||
resolve(); | ||
} | ||
})).resolves.not.toThrow(); | ||
{{/expectedNoError}} | ||
|
||
{{^expectedNoError}} | ||
{{> step}} | ||
|
||
if (actual instanceof Promise) { | ||
actual = await actual; | ||
} | ||
|
||
{{#expected}} | ||
{{> expected}} | ||
{{/expected}} | ||
{{/expectedNoError}} | ||
{{/expectedError}} | ||
{{/steps}} | ||
}); | ||
|
||
{{/tests}} | ||
}) | ||
|
||
{{/blocks}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{object}}{{#path}}.{{.}}{{/path}}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @ts-nocheck | ||
import { AnalyticsApi, EchoRequester } from '@algolia/client-analytics'; | ||
|
||
const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; | ||
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; | ||
|
||
function createClient(): AnalyticsApi { | ||
return new AnalyticsApi(appId, apiKey, 'us', { | ||
requester: new EchoRequester(), | ||
}); | ||
} | ||
|
||
describe('basic', () => { | ||
test('does not throw when region is not given', async () => { | ||
let actual; | ||
|
||
await expect( | ||
new Promise((resolve, reject) => { | ||
const $client = new AnalyticsApi('my-app-id', 'my-api-key', '', { | ||
requester: new EchoRequester(), | ||
}); | ||
actual = $client; | ||
|
||
if (actual instanceof Promise) { | ||
actual.then(resolve).catch(reject); | ||
} else { | ||
resolve(); | ||
} | ||
}) | ||
).resolves.not.toThrow(); | ||
}); | ||
|
||
test('getAverageClickPosition throws without index', async () => { | ||
const $client = createClient(); | ||
|
||
let actual; | ||
await expect( | ||
new Promise((resolve, reject) => { | ||
actual = $client.getClickPositions({}); | ||
if (actual instanceof Promise) { | ||
actual.then(resolve).catch(reject); | ||
} else { | ||
resolve(); | ||
} | ||
}) | ||
).rejects.toThrow( | ||
'Parameter `index` is required when calling `getClickPositions`.' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.