Skip to content

Commit ad27abc

Browse files
authored
test(clients): test more region param and timeouts (#663)
1 parent ed97787 commit ad27abc

File tree

9 files changed

+218
-10
lines changed

9 files changed

+218
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"scripts": {
1414
"build:eslint": "yarn workspace eslint-plugin-automation-custom build && yarn install",
15-
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle || true",
15+
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle **/vendor || true",
1616
"cli": "yarn workspace scripts ts-node --transpile-only ./index.ts",
1717
"docker": "docker exec -it dev yarn cli $*",
1818
"docker:build": "./scripts/docker/build.sh",

templates/javascript/browser.mustache

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ export function {{apiName}}(
3030
throw new Error("`apiKey` is missing.");
3131
}
3232

33-
{{#hasRegionalHost}}{{^fallbackToAliasHost}}
33+
{{#hasRegionalHost}}
34+
{{^fallbackToAliasHost}}
3435
if (!region) {
3536
throw new Error("`region` is missing.");
3637
}
37-
38-
if (typeof region !== 'string' || !REGIONS.includes(region)) {
38+
{{/fallbackToAliasHost}}
39+
40+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
3941
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
4042
}
41-
{{/fallbackToAliasHost}}{{/hasRegionalHost}}
43+
{{/hasRegionalHost}}
4244

4345
return create{{capitalizedApiName}}({
4446
appId,

templates/javascript/node.mustache

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ export function {{apiName}}(
3030
throw new Error("`apiKey` is missing.");
3131
}
3232

33-
{{#hasRegionalHost}}{{^fallbackToAliasHost}}
33+
{{#hasRegionalHost}}
34+
{{^fallbackToAliasHost}}
3435
if (!region) {
3536
throw new Error("`region` is missing.");
3637
}
37-
38-
if (typeof region !== 'string' || !REGIONS.includes(region)) {
38+
{{/fallbackToAliasHost}}
39+
40+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
3941
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
4042
}
41-
{{/fallbackToAliasHost}}{{/hasRegionalHost}}
43+
{{/hasRegionalHost}}
4244

4345
return create{{capitalizedApiName}}({
4446
appId,

tests/CTS/client/abtesting/parameters.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,49 @@
2424
}
2525
}
2626
]
27+
},
28+
{
29+
"testName": "uses the correct region",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "my-app-id",
36+
"apiKey": "my-api-key",
37+
"region": "us"
38+
},
39+
"expected": {}
40+
},
41+
{
42+
"type": "method",
43+
"object": "$client",
44+
"path": "getABTest",
45+
"parameters": {
46+
"id": 123
47+
},
48+
"expected": {
49+
"type": "host",
50+
"match": "analytics.us.algolia.com"
51+
}
52+
}
53+
]
54+
},
55+
{
56+
"testName": "throws when incorrect region is given",
57+
"autoCreateClient": false,
58+
"steps": [
59+
{
60+
"type": "createClient",
61+
"parameters": {
62+
"appId": "my-app-id",
63+
"apiKey": "my-api-key",
64+
"region": "not_a_region"
65+
},
66+
"expected": {
67+
"error": "`region` must be one of the following: de, us"
68+
}
69+
}
70+
]
2771
}
2872
]

tests/CTS/client/analytics/parameters.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,50 @@
2525
}
2626
]
2727
},
28+
{
29+
"testName": "uses the correct region",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "my-app-id",
36+
"apiKey": "my-api-key",
37+
"region": "de"
38+
},
39+
"expected": {}
40+
},
41+
{
42+
"type": "method",
43+
"object": "$client",
44+
"path": "post",
45+
"parameters": {
46+
"path": "/test"
47+
},
48+
"expected": {
49+
"type": "host",
50+
"match": "analytics.de.algolia.com"
51+
}
52+
}
53+
]
54+
},
55+
{
56+
"testName": "throws when incorrect region is given",
57+
"autoCreateClient": false,
58+
"steps": [
59+
{
60+
"type": "createClient",
61+
"parameters": {
62+
"appId": "my-app-id",
63+
"apiKey": "my-api-key",
64+
"region": "not_a_region"
65+
},
66+
"expected": {
67+
"error": "`region` must be one of the following: de, us"
68+
}
69+
}
70+
]
71+
},
2872
{
2973
"testName": "getAverageClickPosition throws without index",
3074
"steps": [

tests/CTS/client/common/commonApi.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,27 @@
1717
]
1818
},
1919
{
20-
"testName": "calls api with correct timeouts",
20+
"testName": "calls api with default read timeouts",
21+
"steps": [
22+
{
23+
"type": "method",
24+
"object": "$client",
25+
"path": "get",
26+
"parameters": {
27+
"path": "/test"
28+
},
29+
"expected": {
30+
"type": "timeouts",
31+
"match": {
32+
"connectTimeout": 2000,
33+
"responseTimeout": 5000
34+
}
35+
}
36+
}
37+
]
38+
},
39+
{
40+
"testName": "calls api with default write timeouts",
2141
"steps": [
2242
{
2343
"type": "method",

tests/CTS/client/insights/parameters.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,49 @@
2424
}
2525
}
2626
]
27+
},
28+
{
29+
"testName": "uses the correct region",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "my-app-id",
36+
"apiKey": "my-api-key",
37+
"region": "us"
38+
},
39+
"expected": {}
40+
},
41+
{
42+
"type": "method",
43+
"object": "$client",
44+
"path": "del",
45+
"parameters": {
46+
"path": "/test"
47+
},
48+
"expected": {
49+
"type": "host",
50+
"match": "insights.us.algolia.io"
51+
}
52+
}
53+
]
54+
},
55+
{
56+
"testName": "throws when incorrect region is given",
57+
"autoCreateClient": false,
58+
"steps": [
59+
{
60+
"type": "createClient",
61+
"parameters": {
62+
"appId": "my-app-id",
63+
"apiKey": "my-api-key",
64+
"region": "not_a_region"
65+
},
66+
"expected": {
67+
"error": "`region` must be one of the following: de, us"
68+
}
69+
}
70+
]
2771
}
2872
]

tests/CTS/client/recommend/api.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,31 @@
2424
}
2525
}
2626
]
27+
},
28+
{
29+
"testName": "calls api with correct write host",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "test-app-id",
36+
"apiKey": "test-api-key"
37+
},
38+
"expected": {}
39+
},
40+
{
41+
"type": "method",
42+
"object": "$client",
43+
"path": "post",
44+
"parameters": {
45+
"path": "/test"
46+
},
47+
"expected": {
48+
"type": "host",
49+
"match": "test-app-id.algolia.net"
50+
}
51+
}
52+
]
2753
}
2854
]

tests/CTS/client/search/api.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,31 @@
2424
}
2525
}
2626
]
27+
},
28+
{
29+
"testName": "calls api with correct write host",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "test-app-id",
36+
"apiKey": "test-api-key"
37+
},
38+
"expected": {}
39+
},
40+
{
41+
"type": "method",
42+
"object": "$client",
43+
"path": "post",
44+
"parameters": {
45+
"path": "/test"
46+
},
47+
"expected": {
48+
"type": "host",
49+
"match": "test-app-id.algolia.net"
50+
}
51+
}
52+
]
2753
}
2854
]

0 commit comments

Comments
 (0)