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 algoliasearch-lite #436

Merged
merged 10 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.openapitools.codegen.*;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -146,20 +147,20 @@ public Map<String, Object> postProcessSupportingFileData(
language
);

for (Entry<String, Request[]> entry : cts.entrySet()) {
for (Entry<String, CodegenOperation> entry : operations.entrySet()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no sorting of operations ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that's what's missing I forgot!!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try

Copy link
Member Author

Choose a reason for hiding this comment

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

wouhou it works b3a3600

String operationId = entry.getKey();
if (!operations.containsKey(operationId)) {
if (!cts.containsKey(operationId)) {
throw new CTSException(
"operationId " + operationId + " does not exist in the spec"
);
}
CodegenOperation op = operations.get(operationId);
Request[] op = cts.get(operationId);

List<Object> tests = new ArrayList<>();
for (int i = 0; i < entry.getValue().length; i++) {
for (int i = 0; i < op.length; i++) {
Map<String, Object> test = paramsType.buildJSONForRequest(
entry.getValue()[i],
op,
op[i],
entry.getValue(),
i
);
tests.add(test);
Expand Down Expand Up @@ -190,7 +191,18 @@ 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, which is only available
// in JavaScript
if (
language.equals("javascript") && 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 All @@ -217,28 +229,32 @@ private Map<String, Request[]> loadCTS()
}

// operationId -> CodegenOperation
private HashMap<String, CodegenOperation> buildOperations(
private TreeMap<String, CodegenOperation> buildOperations(
Map<String, Object> objs
) {
HashMap<String, CodegenOperation> result = new HashMap<>();
List<Map<String, Object>> apis =
((Map<String, List<Map<String, Object>>>) objs.get("apiInfo")).get(
"apis"
);

for (Map<String, Object> api : apis) {
String apiName = ((String) api.get("baseName")).toLowerCase();
if (!apiName.equals(client.replace("-", ""))) {
continue;
}

List<CodegenOperation> operations =
((Map<String, List<CodegenOperation>>) api.get("operations")).get(
"operation"
);

for (CodegenOperation ope : operations) {
result.put(ope.operationId, ope);
}
}
return result;

return new TreeMap<String, CodegenOperation>(result);
}

private String createImportName() {
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
Loading