Skip to content

Commit 4455b77

Browse files
authored
fix(cts): assert the error of chunkedBatch helpers (#3418)
1 parent c664a62 commit 4455b77

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

scripts/cts/testServer/chunkWrapper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ function addRoutes(app: Express): void {
3333
if (!chunkWrapperState[lang]) {
3434
chunkWrapperState[lang] = {};
3535
}
36+
37+
if (req.headers['x-algolia-api-key'] === 'wrong-api-key') {
38+
res.status(403).json({ message: 'Invalid Application-ID or API key', status: 403 });
39+
return;
40+
}
3641
chunkWrapperState[lang][helper] = (chunkWrapperState[lang][helper] ?? 0) + 1;
3742
switch (helper) {
3843
case 'saveObjects':

tests/CTS/client/search/helpers.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,56 @@
220220
}
221221
]
222222
},
223+
{
224+
"testName": "saveObjects should report errors",
225+
"autoCreateClient": false,
226+
"steps": [
227+
{
228+
"type": "createClient",
229+
"parameters": {
230+
"appId": "test-app-id",
231+
"apiKey": "wrong-api-key",
232+
"customHosts": [
233+
{
234+
"host": "${{localhost}}",
235+
"port": 6680
236+
}
237+
]
238+
}
239+
},
240+
{
241+
"type": "method",
242+
"method": "saveObjects",
243+
"parameters": {
244+
"indexName": "cts_e2e_saveObjects_${{language}}",
245+
"objects": [
246+
{
247+
"objectID": "1",
248+
"name": "Adam"
249+
},
250+
{
251+
"objectID": "2",
252+
"name": "Benoit"
253+
}
254+
]
255+
},
256+
"expected": {
257+
"error": {
258+
"csharp": "{\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}",
259+
"go": "API error [403] {\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}",
260+
"java": "Status Code: 403 - {\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}",
261+
"javascript": "Invalid Application-ID or API key",
262+
"kotlin": "Client request(POST http://${{localhost}}:6680/1/indexes/cts_e2e_saveObjects_kotlin/batch) invalid: 403 Forbidden. Text: \\\"{\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}\\\"",
263+
"php": "Invalid Application-ID or API key",
264+
"python": "Invalid Application-ID or API key",
265+
"ruby": "Invalid Application-ID or API key",
266+
"scala": "Invalid Application-ID or API key",
267+
"swift": "HTTP error: Status code: 403 Message: Invalid Application-ID or API key"
268+
}
269+
}
270+
}
271+
]
272+
},
223273
{
224274
"testName": "call partialUpdateObjects with createIfNotExists=true",
225275
"autoCreateClient": false,

tests/output/javascript/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -938,12 +938,12 @@ __metadata:
938938
languageName: node
939939
linkType: hard
940940

941-
"@types/node@npm:20.14.10":
942-
version: 20.14.10
943-
resolution: "@types/node@npm:20.14.10"
941+
"@types/node@npm:20.14.11":
942+
version: 20.14.11
943+
resolution: "@types/node@npm:20.14.11"
944944
dependencies:
945945
undici-types: "npm:~5.26.4"
946-
checksum: 10/672892cf94d0d95cf052f11271990686a0fd204cd1e5fe7a4ef240e5315e06711765dc47b9ec98627d3adac18b8c92bb7e2d8db21d18faa20bc3e3203a143e79
946+
checksum: 10/344e1ce1ed16c86ed1c4209ab4d1de67db83dd6b694a6fabe295c47144dde2c58dabddae9f39a0a2bdd246e95f8d141ccfe848e464884b48b8918df4f7788025
947947
languageName: node
948948
linkType: hard
949949

@@ -2067,7 +2067,7 @@ __metadata:
20672067
"@algolia/recommend": "link:../../../clients/algoliasearch-client-javascript/packages/recommend"
20682068
"@algolia/requester-node-http": "link:../../../clients/algoliasearch-client-javascript/packages/requester-node-http"
20692069
"@types/jest": "npm:29.5.12"
2070-
"@types/node": "npm:20.14.10"
2070+
"@types/node": "npm:20.14.11"
20712071
algoliasearch: "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch"
20722072
dotenv: "npm:16.4.5"
20732073
jest: "npm:29.7.0"

tests/output/scala/src/test/scala/algoliasearch/package.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ package object algoliasearch {
1616
@targetName("assertErrorFuture")
1717
def assertError(message: String)(call: => Future[_])(implicit ec: ExecutionContextExecutor): Unit = {
1818
Await.ready(call, Duration.Inf).value.get match {
19-
case Failure(exception) => assert(exception.getMessage == message, s"Error message does not match, expected: $message, got: ${exception.getMessage}")
20-
case Success(_) => assert(false, "Future should have failed")
19+
case Failure(exception) =>
20+
assert(
21+
exception.getMessage == message,
22+
s"Error message does not match, expected: $message, got: ${exception.getMessage}"
23+
)
24+
case Success(_) => assert(false, "Future should have failed")
2125
}
2226
}
2327
}

0 commit comments

Comments
 (0)