Skip to content
Open
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 @@ -61,6 +61,7 @@ public void processOpts() {
ctsManager.addTestsSupportingFiles(supportingFiles);

testsGenerators.add(new TestsRequest(ctsManager));

testsGenerators.add(new TestsClient(ctsManager, true));
testsGenerators.add(new TestsClient(ctsManager, false));
} else if (mode.equals("snippets")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles, String outp
Helpers.createClientName(client, language) + extension
)
);

if (new File("templates/" + language + "/tests/e2e/e2e.mustache").exists()) {
if (this.client.equals("search")) {
supportingFiles.add(
new SupportingFile(
"tests/e2e/e2eAlt.mustache",
"tests/output/" + language + "/" + outputFolder + "/e2eAlt",
Helpers.createClientName(client, language) + extension
)
);
}

supportingFiles.add(
new SupportingFile(
"tests/e2e/e2e.mustache",
Expand Down
77 changes: 77 additions & 0 deletions templates/csharp/tests/e2e/e2eAlt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// {{generationBanner}}
using Algolia.Search.Http;
using Algolia.Search.Clients;
using Algolia.Search.Models.{{clientPrefix}};
using Algolia.Search.Serializer;
using Algolia.Search.Tests.Utils;
using Xunit;
using System.Text.Json;
using Quibble.Xunit;
using dotenv.net;
{{#isSearchClient}}
using Action = Algolia.Search.Models.Search.Action;
using Range = Algolia.Search.Models.Search.Range;
{{/isSearchClient}}
{{#isIngestionClient}}
using Action = Algolia.Search.Models.Ingestion.Action;
{{/isIngestionClient}}
{{#isCompositionClient}}
using Action = Algolia.Search.Models.Composition.Action;
{{/isCompositionClient}}

namespace Algolia.Search.e2eAlt;

public class {{client}}RequestTestsE2EAlt
{
private readonly {{client}} client;

public {{client}}RequestTestsE2EAlt()
{
DotEnv.Load(options: new DotEnvOptions(ignoreExceptions: true, probeForEnv: true, probeLevelsToSearch: 8, envFilePaths: new[] { ".env" }));

var appId = Environment.GetEnvironmentVariable("METIS_APPLICATION_ID");
if (appId == null)
{
throw new Exception("please provide an `METIS_APPLICATION_ID` env var for e2e tests");
}

var apiKey = Environment.GetEnvironmentVariable("METIS_API_KEY");
if (apiKey == null)
{
throw new Exception("please provide an `METIS_API_KEY` env var for e2e tests");
}

client = new {{client}}(new {{clientPrefix}}Config(appId, apiKey{{#hasRegionalHost}},"{{defaultRegion}}"{{/hasRegionalHost}}));
}

[Fact]
public void Dispose()
{

}

{{#blocksE2E}}
{{#tests}}
[Fact(DisplayName = "{{{testName}}}")]
public async Task {{#lambda.pascalcase}}{{method}}Test{{testIndex}}{{/lambda.pascalcase}}()
{
try {
var resp = {{> tests/method}};
{{#response}}
{{#statusCode}}
// Check status code {{statusCode}}
Assert.NotNull(resp);
{{/statusCode}}

{{#body}}
JsonAssert.EqualOverrideDefault("{{#lambda.escapeQuotes}}{{{.}}}{{/lambda.escapeQuotes}}", JsonSerializer.Serialize(resp, JsonConfig.Options), new JsonDiffConfig(true));
{{/body}}
} catch (Exception e)
{
Assert.Fail("An exception was thrown: " + e.Message);
}
{{/response}}
}
{{/tests}}
{{/blocksE2E}}
}
71 changes: 71 additions & 0 deletions templates/go/tests/e2e/e2eAlt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// {{generationBanner}}
package e2eAlt

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/require"
"github.com/kinbiko/jsonassert"
"github.com/joho/godotenv"

"gotests/tests"

"github.com/algolia/algoliasearch-client-go/v4/algolia/{{clientImport}}"
)

func createE2E{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t *testing.T) *{{clientPrefix}}.APIClient {
t.Helper()

appID := os.Getenv("METIS_APPLICATION_ID")
if appID == "" && os.Getenv("CI") != "true" {
err := godotenv.Load("../../../../.env")
require.NoError(t, err)
appID = os.Getenv("METIS_APPLICATION_ID")
}
apiKey := os.Getenv("METIS_API_KEY")
client, err := {{clientPrefix}}.NewClient(appID, apiKey, {{#hasRegionalHost}}{{clientPrefix}}.{{#lambda.uppercase}}{{defaultRegion}}{{/lambda.uppercase}},{{/hasRegionalHost}})
require.NoError(t, err)

return client
}

{{#blocksE2E}}
func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}E2E_{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}(t *testing.T) {
t.Parallel()
{{#tests}}
t.Run("{{{testName}}}", func(t *testing.T) {
t.Parallel()

client := createE2E{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t)
res, err := {{> tests/method}}
require.NoError(t, err)
_ = res

{{#response}}
{{#body}}
rawBody, err := json.Marshal(res)
require.NoError(t, err)

var rawBodyMap any
err = json.Unmarshal(rawBody, &rawBodyMap)
require.NoError(t, err)

expectedBodyRaw := `{{{.}}}`
var expectedBody any
err = json.Unmarshal([]byte(expectedBodyRaw), &expectedBody)
require.NoError(t, err)

unionBody := tests.Union(t, expectedBody, rawBodyMap)
unionBodyRaw, err := json.Marshal(unionBody)
require.NoError(t, err)

jsonassert.New(t).Assertf(string(unionBodyRaw), "%s", expectedBodyRaw)
{{/body}}
{{/response}}
})
{{/tests}}
}

{{/blocksE2E}}
54 changes: 54 additions & 0 deletions templates/java/tests/e2e/e2eAlt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.algolia.e2eAlt;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import com.algolia.api.{{client}};
import com.algolia.config.*;
import com.algolia.model.{{import}}.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import io.github.cdimascio.dotenv.Dotenv;
import java.util.*;
import java.time.Duration;
import org.junit.jupiter.api.*;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class {{client}}RequestsTestsE2EAlt {
private {{client}} client;
private ObjectMapper json;

@BeforeAll
void init() {
this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build();

if ("true".equals(System.getenv("CI"))) {
this.client = new {{client}}(System.getenv("METIS_APPLICATION_ID"), System.getenv("METIS_API_KEY"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
} else {
Dotenv dotenv = Dotenv.configure().directory("../../").load();
this.client = new {{client}}(dotenv.get("METIS_APPLICATION_ID"), dotenv.get("METIS_API_KEY"){{#hasRegionalHost}}, "{{defaultRegion}}"{{/hasRegionalHost}});
}
}

@AfterAll
void tearUp() throws Exception {
client.close();
}

{{#blocksE2E}}
{{#tests}}
@Test
@DisplayName("{{{testName}}}")
void {{method}}Test{{testIndex}}() {
{{returnType}} res = {{> tests/method}};
{{#response}}
{{#body}}
assertDoesNotThrow(() -> JSONAssert.assertEquals("{{#lambda.escapeQuotes}}{{{body}}}{{/lambda.escapeQuotes}}", json.writeValueAsString(res), JSONCompareMode.LENIENT));
{{/body}}
{{/response}}
}
{{/tests}}
{{/blocksE2E}}
}
37 changes: 37 additions & 0 deletions templates/javascript/tests/e2e/e2eAlt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// {{generationBanner}}
import { describe, test, expect } from 'vitest';

import { union } from '../helpers.js';

import { {{{clientName}}} } from '{{{importPackage}}}';
import type { RequestOptions } from '@algolia/client-common';

if (!process.env.METIS_APPLICATION_ID) {
throw new Error("please provide an `METIS_APPLICATION_ID` env var for e2e tests");
}

if (!process.env.METIS_API_KEY) {
throw new Error("please provide an `METIS_API_KEY` env var for e2e tests");
}

const client = {{{clientName}}}(process.env.METIS_APPLICATION_ID, process.env.METIS_API_KEY){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}};

{{#blocksE2E}}
describe('{{operationId}}', () => {
{{#tests}}
test('{{{testName}}}', async () => {
{{#response}}
{{#body}}const resp = {{/body}}{{> tests/method}};

{{#body}}
const expectedBody = {{{.}}};

expect(expectedBody).toEqual(union(expectedBody, resp));
{{/body}}
{{/response}}
});

{{/tests}}
})

{{/blocksE2E}}
56 changes: 56 additions & 0 deletions templates/kotlin/tests/e2e/e2eAlt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// {{generationBanner}}
package com.algolia.e2eAlt

import com.algolia.client.api.{{client}}
import com.algolia.client.model.{{import}}.*
import com.algolia.client.configuration.*
import com.algolia.client.transport.*
import com.algolia.utils.*
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import io.ktor.http.*
import io.github.cdimascio.dotenv.Dotenv
import kotlinx.coroutines.test.*
import kotlinx.serialization.json.*
import kotlinx.serialization.encodeToString
import kotlin.test.*
import kotlin.time.Duration.Companion.milliseconds

{{#isCompositionClient}}
import com.algolia.client.model.{{import}}.RequestBody
{{/isCompositionClient}}

class {{clientPrefix}}AltTest {

var client: {{client}};

init {
if (System.getenv("CI") == "true") {
this.client = {{client}}(appId = System.getenv("METIS_APPLICATION_ID"), apiKey = System.getenv("METIS_API_KEY"){{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
} else {
val dotenv = Dotenv.configure().directory("../../").load()
this.client = {{client}}(appId = dotenv["METIS_APPLICATION_ID"], apiKey = dotenv["METIS_API_KEY"]{{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
}
}

{{#blocksE2E}}
{{#tests}}
@Test
fun `{{#lambda.replaceBacktick}}{{{testName}}}{{testIndex}}{{/lambda.replaceBacktick}}`() = runTest {
client.runTest(
call = {
{{> tests/method}}
},
{{#response}}
{{#body}}
response = {
JSONAssert.assertEquals("{{#lambda.escapeQuotes}}{{{body}}}{{/lambda.escapeQuotes}}", Json.encodeToString(it), JSONCompareMode.LENIENT)
},
{{/body}}
{{/response}}
)
}

{{/tests}}
{{/blocksE2E}}
}
Loading
Loading