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

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}}

templates/python/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ load_dotenv("../../.env")
1616
{{#modes}}
1717
class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isSyncClient}}Sync{{/isSyncClient}}E2E:
1818
_helpers = Helpers()
19-
_e2e_app_id = environ.get("ALGOLIA_APPLICATION_ID")
19+
_e2e_app_id = environ.get("{{e2eAppID}}")
2020
if _e2e_app_id is None:
21-
raise Exception("please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests")
21+
raise Exception("please provide an `{{e2eAppID}}` env var for e2e tests")
2222

2323
_e2e_api_key = environ.get("{{e2eApiKey}}")
2424
if _e2e_api_key is None:

templates/ruby/tests/e2e/e2e.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Dotenv.load('../../.env')
99
class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}E2E < Test::Unit::TestCase
1010
def setup
1111
@client = Algolia::{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}.create(
12-
ENV.fetch('ALGOLIA_APPLICATION_ID', nil),
12+
ENV.fetch('{{e2eAppID}}', nil),
1313
ENV.fetch('{{e2eApiKey}}', nil){{#hasRegionalHost}},
1414
'{{{defaultRegion}}}'{{/hasRegionalHost}}
1515
)

templates/scala/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class {{clientPrefix}}TestE2E extends AnyFunSuite {
2626
{{/hasRegionalHost}}
2727
if (System.getenv("CI") == "true") {
2828
{{client}}(
29-
appId = System.getenv("ALGOLIA_APPLICATION_ID"),
29+
appId = System.getenv("{{e2eAppID}}"),
3030
apiKey = System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}},
3131
region = region{{/hasRegionalHost}}
3232
)
3333
} else {
3434
val dotenv = Dotenv.configure.directory("../../").load
3535
{{client}}(
36-
appId = dotenv.get("ALGOLIA_APPLICATION_ID"),
36+
appId = dotenv.get("{{e2eAppID}}"),
3737
apiKey = dotenv.get("{{e2eApiKey}}"){{#hasRegionalHost}},
3838
region = region{{/hasRegionalHost}}
3939
)

templates/swift/tests/e2e/e2e.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ final class {{client}}RequestsTestsE2E: XCTestCase {
3535
}
3636

3737
do {
38-
APPLICATION_ID = try XCTUnwrap(ProcessInfo.processInfo.environment["ALGOLIA_APPLICATION_ID"])
38+
APPLICATION_ID = try XCTUnwrap(ProcessInfo.processInfo.environment["{{e2eAppID}}"])
3939
} catch {
40-
XCTFail("Please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests")
40+
XCTFail("Please provide an `{{e2eAppID}}` env var for e2e tests")
4141
}
4242

4343
do {

tests/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
ALGOLIA_APPLICATION_ID=
22
ALGOLIA_ADMIN_KEY=
3+
34
MONITORING_API_KEY=
5+
6+
METIS_APPLICATION_ID=
7+
METIS_API_KEY=

tests/CTS/requests/composition/listCompositions.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
"request": {
1212
"path": "/1/compositions",
1313
"method": "GET"
14+
},
15+
"response": {
16+
"statusCode": 200,
17+
"body": {
18+
"items": [
19+
{
20+
"objectID": "id1",
21+
"description": "the first ever composition from the client",
22+
"behavior": {
23+
"injection": {
24+
"main": {
25+
"source": {
26+
"search": {
27+
"index": "cts_e2e_small"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
],
35+
"nbPages": 1
36+
}
1437
}
1538
}
1639
]

0 commit comments

Comments
 (0)