Skip to content

Commit da8b588

Browse files
authored
Merge branch 'main' into feat/ingestion-push-endpoint
2 parents 73b9db6 + fa43c59 commit da8b588

File tree

9 files changed

+282
-41
lines changed

9 files changed

+282
-41
lines changed

tests/output/csharp/src/generated/client/Search.test.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,45 @@ public async Task HelpersTest3()
324324
);
325325
}
326326

327-
[Fact(DisplayName = "call partialUpdateObjects with createIfNotExists=true")]
327+
[Fact(DisplayName = "saveObjects should report errors")]
328328
public async Task HelpersTest4()
329+
{
330+
SearchConfig _config = new SearchConfig("test-app-id", "wrong-api-key")
331+
{
332+
CustomHosts = new List<StatefulHost>
333+
{
334+
new()
335+
{
336+
Scheme = HttpScheme.Http,
337+
Url = "localhost",
338+
Port = 6680,
339+
Up = true,
340+
LastUse = DateTime.UtcNow,
341+
Accept = CallType.Read | CallType.Write,
342+
}
343+
}
344+
};
345+
var client = new SearchClient(_config);
346+
347+
_ex = await Assert.ThrowsAnyAsync<Exception>(async () =>
348+
{
349+
var res = await client.SaveObjectsAsync(
350+
"cts_e2e_saveObjects_csharp",
351+
new List<Object>
352+
{
353+
new Dictionary<string, string> { { "objectID", "1" }, { "name", "Adam" } },
354+
new Dictionary<string, string> { { "objectID", "2" }, { "name", "Benoit" } }
355+
}
356+
);
357+
});
358+
Assert.Equal(
359+
"{\"message\":\"Invalid Application-ID or API key\",\"status\":403}".ToLowerInvariant(),
360+
_ex.Message.ToLowerInvariant()
361+
);
362+
}
363+
364+
[Fact(DisplayName = "call partialUpdateObjects with createIfNotExists=true")]
365+
public async Task HelpersTest5()
329366
{
330367
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
331368
{
@@ -362,7 +399,7 @@ public async Task HelpersTest4()
362399
}
363400

364401
[Fact(DisplayName = "call partialUpdateObjects with createIfNotExists=false")]
365-
public async Task HelpersTest5()
402+
public async Task HelpersTest6()
366403
{
367404
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
368405
{
@@ -399,7 +436,7 @@ public async Task HelpersTest5()
399436
}
400437

401438
[Fact(DisplayName = "call deleteObjects without error")]
402-
public async Task HelpersTest6()
439+
public async Task HelpersTest7()
403440
{
404441
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
405442
{
@@ -431,7 +468,7 @@ public async Task HelpersTest6()
431468
}
432469

433470
[Fact(DisplayName = "wait for api key helper - add")]
434-
public async Task HelpersTest7()
471+
public async Task HelpersTest8()
435472
{
436473
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
437474
{
@@ -463,7 +500,7 @@ public async Task HelpersTest7()
463500
}
464501

465502
[Fact(DisplayName = "wait for api key - update")]
466-
public async Task HelpersTest8()
503+
public async Task HelpersTest9()
467504
{
468505
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
469506
{
@@ -510,7 +547,7 @@ public async Task HelpersTest8()
510547
}
511548

512549
[Fact(DisplayName = "wait for api key - delete")]
513-
public async Task HelpersTest9()
550+
public async Task HelpersTest10()
514551
{
515552
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
516553
{

tests/output/go/tests/client/search_test.go

Lines changed: 32 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/java/src/test/java/com/algolia/client/Search.test.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,29 @@ void helpersTest3() {
279279
}
280280

281281
@Test
282-
@DisplayName("call partialUpdateObjects with createIfNotExists=true")
282+
@DisplayName("saveObjects should report errors")
283283
void helpersTest4() {
284+
assertDoesNotThrow(() -> {
285+
SearchClient client = new SearchClient(
286+
"test-app-id",
287+
"wrong-api-key",
288+
withCustomHosts(Arrays.asList(new Host("localhost", EnumSet.of(CallType.READ, CallType.WRITE), "http", 6680)), false)
289+
);
290+
{
291+
Exception exception = assertThrows(Exception.class, () -> {
292+
var res = client.saveObjects(
293+
"cts_e2e_saveObjects_java",
294+
List.of(Map.of("objectID", "1", "name", "Adam"), Map.of("objectID", "2", "name", "Benoit"))
295+
);
296+
});
297+
assertEquals("Status Code: 403 - {\"message\":\"Invalid Application-ID or API" + " key\",\"status\":403}", exception.getMessage());
298+
}
299+
});
300+
}
301+
302+
@Test
303+
@DisplayName("call partialUpdateObjects with createIfNotExists=true")
304+
void helpersTest5() {
284305
assertDoesNotThrow(() -> {
285306
SearchClient client = new SearchClient(
286307
"test-app-id",
@@ -301,7 +322,7 @@ void helpersTest4() {
301322

302323
@Test
303324
@DisplayName("call partialUpdateObjects with createIfNotExists=false")
304-
void helpersTest5() {
325+
void helpersTest6() {
305326
assertDoesNotThrow(() -> {
306327
SearchClient client = new SearchClient(
307328
"test-app-id",
@@ -322,7 +343,7 @@ void helpersTest5() {
322343

323344
@Test
324345
@DisplayName("call deleteObjects without error")
325-
void helpersTest6() {
346+
void helpersTest7() {
326347
assertDoesNotThrow(() -> {
327348
SearchClient client = new SearchClient(
328349
"test-app-id",
@@ -339,7 +360,7 @@ void helpersTest6() {
339360

340361
@Test
341362
@DisplayName("wait for api key helper - add")
342-
void helpersTest7() {
363+
void helpersTest8() {
343364
assertDoesNotThrow(() -> {
344365
SearchClient client = new SearchClient(
345366
"test-app-id",
@@ -361,7 +382,7 @@ void helpersTest7() {
361382

362383
@Test
363384
@DisplayName("wait for api key - update")
364-
void helpersTest8() {
385+
void helpersTest9() {
365386
assertDoesNotThrow(() -> {
366387
SearchClient client = new SearchClient(
367388
"test-app-id",
@@ -395,7 +416,7 @@ void helpersTest8() {
395416

396417
@Test
397418
@DisplayName("wait for api key - delete")
398-
void helpersTest9() {
419+
void helpersTest10() {
399420
assertDoesNotThrow(() -> {
400421
SearchClient client = new SearchClient(
401422
"test-app-id",

tests/output/javascript/src/client/search.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,27 @@ describe('helpers', () => {
209209
expect(result).toEqual([{ taskID: 333, objectIDs: ['1', '2'] }]);
210210
}, 15000);
211211

212+
test('saveObjects should report errors', async () => {
213+
const client = searchClient('test-app-id', 'wrong-api-key', {
214+
hosts: [
215+
{ url: 'localhost', port: 6680, accept: 'readWrite', protocol: 'http' },
216+
],
217+
});
218+
219+
try {
220+
const result = await client.saveObjects({
221+
indexName: 'cts_e2e_saveObjects_javascript',
222+
objects: [
223+
{ objectID: '1', name: 'Adam' },
224+
{ objectID: '2', name: 'Benoit' },
225+
],
226+
});
227+
throw new Error('test is expected to throw error');
228+
} catch (e) {
229+
expect((e as Error).message).toMatch('Invalid Application-ID or API key');
230+
}
231+
}, 15000);
232+
212233
test('call partialUpdateObjects with createIfNotExists=true', async () => {
213234
const client = searchClient('test-app-id', 'test-api-key', {
214235
hosts: [

tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,38 @@ class SearchTest {
363363
)
364364
}
365365

366+
@Test
367+
fun `saveObjects should report errors`() = runTest {
368+
val client = SearchClient(appId = "test-app-id", apiKey = "wrong-api-key", options = ClientOptions(hosts = listOf(Host(url = "localhost", protocol = "http", port = 6680))))
369+
assertFails {
370+
client.saveObjects(
371+
indexName = "cts_e2e_saveObjects_kotlin",
372+
objects = listOf(
373+
buildJsonObject {
374+
put(
375+
"objectID",
376+
JsonPrimitive("1"),
377+
)
378+
put(
379+
"name",
380+
JsonPrimitive("Adam"),
381+
)
382+
},
383+
buildJsonObject {
384+
put(
385+
"objectID",
386+
JsonPrimitive("2"),
387+
)
388+
put(
389+
"name",
390+
JsonPrimitive("Benoit"),
391+
)
392+
},
393+
),
394+
)
395+
}.let { error -> assertError(error, "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}\"") }
396+
}
397+
366398
@Test
367399
fun `call partialUpdateObjects with createIfNotExists=true`() = runTest {
368400
val client = SearchClient(appId = "test-app-id", apiKey = "test-api-key", options = ClientOptions(hosts = listOf(Host(url = "localhost", protocol = "http", port = 6680))))

tests/output/php/src/client/SearchTest.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,32 @@ public function test3helpers()
285285
);
286286
}
287287

288-
#[TestDox('call partialUpdateObjects with createIfNotExists=true')]
288+
#[TestDox('saveObjects should report errors')]
289289
public function test4helpers()
290+
{
291+
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'wrong-api-key')->setFullHosts(['http://localhost:6680']));
292+
293+
try {
294+
$res = $client->saveObjects(
295+
'cts_e2e_saveObjects_php',
296+
[
297+
['objectID' => '1',
298+
'name' => 'Adam',
299+
],
300+
301+
['objectID' => '2',
302+
'name' => 'Benoit',
303+
],
304+
],
305+
);
306+
$this->fail('Expected exception to be thrown');
307+
} catch (\Exception $e) {
308+
$this->assertEquals($e->getMessage(), 'Invalid Application-ID or API key');
309+
}
310+
}
311+
312+
#[TestDox('call partialUpdateObjects with createIfNotExists=true')]
313+
public function test5helpers()
290314
{
291315
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6680']));
292316

@@ -310,7 +334,7 @@ public function test4helpers()
310334
}
311335

312336
#[TestDox('call partialUpdateObjects with createIfNotExists=false')]
313-
public function test5helpers()
337+
public function test6helpers()
314338
{
315339
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6680']));
316340

@@ -334,7 +358,7 @@ public function test5helpers()
334358
}
335359

336360
#[TestDox('call deleteObjects without error')]
337-
public function test6helpers()
361+
public function test7helpers()
338362
{
339363
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6680']));
340364

@@ -353,7 +377,7 @@ public function test6helpers()
353377
}
354378

355379
#[TestDox('wait for api key helper - add')]
356-
public function test7helpers()
380+
public function test8helpers()
357381
{
358382
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6681']));
359383

@@ -368,7 +392,7 @@ public function test7helpers()
368392
}
369393

370394
#[TestDox('wait for api key - update')]
371-
public function test8helpers()
395+
public function test9helpers()
372396
{
373397
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6681']));
374398

@@ -405,7 +429,7 @@ public function test8helpers()
405429
}
406430

407431
#[TestDox('wait for api key - delete')]
408-
public function test9helpers()
432+
public function test10helpers()
409433
{
410434
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6681']));
411435

0 commit comments

Comments
 (0)