Skip to content

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 10 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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 can be much more conditional if we want to keep throwing, but we could only skip for algoliasearch-lite.

CodegenOperation op = operations.get(operationId);

Expand Down Expand Up @@ -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")) {
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);
Expand Down
37 changes: 37 additions & 0 deletions tests/CTS/methods/requests/search/multipleQueries.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
[
{
"method": "multipleQueries",
"testName": "multipleQueries for a single request with minimal parameters",
"parameters": {
"requests": [
{
"indexName": "theIndexName"
}
],
"strategy": "stopIfEnoughMatches"
},
"request": {
"path": "/1/indexes/*/queries",
"method": "POST",
"data": {
"requests": [
{
"indexName": "theIndexName"
}
],
"strategy": "stopIfEnoughMatches"
}
}
},
{
"method": "multipleQueries",
"testName": "multipleQueries for multiple requests with all parameters",
"parameters": {
"requests": [
{
Expand All @@ -9,6 +34,12 @@
"type": "facet",
"facet": "theFacet",
"params": "testParam"
},
{
"indexName": "theIndexName",
"query": "test",
"type": "default",
"params": "testParam"
}
],
"strategy": "stopIfEnoughMatches"
Expand All @@ -24,6 +55,12 @@
"type": "facet",
"facet": "theFacet",
"params": "testParam"
},
{
"indexName": "theIndexName",
"query": "test",
"type": "default",
"params": "testParam"
}
],
"strategy": "stopIfEnoughMatches"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,8 +1408,49 @@ void multipleBatchTest0() {
}

@Test
@DisplayName("multipleQueries")
@DisplayName("multipleQueries for a single request with minimal parameters")
void multipleQueriesTest0() {
MultipleQueriesParams multipleQueriesParams0 = new MultipleQueriesParams();
{
List<MultipleQueries> requests1 = new ArrayList<>();
{
MultipleQueries requests_02 = new MultipleQueries();
{
String indexName3 = "theIndexName";

requests_02.setIndexName(indexName3);
}
requests1.add(requests_02);
}
multipleQueriesParams0.setRequests(requests1);

MultipleQueriesStrategy strategy1 = MultipleQueriesStrategy.fromValue(
"stopIfEnoughMatches"
);

multipleQueriesParams0.setStrategy(strategy1);
}

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.multipleQueries(multipleQueriesParams0);
}
);

assertEquals(req.getPath(), "/1/indexes/*/queries");
assertEquals(req.getMethod(), "POST");

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"requests\":[{\"indexName\":\"theIndexName\"}],\"strategy\":\"stopIfEnoughMatches\"}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
});
}

@Test
@DisplayName("multipleQueries for multiple requests with all parameters")
void multipleQueriesTest1() {
MultipleQueriesParams multipleQueriesParams0 = new MultipleQueriesParams();
{
List<MultipleQueries> requests1 = new ArrayList<>();
Expand All @@ -1434,6 +1475,24 @@ void multipleQueriesTest0() {
requests_02.setParams(params3);
}
requests1.add(requests_02);

MultipleQueries requests_12 = new MultipleQueries();
{
String indexName3 = "theIndexName";

requests_12.setIndexName(indexName3);
String query3 = "test";

requests_12.setQuery(query3);

MultipleQueriesType type3 = MultipleQueriesType.fromValue("default");

requests_12.setType(type3);
String params3 = "testParam";

requests_12.setParams(params3);
}
requests1.add(requests_12);
}
multipleQueriesParams0.setRequests(requests1);

Expand All @@ -1454,7 +1513,7 @@ void multipleQueriesTest0() {

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"requests\":[{\"indexName\":\"theIndexName\",\"query\":\"test\",\"type\":\"facet\",\"facet\":\"theFacet\",\"params\":\"testParam\"}],\"strategy\":\"stopIfEnoughMatches\"}",
"{\"requests\":[{\"indexName\":\"theIndexName\",\"query\":\"test\",\"type\":\"facet\",\"facet\":\"theFacet\",\"params\":\"testParam\"},{\"indexName\":\"theIndexName\",\"query\":\"test\",\"type\":\"default\",\"params\":\"testParam\"}],\"strategy\":\"stopIfEnoughMatches\"}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
Expand Down
1 change: 1 addition & 0 deletions tests/output/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"test": "jest"
},
"dependencies": {
"@experimental-api-clients-automation/algoliasearch-lite": "0.0.5",
"@experimental-api-clients-automation/client-abtesting": "0.0.5",
"@experimental-api-clients-automation/client-analytics": "0.0.5",
"@experimental-api-clients-automation/client-common": "0.0.5",
Expand Down
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);
});
});
29 changes: 28 additions & 1 deletion tests/output/javascript/src/methods/requests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,22 @@ describe('multipleBatch', () => {
});

describe('multipleQueries', () => {
test('multipleQueries', async () => {
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: [
{
Expand All @@ -748,6 +763,12 @@ describe('multipleQueries', () => {
facet: 'theFacet',
params: 'testParam',
},
{
indexName: 'theIndexName',
query: 'test',
type: 'default',
params: 'testParam',
},
],
strategy: 'stopIfEnoughMatches',
})) as unknown as EchoResponse;
Expand All @@ -763,6 +784,12 @@ describe('multipleQueries', () => {
facet: 'theFacet',
params: 'testParam',
},
{
indexName: 'theIndexName',
query: 'test',
type: 'default',
params: 'testParam',
},
],
strategy: 'stopIfEnoughMatches',
});
Expand Down
Loading