-
Notifications
You must be signed in to change notification settings - Fork 21
feat(cts): add algoliasearch-lite #436
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bb66f51
feat(cts): add algoliasearch-lite
shortcuts da9cae4
millotp said 2 lines to change
shortcuts 1a8b685
Merge branch 'main' into feat/algoliasearch-lite-cts
shortcuts 6924ca0
regen all
shortcuts 95b1f2f
Merge branch 'main' into feat/algoliasearch-lite-cts
shortcuts 50f7490
Merge branch 'main' into feat/algoliasearch-lite-cts
shortcuts 2f73710
add javascript clause
shortcuts c251cf3
Merge branch 'main' into feat/algoliasearch-lite-cts
shortcuts b3a3600
is it sorted
shortcuts c2db902
format
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -142,9 +142,12 @@ public Map<String, Object> postProcessSupportingFileData( | |
for (Entry<String, Request[]> entry : cts.entrySet()) { | ||
String operationId = entry.getKey(); | ||
if (!operations.containsKey(operationId)) { | ||
throw new CTSException( | ||
// We only inform that it does not exist but skip the test generation | ||
System.out.println( | ||
"operationId " + operationId + " does not exist in the spec" | ||
); | ||
|
||
continue; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be much more conditional if we want to keep throwing, but we could only skip for |
||
CodegenOperation op = operations.get(operationId); | ||
|
||
|
@@ -183,7 +186,15 @@ public Map<String, Object> postProcessSupportingFileData( | |
private Map<String, Request[]> loadCTS() | ||
throws JsonParseException, JsonMappingException, IOException, CTSException { | ||
TreeMap<String, Request[]> cts = new TreeMap<>(); | ||
File dir = new File("tests/CTS/methods/requests/" + client); | ||
String clientName = client; | ||
|
||
// This special case allow us to read the `search` CTS to generated the | ||
// tests for the `algoliasearch-lite` client. | ||
if (clientName.equals("algoliasearch-lite")) { | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clientName = "search"; | ||
} | ||
|
||
File dir = new File("tests/CTS/methods/requests/" + clientName); | ||
File commonTestDir = new File("tests/CTS/methods/requests/common"); | ||
if (!dir.exists()) { | ||
throw new CTSException("CTS not found at " + dir.getAbsolutePath(), true); | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
160 changes: 160 additions & 0 deletions
160
tests/output/javascript/src/methods/requests/algoliasearch-lite.test.ts
This file contains hidden or 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,160 @@ | ||
import { algoliasearchLiteClient } from '@experimental-api-clients-automation/algoliasearch-lite'; | ||
import type { EchoResponse } from '@experimental-api-clients-automation/client-common'; | ||
import { echoRequester } from '@experimental-api-clients-automation/requester-node-http'; | ||
|
||
const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; | ||
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; | ||
|
||
const client = algoliasearchLiteClient(appId, apiKey, { | ||
requester: echoRequester(), | ||
}); | ||
|
||
describe('multipleQueries', () => { | ||
test('multipleQueries for a single request with minimal parameters', async () => { | ||
const req = (await client.multipleQueries({ | ||
requests: [{ indexName: 'theIndexName' }], | ||
strategy: 'stopIfEnoughMatches', | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/*/queries'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ | ||
requests: [{ indexName: 'theIndexName' }], | ||
strategy: 'stopIfEnoughMatches', | ||
}); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
|
||
test('multipleQueries for multiple requests with all parameters', async () => { | ||
const req = (await client.multipleQueries({ | ||
requests: [ | ||
{ | ||
indexName: 'theIndexName', | ||
query: 'test', | ||
type: 'facet', | ||
facet: 'theFacet', | ||
params: 'testParam', | ||
}, | ||
{ | ||
indexName: 'theIndexName', | ||
query: 'test', | ||
type: 'default', | ||
params: 'testParam', | ||
}, | ||
], | ||
strategy: 'stopIfEnoughMatches', | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/*/queries'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ | ||
requests: [ | ||
{ | ||
indexName: 'theIndexName', | ||
query: 'test', | ||
type: 'facet', | ||
facet: 'theFacet', | ||
params: 'testParam', | ||
}, | ||
{ | ||
indexName: 'theIndexName', | ||
query: 'test', | ||
type: 'default', | ||
params: 'testParam', | ||
}, | ||
], | ||
strategy: 'stopIfEnoughMatches', | ||
}); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('post', () => { | ||
test('allow post method for a custom path with minimal parameters', async () => { | ||
const req = (await client.post({ | ||
path: '/test/minimal', | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/test/minimal'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual(undefined); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
|
||
test('allow post method for a custom path with all parameters', async () => { | ||
const req = (await client.post({ | ||
path: '/test/all', | ||
parameters: { query: 'parameters' }, | ||
body: { body: 'parameters' }, | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/test/all'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ body: 'parameters' }); | ||
expect(req.searchParams).toEqual({ query: 'parameters' }); | ||
}); | ||
}); | ||
|
||
describe('search', () => { | ||
test('search with minimal parameters', async () => { | ||
const req = (await client.search({ | ||
indexName: 'indexName', | ||
searchParams: { query: 'myQuery' }, | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/indexName/query'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ query: 'myQuery' }); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
|
||
test('search with facetFilters', async () => { | ||
const req = (await client.search({ | ||
indexName: 'indexName', | ||
searchParams: { query: 'myQuery', facetFilters: ['tags:algolia'] }, | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/indexName/query'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ | ||
query: 'myQuery', | ||
facetFilters: ['tags:algolia'], | ||
}); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('searchForFacetValues', () => { | ||
test('get searchForFacetValues results with minimal parameters', async () => { | ||
const req = (await client.searchForFacetValues({ | ||
indexName: 'indexName', | ||
facetName: 'facetName', | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/indexName/facets/facetName/query'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual(undefined); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
|
||
test('get searchForFacetValues results with all parameters', async () => { | ||
const req = (await client.searchForFacetValues({ | ||
indexName: 'indexName', | ||
facetName: 'facetName', | ||
searchForFacetValuesRequest: { | ||
params: "query=foo&facetFilters=['bar']", | ||
facetQuery: 'foo', | ||
maxFacetHits: 42, | ||
}, | ||
})) as unknown as EchoResponse; | ||
|
||
expect(req.path).toEqual('/1/indexes/indexName/facets/facetName/query'); | ||
expect(req.method).toEqual('POST'); | ||
expect(req.data).toEqual({ | ||
params: "query=foo&facetFilters=['bar']", | ||
facetQuery: 'foo', | ||
maxFacetHits: 42, | ||
}); | ||
expect(req.searchParams).toEqual(undefined); | ||
}); | ||
}); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.