Skip to content

Commit 434ef86

Browse files
committed
feat: kotlin e2e
1 parent a2bb7b7 commit 434ef86

File tree

5 files changed

+96
-44
lines changed

5 files changed

+96
-44
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// {{generationBanner}}
2+
package com.algolia.e2e
3+
4+
import com.algolia.client.api.{{client}}
5+
import com.algolia.client.model.{{import}}.*
6+
import com.algolia.client.configuration.*
7+
import com.algolia.client.transport.*
8+
import com.algolia.utils.*
9+
import io.ktor.http.*
10+
import io.github.cdimascio.dotenv.Dotenv
11+
import kotlinx.coroutines.test.*
12+
import kotlinx.serialization.json.*
13+
import kotlinx.serialization.encodeToString
14+
import kotlin.test.*
15+
16+
class {{clientPrefix}}Test {
17+
18+
var client: {{client}};
19+
20+
init {
21+
if (System.getenv("CI") == "true") {
22+
var client = {{client}}(appId = System.getenv("ALGOLIA_APPLICATION_ID"), apiKey = System.getenv("{{e2eApiKey}}"){{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
23+
} else {
24+
val dotenv = Dotenv.configure().directory("../../").load()
25+
val client = {{client}}(appId = dotenv["ALGOLIA_APPLICATION_ID"], apiKey = dotenv["{{e2eApiKey}}"]{{#hasRegionalHost}}, region = "{{defaultRegion}}", {{/hasRegionalHost}});
26+
}
27+
}
28+
29+
{{#blocksE2E}}
30+
{{#tests}}
31+
@Test
32+
fun `{{#lambda.replaceBacktick}}{{{testName}}}{{testIndex}}{{/lambda.replaceBacktick}}`() = runTest {
33+
client.runTest(
34+
call = {
35+
{{> tests/method}}
36+
},
37+
{{#response}}
38+
{{#body}}
39+
response = {
40+
areJsonElementsEqual(Json.parseToJsonElement("{{#lambda.escapeQuotes}}{{{body}}}{{/lambda.escapeQuotes}}"), Json.parseToJsonElement(Json.encodeToString(it)))
41+
},
42+
{{/body}}
43+
{{/response}}
44+
)
45+
}
46+
47+
{{/tests}}
48+
{{/blocksE2E}}
49+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{#request}}
2+
assertEquals("{{{path}}}".toPathSegments(), it.url.pathSegments)
3+
assertEquals(HttpMethod.parse("{{method}}"), it.method)
4+
{{#headers}}
5+
assertContainsAll("""{{{.}}}""", it.headers)
6+
{{/headers}}
7+
{{#queryParameters}}
8+
assertQueryParams("""{{{.}}}""", it.url.encodedParameters)
9+
{{/queryParameters}}
10+
{{#body}}
11+
assertJsonBody("""{{{.}}}""", it.body)
12+
{{/body}}
13+
{{^body}}
14+
{{#assertNullBody}}
15+
assertNoBody(it.body)
16+
{{/assertNullBody}}
17+
{{^assertNullBody}}
18+
assertEmptyBody(it.body)
19+
{{/assertNullBody}}
20+
{{/body}}
21+
{{/request}}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{method}}(
2+
{{#parametersWithDataType}}
3+
{{> tests/request_param}}
4+
{{/parametersWithDataType}}
5+
{{#hasRequestOptions}}
6+
requestOptions = RequestOptions(
7+
{{#requestOptions.queryParameters}}
8+
urlParameters = buildMap {
9+
{{#parametersWithDataType}}
10+
put("{{{key}}}", {{> tests/param_value}})
11+
{{/parametersWithDataType}}
12+
},
13+
{{/requestOptions.queryParameters}}
14+
{{#requestOptions.headers}}
15+
headers = buildMap {
16+
{{#parametersWithDataType}}
17+
put("{{{key}}}", {{> tests/param_value}})
18+
{{/parametersWithDataType}}
19+
},
20+
{{/requestOptions.headers}}
21+
)
22+
{{/hasRequestOptions}}
23+
)

templates/kotlin/tests/requests/requests.mustache

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,10 @@ class {{clientPrefix}}Test {
3030
fun `{{#lambda.replaceBacktick}}{{{testName}}}{{testIndex}}{{/lambda.replaceBacktick}}`() = runTest {
3131
client.runTest(
3232
call = {
33-
{{method}}(
34-
{{#parametersWithDataType}}
35-
{{> tests/request_param}}
36-
{{/parametersWithDataType}}
37-
{{#hasRequestOptions}}
38-
requestOptions = RequestOptions(
39-
{{#requestOptions.queryParameters}}
40-
urlParameters = buildMap {
41-
{{#parametersWithDataType}}
42-
put("{{{key}}}", {{> tests/param_value}})
43-
{{/parametersWithDataType}}
44-
},
45-
{{/requestOptions.queryParameters}}
46-
{{#requestOptions.headers}}
47-
headers = buildMap {
48-
{{#parametersWithDataType}}
49-
put("{{{key}}}", {{> tests/param_value}})
50-
{{/parametersWithDataType}}
51-
},
52-
{{/requestOptions.headers}}
53-
)
54-
{{/hasRequestOptions}}
55-
)
33+
{{> tests/method}}
5634
},
5735
intercept = {
58-
{{#request}}
59-
assertEquals("{{{path}}}".toPathSegments(), it.url.pathSegments)
60-
assertEquals(HttpMethod.parse("{{method}}"), it.method)
61-
{{#headers}}
62-
assertContainsAll("""{{{.}}}""", it.headers)
63-
{{/headers}}
64-
{{#queryParameters}}
65-
assertQueryParams("""{{{.}}}""", it.url.encodedParameters)
66-
{{/queryParameters}}
67-
{{#body}}
68-
assertJsonBody("""{{{.}}}""", it.body)
69-
{{/body}}
70-
{{^body}}
71-
{{#assertNullBody}}
72-
assertNoBody(it.body)
73-
{{/assertNullBody}}
74-
{{^assertNullBody}}
75-
assertEmptyBody(it.body)
76-
{{/assertNullBody}}
77-
{{/body}}
78-
{{/request}}
36+
{{> tests/intercept}}
7937
},
8038
)
8139
}

tests/output/kotlin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ kotlin {
4444
implementation(kotlin("test-annotations-common"))
4545
implementation(libs.coroutines.test)
4646
implementation(libs.kotlinx.serialization.json)
47+
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
4748
}
4849
}
4950

0 commit comments

Comments
 (0)