Skip to content

Commit fefc290

Browse files
committed
fix(e2e): add e2e tests for composition api
1 parent 1ed8dad commit fefc290

File tree

16 files changed

+86
-29
lines changed

16 files changed

+86
-29
lines changed

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/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}}', () => {

templates/kotlin/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class {{clientPrefix}}Test {
2121

2222
init {
2323
if (System.getenv("CI") == "true") {
24-
this.client = {{client}}(appId = System.getenv("ALGOLIA_APPLICATION_ID"), apiKey = System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
24+
this.client = {{client}}(appId = System.getenv("{{e2eAppID}}"), apiKey = System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
2525
} else {
2626
val dotenv = Dotenv.configure().directory("../../").load()
27-
this.client = {{client}}(appId = dotenv["ALGOLIA_APPLICATION_ID"], apiKey = dotenv["{{e2eApiKey}}"]{{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
27+
this.client = {{client}}(appId = dotenv["{{e2eAppID}}"], apiKey = dotenv["{{e2eApiKey}}"]{{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
2828
}
2929
}
3030

templates/php/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Psr\Http\Message\RequestInterface;
1717
use Dotenv\Dotenv;
1818

1919
// we only read .env file if we run locally
20-
if (getenv('ALGOLIA_APPLICATION_ID')) {
20+
if (getenv('{{e2eAppID}}')) {
2121
$_ENV = getenv();
2222
} else {
2323
$dotenv = Dotenv::createImmutable('tests');
@@ -44,7 +44,7 @@ class {{clientPrefix}}Test extends TestCase
4444

4545
protected function getClient(): {{client}}
4646
{
47-
return {{client}}::create($_ENV['ALGOLIA_APPLICATION_ID'], $_ENV['{{e2eApiKey}}']{{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}});
47+
return {{client}}::create($_ENV['{{e2eAppID}}'], $_ENV['{{e2eApiKey}}']{{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}});
4848
}
4949

5050
{{#blocksE2E}}

0 commit comments

Comments
 (0)