@joystick.js/db-canary 0.0.0-canary.2294 → 0.0.0-canary.2296

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import test from 'ava';
2
2
  import { create_server } from '../../src/server/index.js';
3
3
  import joystickdb from '../../src/client/index.js';
4
4
  import { writeFileSync, unlinkSync, existsSync } from 'fs';
5
- import { reset_auth_state } from '../../src/server/lib/auth_manager.js';
5
+ import { reset_auth_state } from '../../src/server/lib/user_auth_manager.js';
6
6
 
7
7
  let server;
8
8
  let client;
@@ -53,7 +53,7 @@ test.afterEach(async () => {
53
53
  await reset_auth_state();
54
54
  });
55
55
 
56
- test('client can be created with custom options', (t) => {
56
+ test('client can be created with custom options and authentication object', (t) => {
57
57
  client = joystickdb.client({
58
58
  host: '127.0.0.1',
59
59
  port: 9999,
@@ -61,7 +61,10 @@ test('client can be created with custom options', (t) => {
61
61
  reconnect: false,
62
62
  max_reconnect_attempts: 5,
63
63
  reconnect_delay: 2000,
64
- password: 'test_password',
64
+ authentication: {
65
+ username: 'test_user',
66
+ password: 'test_password'
67
+ },
65
68
  auto_connect: false
66
69
  });
67
70
 
@@ -71,7 +74,181 @@ test('client can be created with custom options', (t) => {
71
74
  t.is(client.reconnect, false);
72
75
  t.is(client.max_reconnect_attempts, 5);
73
76
  t.is(client.reconnect_delay, 2000);
74
- t.is(client.password, 'test_password');
77
+ t.deepEqual(client.authentication, { username: 'test_user', password: 'test_password' });
78
+ });
79
+
80
+ test('client rejects old password-only authentication format', (t) => {
81
+ const error = t.throws(() => {
82
+ client = joystickdb.client({
83
+ host: '127.0.0.1',
84
+ port: 9999,
85
+ password: 'old_style_password',
86
+ auto_connect: false
87
+ });
88
+ });
89
+
90
+ t.truthy(error.message.includes('Authentication must be provided as an object with username and password'));
91
+ });
92
+
93
+ test('client can setup initial admin and authenticate with username/password', async (t) => {
94
+ const test_port = get_next_port();
95
+ server = await create_server();
96
+
97
+ await new Promise((resolve) => {
98
+ server.listen(test_port, () => {
99
+ setTimeout(resolve, 100);
100
+ });
101
+ });
102
+
103
+ client = joystickdb.client({
104
+ port: test_port,
105
+ reconnect: false
106
+ });
107
+
108
+ await new Promise((resolve) => {
109
+ client.on('connect', resolve);
110
+ });
111
+
112
+ // Setup initial admin user
113
+ const admin_result = await client.admin('setup_initial_admin', {
114
+ username: 'admin',
115
+ password: 'admin123',
116
+ email: 'admin@test.com'
117
+ });
118
+
119
+ t.is(admin_result.ok, 1);
120
+ t.truthy(admin_result.message.includes('Initial admin user created'));
121
+
122
+ client.disconnect();
123
+
124
+ // Connect with new authentication format
125
+ client = joystickdb.client({
126
+ port: test_port,
127
+ reconnect: false,
128
+ authentication: {
129
+ username: 'admin',
130
+ password: 'admin123'
131
+ }
132
+ });
133
+
134
+ await new Promise((resolve) => {
135
+ client.on('authenticated', resolve);
136
+ });
137
+
138
+ t.is(client.is_authenticated, true);
139
+ });
140
+
141
+ test('client authentication fails with invalid username/password', async (t) => {
142
+ const test_port = get_next_port();
143
+ server = await create_server();
144
+
145
+ await new Promise((resolve) => {
146
+ server.listen(test_port, () => {
147
+ setTimeout(resolve, 100);
148
+ });
149
+ });
150
+
151
+ // Setup admin first
152
+ const setup_client = joystickdb.client({
153
+ port: test_port,
154
+ reconnect: false
155
+ });
156
+
157
+ await new Promise((resolve) => {
158
+ setup_client.on('connect', resolve);
159
+ });
160
+
161
+ await setup_client.admin('setup_initial_admin', {
162
+ username: 'admin',
163
+ password: 'admin123'
164
+ });
165
+ setup_client.disconnect();
166
+
167
+ // Try to connect with invalid credentials
168
+ client = joystickdb.client({
169
+ port: test_port,
170
+ reconnect: false,
171
+ authentication: {
172
+ username: 'admin',
173
+ password: 'wrong_password'
174
+ }
175
+ });
176
+
177
+ const error = await new Promise((resolve) => {
178
+ client.on('error', resolve);
179
+ });
180
+
181
+ t.truthy(error.message.includes('Authentication') || error.message.includes('Invalid credentials'));
182
+ });
183
+
184
+ test('client can create and authenticate multiple users', async (t) => {
185
+ const test_port = get_next_port();
186
+ server = await create_server();
187
+
188
+ await new Promise((resolve) => {
189
+ server.listen(test_port, () => {
190
+ setTimeout(resolve, 100);
191
+ });
192
+ });
193
+
194
+ // Setup admin
195
+ const admin_client = joystickdb.client({
196
+ port: test_port,
197
+ reconnect: false
198
+ });
199
+
200
+ await new Promise((resolve) => {
201
+ admin_client.on('connect', resolve);
202
+ });
203
+
204
+ await admin_client.admin('setup_initial_admin', {
205
+ username: 'admin',
206
+ password: 'admin123'
207
+ });
208
+
209
+ admin_client.disconnect();
210
+
211
+ // Connect as admin
212
+ const admin_auth_client = joystickdb.client({
213
+ port: test_port,
214
+ reconnect: false,
215
+ authentication: {
216
+ username: 'admin',
217
+ password: 'admin123'
218
+ }
219
+ });
220
+
221
+ await new Promise((resolve) => {
222
+ admin_auth_client.on('authenticated', resolve);
223
+ });
224
+
225
+ // Create regular user
226
+ const create_user_result = await admin_auth_client.admin('create_user', {
227
+ username: 'user1',
228
+ password: 'user123',
229
+ email: 'user1@test.com'
230
+ });
231
+
232
+ t.is(create_user_result.ok, 1);
233
+ t.truthy(create_user_result.message.includes('User created successfully'));
234
+
235
+ admin_auth_client.disconnect();
236
+
237
+ // Connect as the new user
238
+ client = joystickdb.client({
239
+ port: test_port,
240
+ reconnect: false,
241
+ authentication: {
242
+ username: 'user1',
243
+ password: 'user123'
244
+ }
245
+ });
246
+
247
+ await new Promise((resolve) => {
248
+ client.on('authenticated', resolve);
249
+ });
250
+
251
+ t.is(client.is_authenticated, true);
75
252
  });
76
253
 
77
254
  test('client can setup authentication', async (t) => {
@@ -93,11 +270,14 @@ test('client can setup authentication', async (t) => {
93
270
  client.on('connect', resolve);
94
271
  });
95
272
 
96
- const result = await client.setup();
273
+ const result = await client.admin('setup_initial_admin', {
274
+ username: 'admin',
275
+ password: 'admin123',
276
+ email: 'admin@test.com'
277
+ });
97
278
 
98
279
  t.is(result.ok, 1);
99
- t.truthy(result.password);
100
- t.truthy(result.message);
280
+ t.truthy(result.message.includes('Initial admin user created'));
101
281
  });
102
282
 
103
283
  test('client can authenticate with valid password', async (t) => {
@@ -119,13 +299,21 @@ test('client can authenticate with valid password', async (t) => {
119
299
  setup_client.on('connect', resolve);
120
300
  });
121
301
 
122
- const setup_result = await setup_client.setup();
302
+ await setup_client.admin('setup_initial_admin', {
303
+ username: 'admin',
304
+ password: 'admin123',
305
+ email: 'admin@test.com'
306
+ });
123
307
  setup_client.disconnect();
124
308
 
309
+ // Connect with authentication object format
125
310
  client = joystickdb.client({
126
311
  port: test_port,
127
312
  reconnect: false,
128
- password: setup_result.password
313
+ authentication: {
314
+ username: 'admin',
315
+ password: 'admin123'
316
+ }
129
317
  });
130
318
 
131
319
  await new Promise((resolve) => {
@@ -145,6 +333,7 @@ test('client authentication fails with invalid password', async (t) => {
145
333
  });
146
334
  });
147
335
 
336
+ // Setup admin first
148
337
  const setup_client = joystickdb.client({
149
338
  port: test_port,
150
339
  reconnect: false
@@ -154,13 +343,20 @@ test('client authentication fails with invalid password', async (t) => {
154
343
  setup_client.on('connect', resolve);
155
344
  });
156
345
 
157
- await setup_client.setup();
346
+ await setup_client.admin('setup_initial_admin', {
347
+ username: 'admin',
348
+ password: 'admin123'
349
+ });
158
350
  setup_client.disconnect();
159
351
 
352
+ // Try with invalid password using authentication object
160
353
  client = joystickdb.client({
161
354
  port: test_port,
162
355
  reconnect: false,
163
- password: 'invalid_password'
356
+ authentication: {
357
+ username: 'admin',
358
+ password: 'invalid_password'
359
+ }
164
360
  });
165
361
 
166
362
  const error = await new Promise((resolve) => {
@@ -213,13 +409,20 @@ test('client can perform CRUD operations', async (t) => {
213
409
  setup_client.on('connect', resolve);
214
410
  });
215
411
 
216
- const setup_result = await setup_client.setup();
412
+ await setup_client.admin('setup_initial_admin', {
413
+ username: 'admin',
414
+ password: 'admin123',
415
+ email: 'admin@test.com'
416
+ });
217
417
  setup_client.disconnect();
218
418
 
219
419
  client = joystickdb.client({
220
420
  port: test_port,
221
421
  reconnect: false,
222
- password: setup_result.password
422
+ authentication: {
423
+ username: 'admin',
424
+ password: 'admin123'
425
+ }
223
426
  });
224
427
 
225
428
  await new Promise((resolve) => {
@@ -289,13 +492,20 @@ test('client can perform find operation with multiple results', async (t) => {
289
492
  setup_client.on('connect', resolve);
290
493
  });
291
494
 
292
- const setup_result = await setup_client.setup();
495
+ await setup_client.admin('setup_initial_admin', {
496
+ username: 'admin',
497
+ password: 'admin123',
498
+ email: 'admin@test.com'
499
+ });
293
500
  setup_client.disconnect();
294
501
 
295
502
  client = joystickdb.client({
296
503
  port: test_port,
297
504
  reconnect: false,
298
- password: setup_result.password
505
+ authentication: {
506
+ username: 'admin',
507
+ password: 'admin123'
508
+ }
299
509
  });
300
510
 
301
511
  await new Promise((resolve) => {
@@ -336,13 +546,20 @@ test('client can perform bulk write operations', async (t) => {
336
546
  setup_client.on('connect', resolve);
337
547
  });
338
548
 
339
- const setup_result = await setup_client.setup();
549
+ await setup_client.admin('setup_initial_admin', {
550
+ username: 'admin',
551
+ password: 'admin123',
552
+ email: 'admin@test.com'
553
+ });
340
554
  setup_client.disconnect();
341
555
 
342
556
  client = joystickdb.client({
343
557
  port: test_port,
344
558
  reconnect: false,
345
- password: setup_result.password
559
+ authentication: {
560
+ username: 'admin',
561
+ password: 'admin123'
562
+ }
346
563
  });
347
564
 
348
565
  await new Promise((resolve) => {
@@ -384,13 +601,20 @@ test('client can perform index operations', async (t) => {
384
601
  setup_client.on('connect', resolve);
385
602
  });
386
603
 
387
- const setup_result = await setup_client.setup();
604
+ await setup_client.admin('setup_initial_admin', {
605
+ username: 'admin',
606
+ password: 'admin123',
607
+ email: 'admin@test.com'
608
+ });
388
609
  setup_client.disconnect();
389
610
 
390
611
  client = joystickdb.client({
391
612
  port: test_port,
392
613
  reconnect: false,
393
- password: setup_result.password
614
+ authentication: {
615
+ username: 'admin',
616
+ password: 'admin123'
617
+ }
394
618
  });
395
619
 
396
620
  await new Promise((resolve) => {
@@ -432,13 +656,20 @@ test('client can perform admin operations', async (t) => {
432
656
  setup_client.on('connect', resolve);
433
657
  });
434
658
 
435
- const setup_result = await setup_client.setup();
659
+ await setup_client.admin('setup_initial_admin', {
660
+ username: 'admin',
661
+ password: 'admin123',
662
+ email: 'admin@test.com'
663
+ });
436
664
  setup_client.disconnect();
437
665
 
438
666
  client = joystickdb.client({
439
667
  port: test_port,
440
668
  reconnect: false,
441
- password: setup_result.password
669
+ authentication: {
670
+ username: 'admin',
671
+ password: 'admin123'
672
+ }
442
673
  });
443
674
 
444
675
  await new Promise((resolve) => {
@@ -528,13 +759,20 @@ test('client queues requests when not authenticated', async (t) => {
528
759
  setup_client.on('connect', resolve);
529
760
  });
530
761
 
531
- const setup_result = await setup_client.setup();
762
+ await setup_client.admin('setup_initial_admin', {
763
+ username: 'admin',
764
+ password: 'admin123',
765
+ email: 'admin@test.com'
766
+ });
532
767
  setup_client.disconnect();
533
768
 
534
769
  client = joystickdb.client({
535
770
  port: test_port,
536
771
  reconnect: false,
537
- password: setup_result.password
772
+ authentication: {
773
+ username: 'admin',
774
+ password: 'admin123'
775
+ }
538
776
  });
539
777
 
540
778
  const insert_promise = client.db('default').collection('queue_test').insert_one({ queued: true });
@@ -584,13 +822,20 @@ test('client can reload server configuration', async (t) => {
584
822
  setup_client.on('connect', resolve);
585
823
  });
586
824
 
587
- const setup_result = await setup_client.setup();
825
+ await setup_client.admin('setup_initial_admin', {
826
+ username: 'admin',
827
+ password: 'admin123',
828
+ email: 'admin@test.com'
829
+ });
588
830
  setup_client.disconnect();
589
831
 
590
832
  client = joystickdb.client({
591
833
  port: test_port,
592
834
  reconnect: false,
593
- password: setup_result.password
835
+ authentication: {
836
+ username: 'admin',
837
+ password: 'admin123'
838
+ }
594
839
  });
595
840
 
596
841
  await new Promise((resolve) => {
@@ -623,13 +868,20 @@ test('client.collection() returns a collection interface', async (t) => {
623
868
  setup_client.on('connect', resolve);
624
869
  });
625
870
 
626
- const setup_result = await setup_client.setup();
871
+ await setup_client.admin('setup_initial_admin', {
872
+ username: 'admin',
873
+ password: 'admin123',
874
+ email: 'admin@test.com'
875
+ });
627
876
  setup_client.disconnect();
628
877
 
629
878
  client = joystickdb.client({
630
879
  port: test_port,
631
880
  reconnect: false,
632
- password: setup_result.password
881
+ authentication: {
882
+ username: 'admin',
883
+ password: 'admin123'
884
+ }
633
885
  });
634
886
 
635
887
  await new Promise((resolve) => {
@@ -671,13 +923,20 @@ test('collection chaining API can perform CRUD operations', async (t) => {
671
923
  setup_client.on('connect', resolve);
672
924
  });
673
925
 
674
- const setup_result = await setup_client.setup();
926
+ await setup_client.admin('setup_initial_admin', {
927
+ username: 'admin',
928
+ password: 'admin123',
929
+ email: 'admin@test.com'
930
+ });
675
931
  setup_client.disconnect();
676
932
 
677
933
  client = joystickdb.client({
678
934
  port: test_port,
679
935
  reconnect: false,
680
- password: setup_result.password
936
+ authentication: {
937
+ username: 'admin',
938
+ password: 'admin123'
939
+ }
681
940
  });
682
941
 
683
942
  await new Promise((resolve) => {
@@ -749,13 +1008,20 @@ test('collection chaining API can perform find operation with multiple results',
749
1008
  setup_client.on('connect', resolve);
750
1009
  });
751
1010
 
752
- const setup_result = await setup_client.setup();
1011
+ await setup_client.admin('setup_initial_admin', {
1012
+ username: 'admin',
1013
+ password: 'admin123',
1014
+ email: 'admin@test.com'
1015
+ });
753
1016
  setup_client.disconnect();
754
1017
 
755
1018
  client = joystickdb.client({
756
1019
  port: test_port,
757
1020
  reconnect: false,
758
- password: setup_result.password
1021
+ authentication: {
1022
+ username: 'admin',
1023
+ password: 'admin123'
1024
+ }
759
1025
  });
760
1026
 
761
1027
  await new Promise((resolve) => {
@@ -798,13 +1064,20 @@ test('collection chaining API can perform bulk write operations', async (t) => {
798
1064
  setup_client.on('connect', resolve);
799
1065
  });
800
1066
 
801
- const setup_result = await setup_client.setup();
1067
+ await setup_client.admin('setup_initial_admin', {
1068
+ username: 'admin',
1069
+ password: 'admin123',
1070
+ email: 'admin@test.com'
1071
+ });
802
1072
  setup_client.disconnect();
803
1073
 
804
1074
  client = joystickdb.client({
805
1075
  port: test_port,
806
1076
  reconnect: false,
807
- password: setup_result.password
1077
+ authentication: {
1078
+ username: 'admin',
1079
+ password: 'admin123'
1080
+ }
808
1081
  });
809
1082
 
810
1083
  await new Promise((resolve) => {
@@ -848,13 +1121,20 @@ test('collection chaining API can perform index operations', async (t) => {
848
1121
  setup_client.on('connect', resolve);
849
1122
  });
850
1123
 
851
- const setup_result = await setup_client.setup();
1124
+ await setup_client.admin('setup_initial_admin', {
1125
+ username: 'admin',
1126
+ password: 'admin123',
1127
+ email: 'admin@test.com'
1128
+ });
852
1129
  setup_client.disconnect();
853
1130
 
854
1131
  client = joystickdb.client({
855
1132
  port: test_port,
856
1133
  reconnect: false,
857
- password: setup_result.password
1134
+ authentication: {
1135
+ username: 'admin',
1136
+ password: 'admin123'
1137
+ }
858
1138
  });
859
1139
 
860
1140
  await new Promise((resolve) => {
@@ -898,13 +1178,20 @@ test('client can perform upsert_index operations', async (t) => {
898
1178
  setup_client.on('connect', resolve);
899
1179
  });
900
1180
 
901
- const setup_result = await setup_client.setup();
1181
+ await setup_client.admin('setup_initial_admin', {
1182
+ username: 'admin',
1183
+ password: 'admin123',
1184
+ email: 'admin@test.com'
1185
+ });
902
1186
  setup_client.disconnect();
903
1187
 
904
1188
  client = joystickdb.client({
905
1189
  port: test_port,
906
1190
  reconnect: false,
907
- password: setup_result.password
1191
+ authentication: {
1192
+ username: 'admin',
1193
+ password: 'admin123'
1194
+ }
908
1195
  });
909
1196
 
910
1197
  await new Promise((resolve) => {
@@ -960,13 +1247,20 @@ test('collection chaining API can perform upsert_index operations', async (t) =>
960
1247
  setup_client.on('connect', resolve);
961
1248
  });
962
1249
 
963
- const setup_result = await setup_client.setup();
1250
+ await setup_client.admin('setup_initial_admin', {
1251
+ username: 'admin',
1252
+ password: 'admin123',
1253
+ email: 'admin@test.com'
1254
+ });
964
1255
  setup_client.disconnect();
965
1256
 
966
1257
  client = joystickdb.client({
967
1258
  port: test_port,
968
1259
  reconnect: false,
969
- password: setup_result.password
1260
+ authentication: {
1261
+ username: 'admin',
1262
+ password: 'admin123'
1263
+ }
970
1264
  });
971
1265
 
972
1266
  await new Promise((resolve) => {
@@ -1024,13 +1318,20 @@ test('upsert_index handles unique constraint violations properly', async (t) =>
1024
1318
  setup_client.on('connect', resolve);
1025
1319
  });
1026
1320
 
1027
- const setup_result = await setup_client.setup();
1321
+ await setup_client.admin('setup_initial_admin', {
1322
+ username: 'admin',
1323
+ password: 'admin123',
1324
+ email: 'admin@test.com'
1325
+ });
1028
1326
  setup_client.disconnect();
1029
1327
 
1030
1328
  client = joystickdb.client({
1031
1329
  port: test_port,
1032
1330
  reconnect: false,
1033
- password: setup_result.password
1331
+ authentication: {
1332
+ username: 'admin',
1333
+ password: 'admin123'
1334
+ }
1034
1335
  });
1035
1336
 
1036
1337
  await new Promise((resolve) => {
@@ -1075,13 +1376,20 @@ test('collection chaining API works with options', async (t) => {
1075
1376
  setup_client.on('connect', resolve);
1076
1377
  });
1077
1378
 
1078
- const setup_result = await setup_client.setup();
1379
+ await setup_client.admin('setup_initial_admin', {
1380
+ username: 'admin',
1381
+ password: 'admin123',
1382
+ email: 'admin@test.com'
1383
+ });
1079
1384
  setup_client.disconnect();
1080
1385
 
1081
1386
  client = joystickdb.client({
1082
1387
  port: test_port,
1083
1388
  reconnect: false,
1084
- password: setup_result.password
1389
+ authentication: {
1390
+ username: 'admin',
1391
+ password: 'admin123'
1392
+ }
1085
1393
  });
1086
1394
 
1087
1395
  await new Promise((resolve) => {
@@ -1148,13 +1456,20 @@ test('both old and new API styles work simultaneously', async (t) => {
1148
1456
  setup_client.on('connect', resolve);
1149
1457
  });
1150
1458
 
1151
- const setup_result = await setup_client.setup();
1459
+ await setup_client.admin('setup_initial_admin', {
1460
+ username: 'admin',
1461
+ password: 'admin123',
1462
+ email: 'admin@test.com'
1463
+ });
1152
1464
  setup_client.disconnect();
1153
1465
 
1154
1466
  client = joystickdb.client({
1155
1467
  port: test_port,
1156
1468
  reconnect: false,
1157
- password: setup_result.password
1469
+ authentication: {
1470
+ username: 'admin',
1471
+ password: 'admin123'
1472
+ }
1158
1473
  });
1159
1474
 
1160
1475
  await new Promise((resolve) => {
@@ -1217,13 +1532,20 @@ test('collection chaining API handles errors properly', async (t) => {
1217
1532
  setup_client.on('connect', resolve);
1218
1533
  });
1219
1534
 
1220
- const setup_result = await setup_client.setup();
1535
+ await setup_client.admin('setup_initial_admin', {
1536
+ username: 'admin',
1537
+ password: 'admin123',
1538
+ email: 'admin@test.com'
1539
+ });
1221
1540
  setup_client.disconnect();
1222
1541
 
1223
1542
  client = joystickdb.client({
1224
1543
  port: test_port,
1225
1544
  reconnect: false,
1226
- password: setup_result.password
1545
+ authentication: {
1546
+ username: 'admin',
1547
+ password: 'admin123'
1548
+ }
1227
1549
  });
1228
1550
 
1229
1551
  await new Promise((resolve) => {
@@ -1272,13 +1594,20 @@ test('client can perform list_databases operation', async (t) => {
1272
1594
  setup_client.on('connect', resolve);
1273
1595
  });
1274
1596
 
1275
- const setup_result = await setup_client.setup();
1597
+ await setup_client.admin('setup_initial_admin', {
1598
+ username: 'admin',
1599
+ password: 'admin123',
1600
+ email: 'admin@test.com'
1601
+ });
1276
1602
  setup_client.disconnect();
1277
1603
 
1278
1604
  client = joystickdb.client({
1279
1605
  port: test_port,
1280
1606
  reconnect: false,
1281
- password: setup_result.password
1607
+ authentication: {
1608
+ username: 'admin',
1609
+ password: 'admin123'
1610
+ }
1282
1611
  });
1283
1612
 
1284
1613
  await new Promise((resolve) => {
@@ -1312,13 +1641,20 @@ test('client list_databases returns default database after data insertion', asyn
1312
1641
  setup_client.on('connect', resolve);
1313
1642
  });
1314
1643
 
1315
- const setup_result = await setup_client.setup();
1644
+ await setup_client.admin('setup_initial_admin', {
1645
+ username: 'admin',
1646
+ password: 'admin123',
1647
+ email: 'admin@test.com'
1648
+ });
1316
1649
  setup_client.disconnect();
1317
1650
 
1318
1651
  client = joystickdb.client({
1319
1652
  port: test_port,
1320
1653
  reconnect: false,
1321
- password: setup_result.password
1654
+ authentication: {
1655
+ username: 'admin',
1656
+ password: 'admin123'
1657
+ }
1322
1658
  });
1323
1659
 
1324
1660
  await new Promise((resolve) => {
@@ -1359,13 +1695,20 @@ test('client list_databases method is properly bound to instance', async (t) =>
1359
1695
  setup_client.on('connect', resolve);
1360
1696
  });
1361
1697
 
1362
- const setup_result = await setup_client.setup();
1698
+ await setup_client.admin('setup_initial_admin', {
1699
+ username: 'admin',
1700
+ password: 'admin123',
1701
+ email: 'admin@test.com'
1702
+ });
1363
1703
  setup_client.disconnect();
1364
1704
 
1365
1705
  client = joystickdb.client({
1366
1706
  port: test_port,
1367
1707
  reconnect: false,
1368
- password: setup_result.password
1708
+ authentication: {
1709
+ username: 'admin',
1710
+ password: 'admin123'
1711
+ }
1369
1712
  });
1370
1713
 
1371
1714
  await new Promise((resolve) => {
@@ -1408,13 +1751,20 @@ test('client can perform delete_many operation via main client method', async (t
1408
1751
  setup_client.on('connect', resolve);
1409
1752
  });
1410
1753
 
1411
- const setup_result = await setup_client.setup();
1754
+ await setup_client.admin('setup_initial_admin', {
1755
+ username: 'admin',
1756
+ password: 'admin123',
1757
+ email: 'admin@test.com'
1758
+ });
1412
1759
  setup_client.disconnect();
1413
1760
 
1414
1761
  client = joystickdb.client({
1415
1762
  port: test_port,
1416
1763
  reconnect: false,
1417
- password: setup_result.password
1764
+ authentication: {
1765
+ username: 'admin',
1766
+ password: 'admin123'
1767
+ }
1418
1768
  });
1419
1769
 
1420
1770
  await new Promise((resolve) => {
@@ -1458,13 +1808,20 @@ test('client can perform delete_many operation via collection chaining', async (
1458
1808
  setup_client.on('connect', resolve);
1459
1809
  });
1460
1810
 
1461
- const setup_result = await setup_client.setup();
1811
+ await setup_client.admin('setup_initial_admin', {
1812
+ username: 'admin',
1813
+ password: 'admin123',
1814
+ email: 'admin@test.com'
1815
+ });
1462
1816
  setup_client.disconnect();
1463
1817
 
1464
1818
  client = joystickdb.client({
1465
1819
  port: test_port,
1466
1820
  reconnect: false,
1467
- password: setup_result.password
1821
+ authentication: {
1822
+ username: 'admin',
1823
+ password: 'admin123'
1824
+ }
1468
1825
  });
1469
1826
 
1470
1827
  await new Promise((resolve) => {
@@ -1511,13 +1868,20 @@ test('client delete_many respects limit option', async (t) => {
1511
1868
  setup_client.on('connect', resolve);
1512
1869
  });
1513
1870
 
1514
- const setup_result = await setup_client.setup();
1871
+ await setup_client.admin('setup_initial_admin', {
1872
+ username: 'admin',
1873
+ password: 'admin123',
1874
+ email: 'admin@test.com'
1875
+ });
1515
1876
  setup_client.disconnect();
1516
1877
 
1517
1878
  client = joystickdb.client({
1518
1879
  port: test_port,
1519
1880
  reconnect: false,
1520
- password: setup_result.password
1881
+ authentication: {
1882
+ username: 'admin',
1883
+ password: 'admin123'
1884
+ }
1521
1885
  });
1522
1886
 
1523
1887
  await new Promise((resolve) => {
@@ -1562,13 +1926,20 @@ test('client delete_many returns zero count when no matches', async (t) => {
1562
1926
  setup_client.on('connect', resolve);
1563
1927
  });
1564
1928
 
1565
- const setup_result = await setup_client.setup();
1929
+ await setup_client.admin('setup_initial_admin', {
1930
+ username: 'admin',
1931
+ password: 'admin123',
1932
+ email: 'admin@test.com'
1933
+ });
1566
1934
  setup_client.disconnect();
1567
1935
 
1568
1936
  client = joystickdb.client({
1569
1937
  port: test_port,
1570
1938
  reconnect: false,
1571
- password: setup_result.password
1939
+ authentication: {
1940
+ username: 'admin',
1941
+ password: 'admin123'
1942
+ }
1572
1943
  });
1573
1944
 
1574
1945
  await new Promise((resolve) => {
@@ -1612,13 +1983,20 @@ test('client delete_many deletes all documents with empty filter', async (t) =>
1612
1983
  setup_client.on('connect', resolve);
1613
1984
  });
1614
1985
 
1615
- const setup_result = await setup_client.setup();
1986
+ await setup_client.admin('setup_initial_admin', {
1987
+ username: 'admin',
1988
+ password: 'admin123',
1989
+ email: 'admin@test.com'
1990
+ });
1616
1991
  setup_client.disconnect();
1617
1992
 
1618
1993
  client = joystickdb.client({
1619
1994
  port: test_port,
1620
1995
  reconnect: false,
1621
- password: setup_result.password
1996
+ authentication: {
1997
+ username: 'admin',
1998
+ password: 'admin123'
1999
+ }
1622
2000
  });
1623
2001
 
1624
2002
  await new Promise((resolve) => {
@@ -1662,13 +2040,20 @@ test('client delete_many handles complex filters', async (t) => {
1662
2040
  setup_client.on('connect', resolve);
1663
2041
  });
1664
2042
 
1665
- const setup_result = await setup_client.setup();
2043
+ await setup_client.admin('setup_initial_admin', {
2044
+ username: 'admin',
2045
+ password: 'admin123',
2046
+ email: 'admin@test.com'
2047
+ });
1666
2048
  setup_client.disconnect();
1667
2049
 
1668
2050
  client = joystickdb.client({
1669
2051
  port: test_port,
1670
2052
  reconnect: false,
1671
- password: setup_result.password
2053
+ authentication: {
2054
+ username: 'admin',
2055
+ password: 'admin123'
2056
+ }
1672
2057
  });
1673
2058
 
1674
2059
  await new Promise((resolve) => {
@@ -1714,13 +2099,20 @@ test('client delete_many method exists on collection interface', async (t) => {
1714
2099
  setup_client.on('connect', resolve);
1715
2100
  });
1716
2101
 
1717
- const setup_result = await setup_client.setup();
2102
+ await setup_client.admin('setup_initial_admin', {
2103
+ username: 'admin',
2104
+ password: 'admin123',
2105
+ email: 'admin@test.com'
2106
+ });
1718
2107
  setup_client.disconnect();
1719
2108
 
1720
2109
  client = joystickdb.client({
1721
2110
  port: test_port,
1722
2111
  reconnect: false,
1723
- password: setup_result.password
2112
+ authentication: {
2113
+ username: 'admin',
2114
+ password: 'admin123'
2115
+ }
1724
2116
  });
1725
2117
 
1726
2118
  await new Promise((resolve) => {
@@ -1753,13 +2145,20 @@ test('client delete_many handles error scenarios properly', async (t) => {
1753
2145
  setup_client.on('connect', resolve);
1754
2146
  });
1755
2147
 
1756
- const setup_result = await setup_client.setup();
2148
+ await setup_client.admin('setup_initial_admin', {
2149
+ username: 'admin',
2150
+ password: 'admin123',
2151
+ email: 'admin@test.com'
2152
+ });
1757
2153
  setup_client.disconnect();
1758
2154
 
1759
2155
  client = joystickdb.client({
1760
2156
  port: test_port,
1761
2157
  reconnect: false,
1762
- password: setup_result.password
2158
+ authentication: {
2159
+ username: 'admin',
2160
+ password: 'admin123'
2161
+ }
1763
2162
  });
1764
2163
 
1765
2164
  await new Promise((resolve) => {