Skip to content

Commit 4ec0c4c

Browse files
authored
fix(cts): add e2e tests for composition api [skip-bc] (#4111)
## 🧭 What and Why 🎟 JIRA Ticket: [DI-3209](https://algolia.atlassian.net/browse/DI-3209) Setup e2e with a special metis app, granted by the fleet team only to use for this CI.
1 parent 48fc1da commit 4ec0c4c

File tree

18 files changed

+91
-29
lines changed

18 files changed

+91
-29
lines changed

.github/workflows/check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ jobs:
189189
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
190190
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
191191
MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }}
192+
METIS_APPLICATION_ID: ${{ secrets.METIS_APPLICATION_ID }}
193+
METIS_API_KEY: ${{ secrets.METIS_API_KEY }}
192194
name: client javascript${{ needs.setup.outputs.RUN_GEN_JAVASCRIPT == 'true' && format('@{0}', fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).version) || '' }}
193195
steps:
194196
- uses: actions/checkout@v4

generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
8181
List<Object> blocksE2E = new ArrayList<>();
8282
ParametersWithDataType paramsType = new ParametersWithDataType(models, language, client, false);
8383

84-
bundle.put("e2eApiKey", client.equals("monitoring") ? "MONITORING_API_KEY" : "ALGOLIA_ADMIN_KEY");
84+
bundle.put("e2eAppID", client.equals("composition") ? "METIS_APPLICATION_ID" : "ALGOLIA_APPLICATION_ID");
85+
bundle.put(
86+
"e2eApiKey",
87+
client.equals("composition") ? "METIS_API_KEY" : (client.equals("monitoring") ? "MONITORING_API_KEY" : "ALGOLIA_ADMIN_KEY")
88+
);
8589
bundle.put("useEchoRequester", true);
8690

8791
for (Map.Entry<String, CodegenOperation> entry : operations.entrySet()) {

playground/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ SEARCH_INDEX=""
1010
SEARCH_QUERY=""
1111

1212
ANALYTICS_INDEX=""
13+
14+
METIS_APPLICATION_ID=
15+
METIS_API_KEY=

playground/javascript/node/algoliasearch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async function testAlgoliasearch() {
8080
}
8181

8282
try {
83-
const analyticsClient = client.initAnalytics({region: 'de'});
83+
const analyticsClient = client.initAnalytics({ region: 'de' });
8484

8585
const res = await analyticsClient.getTopFilterForAttribute({
8686
attribute: 'myAttribute1,myAttribute2',
@@ -97,7 +97,7 @@ async function testAlgoliasearch() {
9797
}
9898

9999
try {
100-
const abtestingClient = client.initAbtesting({region: 'us'});
100+
const abtestingClient = client.initAbtesting({ region: 'us' });
101101

102102
const res = await abtestingClient.getABTest({
103103
id: 42,

playground/javascript/node/composition.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
11
import { ApiError } from '@algolia/client-common';
22
import { compositionClient } from '@algolia/client-composition';
33

4-
const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
5-
const apiKey = process.env.ALGOLIA_ADMIN_KEY || '**** ADMIN_KEY *****';
4+
const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****';
5+
const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****';
66

77
// Init client with appId and apiKey
88
const client = compositionClient(appId, apiKey);
99

1010
async function testComposition() {
1111
try {
12-
const res = await client.listCompositions();
13-
12+
// create a new composition
13+
/*
14+
const res = await client.multipleBatch({
15+
requests: [
16+
{
17+
action: 'upsert',
18+
body: {
19+
objectID: 'id1',
20+
description: 'the first ever composition from the client',
21+
behavior: {
22+
injection: {
23+
main: {
24+
source: {
25+
search: {
26+
index: 'cts_e2e_small',
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
],
35+
});
1436
console.log(`[OK]`, res);
37+
*/
38+
39+
const compos = await client.listCompositions();
40+
41+
console.log(`[OK]`, compos);
1542
} catch (e) {
1643
if (e instanceof ApiError) {
1744
return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e);

playground/javascript/node/search.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ApiError } from '@algolia/client-common';
2-
import { apiClientVersion, searchClient } from '@algolia/client-search';
3-
import { SearchQuery } from '@algolia/client-search';
2+
import { apiClientVersion, searchClient, SearchQuery } from '@algolia/client-search';
43

54
const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
65
const apiKey = process.env.ALGOLIA_ADMIN_KEY || '**** SEARCH_API_KEY *****';

templates/csharp/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class {{client}}RequestTestsE2E
2525
{
2626
DotEnv.Load(options: new DotEnvOptions(ignoreExceptions: true, probeForEnv: true, probeLevelsToSearch: 8, envFilePaths: new[] { ".env" }));
2727

28-
var appId = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
28+
var appId = Environment.GetEnvironmentVariable("{{e2eAppID}}");
2929
if (appId == null)
3030
{
31-
throw new Exception("please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests");
31+
throw new Exception("please provide an `{{e2eAppID}}` env var for e2e tests");
3232
}
3333

3434
var apiKey = Environment.GetEnvironmentVariable("{{e2eApiKey}}");

templates/go/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
func createE2E{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t *testing.T) *{{clientPrefix}}.APIClient {
1616
t.Helper()
1717
18-
appID := os.Getenv("ALGOLIA_APPLICATION_ID")
18+
appID := os.Getenv("{{e2eAppID}}")
1919
if appID == "" && os.Getenv("CI") != "true" {
2020
err := godotenv.Load("../../../../.env")
2121
require.NoError(t, err)
22-
appID = os.Getenv("ALGOLIA_APPLICATION_ID")
22+
appID = os.Getenv("{{e2eAppID}}")
2323
}
2424
apiKey := os.Getenv("{{e2eApiKey}}")
2525
client, err := {{clientPrefix}}.NewClient(appID, apiKey, {{#hasRegionalHost}}{{clientPrefix}}.{{#lambda.uppercase}}{{defaultRegion}}{{/lambda.uppercase}},{{/hasRegionalHost}})

templates/java/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class {{client}}RequestsTestsE2E {
2424
this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build();
2525
2626
if ("true".equals(System.getenv("CI"))) {
27-
this.client = new {{client}}(System.getenv("ALGOLIA_APPLICATION_ID"), System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
27+
this.client = new {{client}}(System.getenv("{{e2eAppID}}"), System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
2828
} else {
2929
Dotenv dotenv = Dotenv.configure().directory("../../").load();
30-
this.client = new {{client}}(dotenv.get("ALGOLIA_APPLICATION_ID"), dotenv.get("{{e2eApiKey}}"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
30+
this.client = new {{client}}(dotenv.get("{{e2eAppID}}"), dotenv.get("{{e2eApiKey}}"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
3131
}
3232
}
3333

templates/javascript/tests/e2e/e2e.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import { compositionClient } from '@algolia/client-composition';
1414
{{/isCompositionClient}}
1515
import type { RequestOptions } from '@algolia/client-common';
1616

17-
if (!process.env.ALGOLIA_APPLICATION_ID) {
18-
throw new Error("please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests");
17+
if (!process.env.{{e2eAppID}}) {
18+
throw new Error("please provide an `{{e2eAppID}}` env var for e2e tests");
1919
}
2020

2121
if (!process.env.{{e2eApiKey}}) {
2222
throw new Error("please provide an `{{e2eApiKey}}` env var for e2e tests");
2323
}
2424

25-
const client = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}(process.env.ALGOLIA_APPLICATION_ID, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}};
25+
const client = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}(process.env.{{e2eAppID}}, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}};
2626

2727
{{#blocksE2E}}
2828
describe('{{operationId}}', () => {

0 commit comments

Comments
 (0)