File tree Expand file tree Collapse file tree 9 files changed +218
-10
lines changed Expand file tree Collapse file tree 9 files changed +218
-10
lines changed Original file line number Diff line number Diff line change 12
12
],
13
13
"scripts" : {
14
14
"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" ,
16
16
"cli" : " yarn workspace scripts ts-node --transpile-only ./index.ts" ,
17
17
"docker" : " docker exec -it dev yarn cli $*" ,
18
18
"docker:build" : " ./scripts/docker/build.sh" ,
Original file line number Diff line number Diff line change @@ -30,15 +30,17 @@ export function {{apiName}}(
30
30
throw new Error(" `apiKey` is missing." );
31
31
}
32
32
33
- { {#hasRegionalHost} }{ {^fallbackToAliasHost} }
33
+ { {#hasRegionalHost} }
34
+ { {^fallbackToAliasHost} }
34
35
if (!region) {
35
36
throw new Error(" `region` is missing." );
36
37
}
37
-
38
- if (typeof region !== 'string' || !REGIONS.includes(region)) {
38
+ { {/fallbackToAliasHost} }
39
+
40
+ if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
39
41
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(' , ' )} `);
40
42
}
41
- { {/fallbackToAliasHost } } { {/ hasRegionalHost} }
43
+ { {/hasRegionalHost} }
42
44
43
45
return create{ {capitalizedApiName} }({
44
46
appId,
Original file line number Diff line number Diff line change @@ -30,15 +30,17 @@ export function {{apiName}}(
30
30
throw new Error(" `apiKey` is missing." );
31
31
}
32
32
33
- { {#hasRegionalHost} }{ {^fallbackToAliasHost} }
33
+ { {#hasRegionalHost} }
34
+ { {^fallbackToAliasHost} }
34
35
if (!region) {
35
36
throw new Error(" `region` is missing." );
36
37
}
37
-
38
- if (typeof region !== 'string' || !REGIONS.includes(region)) {
38
+ { {/fallbackToAliasHost} }
39
+
40
+ if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
39
41
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(' , ' )} `);
40
42
}
41
- { {/fallbackToAliasHost } } { {/ hasRegionalHost} }
43
+ { {/hasRegionalHost} }
42
44
43
45
return create{ {capitalizedApiName} }({
44
46
appId,
Original file line number Diff line number Diff line change 24
24
}
25
25
}
26
26
]
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
+ ]
27
71
}
28
72
]
Original file line number Diff line number Diff line change 25
25
}
26
26
]
27
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" : " 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
+ },
28
72
{
29
73
"testName" : " getAverageClickPosition throws without index" ,
30
74
"steps" : [
Original file line number Diff line number Diff line change 17
17
]
18
18
},
19
19
{
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" ,
21
41
"steps" : [
22
42
{
23
43
"type" : " method" ,
Original file line number Diff line number Diff line change 24
24
}
25
25
}
26
26
]
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
+ ]
27
71
}
28
72
]
Original file line number Diff line number Diff line change 24
24
}
25
25
}
26
26
]
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
+ ]
27
53
}
28
54
]
Original file line number Diff line number Diff line change 24
24
}
25
25
}
26
26
]
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
+ ]
27
53
}
28
54
]
You can’t perform that action at this time.
0 commit comments