soul-cli 0.6.0 → 0.7.0
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.
- package/.all-contributorsrc +73 -0
- package/.editorconfig +26 -0
- package/.env.sample +9 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +24 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/npm-publish.yml +23 -0
- package/.husky/pre-commit +5 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +21 -0
- package/README.md +186 -1
- package/docs/api/root-examples.md +41 -0
- package/docs/api/rows-examples.md +225 -0
- package/docs/api/tables-examples.md +217 -0
- package/docs/api-examples.md +62 -0
- package/docs/extensions-examples.md +167 -0
- package/docs/logo.png +0 -0
- package/docs/soul-studio.png +0 -0
- package/docs/ws/rows-examples.md +122 -0
- package/docs/ws-examples.md +42 -0
- package/package.json +17 -2
- package/src/cli.js +59 -1
- package/src/commands.js +22 -0
- package/src/config/index.js +48 -3
- package/src/constants/api.js +26 -0
- package/src/constants/auth.js +5 -0
- package/src/constants/index.js +13 -0
- package/src/constants/messages.js +41 -0
- package/src/constants/roles.js +3 -0
- package/src/constants/tables.js +47 -0
- package/src/controllers/auth/common.js +16 -0
- package/src/controllers/auth/index.js +5 -0
- package/src/controllers/auth/tables.js +96 -0
- package/src/controllers/auth/token.js +243 -0
- package/src/controllers/auth/user.js +394 -0
- package/src/controllers/auth.test.js +372 -0
- package/src/controllers/rows.js +30 -31
- package/src/controllers/rows.test.js +209 -18
- package/src/controllers/tables.test.js +58 -28
- package/src/db/schema.js +118 -0
- package/src/index.js +32 -7
- package/src/middlewares/api.js +79 -0
- package/src/middlewares/auth.js +85 -0
- package/src/middlewares/broadcast.js +1 -1
- package/src/middlewares/validation.js +3 -2
- package/src/routes/auth.js +29 -0
- package/src/routes/rows.js +17 -5
- package/src/routes/tables.js +26 -4
- package/src/schemas/auth.js +67 -0
- package/src/schemas/index.js +6 -1
- package/src/schemas/rows.js +20 -0
- package/src/schemas/tables.js +18 -2
- package/src/server.js +3 -2
- package/src/services/authService.js +78 -0
- package/src/services/index.js +2 -1
- package/src/services/rowService.js +36 -7
- package/src/services/tableService.js +127 -1
- package/src/swagger/index.js +67 -0
- package/src/swagger/swagger.json +292 -60
- package/src/tests/index.js +4 -5
- package/src/tests/testData.js +72 -27
- package/src/utils/index.js +78 -0
- /package/{src/services/.gitkeep → docs/extensions/api-examples.js} +0 -0
package/src/swagger/swagger.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"swagger": "2.0",
|
|
3
3
|
"info": {
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"title": "Soul API",
|
|
6
6
|
"description": "API Documentation for <b>Soul</b>, a SQLite REST and realtime server. "
|
|
7
7
|
},
|
|
@@ -19,19 +19,16 @@
|
|
|
19
19
|
{
|
|
20
20
|
"name": "Rows",
|
|
21
21
|
"description": "Rows endpoints"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "Auth",
|
|
25
|
+
"description": "Auth endpoints"
|
|
22
26
|
}
|
|
23
27
|
],
|
|
24
|
-
"schemes": [
|
|
25
|
-
"http",
|
|
26
|
-
"https"
|
|
27
|
-
],
|
|
28
|
+
"schemes": ["http", "https"],
|
|
28
29
|
"securityDefinitions": {},
|
|
29
|
-
"consumes": [
|
|
30
|
-
|
|
31
|
-
],
|
|
32
|
-
"produces": [
|
|
33
|
-
"application/json"
|
|
34
|
-
],
|
|
30
|
+
"consumes": ["application/json"],
|
|
31
|
+
"produces": ["application/json"],
|
|
35
32
|
"paths": {
|
|
36
33
|
"/health": {
|
|
37
34
|
"get": {
|
|
@@ -46,9 +43,7 @@
|
|
|
46
43
|
},
|
|
47
44
|
"/api/": {
|
|
48
45
|
"get": {
|
|
49
|
-
"tags": [
|
|
50
|
-
"Root"
|
|
51
|
-
],
|
|
46
|
+
"tags": ["Root"],
|
|
52
47
|
"summary": "Timestamp",
|
|
53
48
|
"description": "Endpoint to return server timestamp",
|
|
54
49
|
"parameters": [],
|
|
@@ -61,9 +56,7 @@
|
|
|
61
56
|
},
|
|
62
57
|
"/api/transaction": {
|
|
63
58
|
"post": {
|
|
64
|
-
"tags": [
|
|
65
|
-
"Root"
|
|
66
|
-
],
|
|
59
|
+
"tags": ["Root"],
|
|
67
60
|
"summary": "Transaction",
|
|
68
61
|
"description": "Endpoint to run any transaction, e.g. [{ \"query\": \"\" }, { \"statement\": \"\", \"values\": {} }, { \"query\": \"\" }]",
|
|
69
62
|
"parameters": [
|
|
@@ -88,9 +81,7 @@
|
|
|
88
81
|
},
|
|
89
82
|
"/api/tables/": {
|
|
90
83
|
"get": {
|
|
91
|
-
"tags": [
|
|
92
|
-
"Tables"
|
|
93
|
-
],
|
|
84
|
+
"tags": ["Tables"],
|
|
94
85
|
"summary": "List Tables",
|
|
95
86
|
"description": "Endpoint to list all tables",
|
|
96
87
|
"parameters": [
|
|
@@ -115,13 +106,17 @@
|
|
|
115
106
|
},
|
|
116
107
|
"400": {
|
|
117
108
|
"description": "Bad Request"
|
|
109
|
+
},
|
|
110
|
+
"401": {
|
|
111
|
+
"description": "Unauthorized"
|
|
112
|
+
},
|
|
113
|
+
"403": {
|
|
114
|
+
"description": "Forbidden"
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
118
|
"post": {
|
|
122
|
-
"tags": [
|
|
123
|
-
"Tables"
|
|
124
|
-
],
|
|
119
|
+
"tags": ["Tables"],
|
|
125
120
|
"summary": "Create Table",
|
|
126
121
|
"description": "Endpoint to create a table",
|
|
127
122
|
"parameters": [
|
|
@@ -146,15 +141,22 @@
|
|
|
146
141
|
"schema": {
|
|
147
142
|
"$ref": "#/definitions/CreateTableErrorResponse"
|
|
148
143
|
}
|
|
144
|
+
},
|
|
145
|
+
"401": {
|
|
146
|
+
"description": "Unauthorized"
|
|
147
|
+
},
|
|
148
|
+
"403": {
|
|
149
|
+
"description": "Forbidden"
|
|
150
|
+
},
|
|
151
|
+
"409": {
|
|
152
|
+
"description": "Conflict"
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
},
|
|
153
157
|
"/api/tables/{name}": {
|
|
154
158
|
"get": {
|
|
155
|
-
"tags": [
|
|
156
|
-
"Tables"
|
|
157
|
-
],
|
|
159
|
+
"tags": ["Tables"],
|
|
158
160
|
"summary": "Get Table Schema",
|
|
159
161
|
"description": "Endpoint to get the schema of a table",
|
|
160
162
|
"parameters": [
|
|
@@ -172,13 +174,17 @@
|
|
|
172
174
|
},
|
|
173
175
|
"400": {
|
|
174
176
|
"description": "Bad Request"
|
|
177
|
+
},
|
|
178
|
+
"401": {
|
|
179
|
+
"description": "Unauthorized"
|
|
180
|
+
},
|
|
181
|
+
"403": {
|
|
182
|
+
"description": "Forbidden"
|
|
175
183
|
}
|
|
176
184
|
}
|
|
177
185
|
},
|
|
178
186
|
"delete": {
|
|
179
|
-
"tags": [
|
|
180
|
-
"Tables"
|
|
181
|
-
],
|
|
187
|
+
"tags": ["Tables"],
|
|
182
188
|
"summary": "Delete Table",
|
|
183
189
|
"description": "Endpoint to delete a table",
|
|
184
190
|
"parameters": [
|
|
@@ -196,15 +202,19 @@
|
|
|
196
202
|
},
|
|
197
203
|
"400": {
|
|
198
204
|
"description": "Bad Request"
|
|
205
|
+
},
|
|
206
|
+
"401": {
|
|
207
|
+
"description": "Unauthorized"
|
|
208
|
+
},
|
|
209
|
+
"403": {
|
|
210
|
+
"description": "Forbidden"
|
|
199
211
|
}
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
},
|
|
203
215
|
"/api/tables/{name}/rows": {
|
|
204
216
|
"get": {
|
|
205
|
-
"tags": [
|
|
206
|
-
"Rows"
|
|
207
|
-
],
|
|
217
|
+
"tags": ["Rows"],
|
|
208
218
|
"summary": "List Rows",
|
|
209
219
|
"description": "Endpoint to list rows of a table.",
|
|
210
220
|
"parameters": [
|
|
@@ -260,18 +270,19 @@
|
|
|
260
270
|
}
|
|
261
271
|
],
|
|
262
272
|
"responses": {
|
|
263
|
-
"200": {
|
|
264
|
-
"description": "OK"
|
|
265
|
-
},
|
|
266
273
|
"400": {
|
|
267
274
|
"description": "Bad Request"
|
|
275
|
+
},
|
|
276
|
+
"401": {
|
|
277
|
+
"description": "Unauthorized"
|
|
278
|
+
},
|
|
279
|
+
"403": {
|
|
280
|
+
"description": "Forbidden"
|
|
268
281
|
}
|
|
269
282
|
}
|
|
270
283
|
},
|
|
271
284
|
"post": {
|
|
272
|
-
"tags": [
|
|
273
|
-
"Rows"
|
|
274
|
-
],
|
|
285
|
+
"tags": ["Rows"],
|
|
275
286
|
"summary": "Insert Row",
|
|
276
287
|
"description": "Insert a new row in a table",
|
|
277
288
|
"parameters": [
|
|
@@ -303,15 +314,19 @@
|
|
|
303
314
|
"schema": {
|
|
304
315
|
"$ref": "#/definitions/InsertRowErrorResponse"
|
|
305
316
|
}
|
|
317
|
+
},
|
|
318
|
+
"401": {
|
|
319
|
+
"description": "Unauthorized"
|
|
320
|
+
},
|
|
321
|
+
"403": {
|
|
322
|
+
"description": "Forbidden"
|
|
306
323
|
}
|
|
307
324
|
}
|
|
308
325
|
}
|
|
309
326
|
},
|
|
310
327
|
"/api/tables/{name}/rows/{pks}": {
|
|
311
328
|
"get": {
|
|
312
|
-
"tags": [
|
|
313
|
-
"Rows"
|
|
314
|
-
],
|
|
329
|
+
"tags": ["Rows"],
|
|
315
330
|
"summary": "Retrieve Row",
|
|
316
331
|
"description": "Retrieve a row by primary key",
|
|
317
332
|
"parameters": [
|
|
@@ -352,21 +367,22 @@
|
|
|
352
367
|
}
|
|
353
368
|
],
|
|
354
369
|
"responses": {
|
|
355
|
-
"200": {
|
|
356
|
-
"description": "OK"
|
|
357
|
-
},
|
|
358
370
|
"400": {
|
|
359
371
|
"description": "Bad Request"
|
|
360
372
|
},
|
|
373
|
+
"401": {
|
|
374
|
+
"description": "Unauthorized"
|
|
375
|
+
},
|
|
376
|
+
"403": {
|
|
377
|
+
"description": "Forbidden"
|
|
378
|
+
},
|
|
361
379
|
"404": {
|
|
362
380
|
"description": "Not Found"
|
|
363
381
|
}
|
|
364
382
|
}
|
|
365
383
|
},
|
|
366
384
|
"put": {
|
|
367
|
-
"tags": [
|
|
368
|
-
"Rows"
|
|
369
|
-
],
|
|
385
|
+
"tags": ["Rows"],
|
|
370
386
|
"summary": "Update Row",
|
|
371
387
|
"description": "Update a row by primary key",
|
|
372
388
|
"parameters": [
|
|
@@ -426,13 +442,17 @@
|
|
|
426
442
|
},
|
|
427
443
|
"400": {
|
|
428
444
|
"description": "Bad Request"
|
|
445
|
+
},
|
|
446
|
+
"401": {
|
|
447
|
+
"description": "Unauthorized"
|
|
448
|
+
},
|
|
449
|
+
"403": {
|
|
450
|
+
"description": "Forbidden"
|
|
429
451
|
}
|
|
430
452
|
}
|
|
431
453
|
},
|
|
432
454
|
"delete": {
|
|
433
|
-
"tags": [
|
|
434
|
-
"Rows"
|
|
435
|
-
],
|
|
455
|
+
"tags": ["Rows"],
|
|
436
456
|
"summary": "Delete Row",
|
|
437
457
|
"description": "Delete a row by primary key",
|
|
438
458
|
"parameters": [
|
|
@@ -465,11 +485,56 @@
|
|
|
465
485
|
"400": {
|
|
466
486
|
"description": "Bad Request"
|
|
467
487
|
},
|
|
488
|
+
"401": {
|
|
489
|
+
"description": "Unauthorized"
|
|
490
|
+
},
|
|
491
|
+
"403": {
|
|
492
|
+
"description": "Forbidden"
|
|
493
|
+
},
|
|
468
494
|
"404": {
|
|
469
495
|
"description": "Not Found"
|
|
470
496
|
}
|
|
471
497
|
}
|
|
472
498
|
}
|
|
499
|
+
},
|
|
500
|
+
"/api/auth/token/obtain": {
|
|
501
|
+
"post": {
|
|
502
|
+
"description": "",
|
|
503
|
+
"parameters": [],
|
|
504
|
+
"responses": {
|
|
505
|
+
"400": {
|
|
506
|
+
"description": "Bad Request"
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
"/api/auth/token/refresh": {
|
|
512
|
+
"get": {
|
|
513
|
+
"description": "",
|
|
514
|
+
"parameters": [],
|
|
515
|
+
"responses": {
|
|
516
|
+
"400": {
|
|
517
|
+
"description": "Bad Request"
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
"/api/auth/change-password": {
|
|
523
|
+
"put": {
|
|
524
|
+
"description": "",
|
|
525
|
+
"parameters": [],
|
|
526
|
+
"responses": {
|
|
527
|
+
"400": {
|
|
528
|
+
"description": "Bad Request"
|
|
529
|
+
},
|
|
530
|
+
"401": {
|
|
531
|
+
"description": "Unauthorized"
|
|
532
|
+
},
|
|
533
|
+
"403": {
|
|
534
|
+
"description": "Forbidden"
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
473
538
|
}
|
|
474
539
|
},
|
|
475
540
|
"definitions": {
|
|
@@ -718,11 +783,7 @@
|
|
|
718
783
|
"properties": {
|
|
719
784
|
"pks": {
|
|
720
785
|
"type": "array",
|
|
721
|
-
"example": [
|
|
722
|
-
1,
|
|
723
|
-
2,
|
|
724
|
-
3
|
|
725
|
-
],
|
|
786
|
+
"example": [1, 2, 3],
|
|
726
787
|
"items": {
|
|
727
788
|
"type": "number"
|
|
728
789
|
}
|
|
@@ -740,11 +801,7 @@
|
|
|
740
801
|
"properties": {
|
|
741
802
|
"pks": {
|
|
742
803
|
"type": "array",
|
|
743
|
-
"example": [
|
|
744
|
-
1,
|
|
745
|
-
2,
|
|
746
|
-
3
|
|
747
|
-
],
|
|
804
|
+
"example": [1, 2, 3],
|
|
748
805
|
"items": {
|
|
749
806
|
"type": "number"
|
|
750
807
|
}
|
|
@@ -753,6 +810,181 @@
|
|
|
753
810
|
},
|
|
754
811
|
"TransactionRequestBody": {
|
|
755
812
|
"$ref": "#/definitions/Transaction"
|
|
813
|
+
},
|
|
814
|
+
"ObtainAccessTokenRequestBody": {
|
|
815
|
+
"type": "object",
|
|
816
|
+
"properties": {
|
|
817
|
+
"fields": {
|
|
818
|
+
"type": "object",
|
|
819
|
+
"properties": {
|
|
820
|
+
"username": {
|
|
821
|
+
"type": "string",
|
|
822
|
+
"example": "@john"
|
|
823
|
+
},
|
|
824
|
+
"password": {
|
|
825
|
+
"type": "string",
|
|
826
|
+
"example": "Ak22#cPM33@v*#"
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
"ObtainAccessTokenSuccessResponse": {
|
|
833
|
+
"type": "object",
|
|
834
|
+
"properties": {
|
|
835
|
+
"message": {
|
|
836
|
+
"type": "string",
|
|
837
|
+
"example": "Success"
|
|
838
|
+
},
|
|
839
|
+
"data": {
|
|
840
|
+
"type": "object",
|
|
841
|
+
"properties": {
|
|
842
|
+
"userId": {
|
|
843
|
+
"type": "number",
|
|
844
|
+
"example": 1
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
"InvalidCredentialErrorResponse": {
|
|
851
|
+
"type": "object",
|
|
852
|
+
"properties": {
|
|
853
|
+
"message": {
|
|
854
|
+
"type": "string",
|
|
855
|
+
"example": "Invalid username or password"
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
"UserRegisterationRequestBody": {
|
|
860
|
+
"type": "object",
|
|
861
|
+
"properties": {
|
|
862
|
+
"fields": {
|
|
863
|
+
"type": "object",
|
|
864
|
+
"properties": {
|
|
865
|
+
"username": {
|
|
866
|
+
"type": "string",
|
|
867
|
+
"example": "@john"
|
|
868
|
+
},
|
|
869
|
+
"password": {
|
|
870
|
+
"type": "string",
|
|
871
|
+
"example": "Ak22#cPM33@v*#"
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
"WeakPasswordErrorResponse": {
|
|
878
|
+
"type": "object",
|
|
879
|
+
"properties": {
|
|
880
|
+
"message": {
|
|
881
|
+
"type": "string",
|
|
882
|
+
"example": "This password is weak, please use another password"
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
"UsernameTakenErrorResponse": {
|
|
887
|
+
"type": "object",
|
|
888
|
+
"properties": {
|
|
889
|
+
"message": {
|
|
890
|
+
"type": "string",
|
|
891
|
+
"example": "This username is taken"
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
},
|
|
895
|
+
"DefaultRoleNotCreatedErrorResponse": {
|
|
896
|
+
"type": "object",
|
|
897
|
+
"properties": {
|
|
898
|
+
"message": {
|
|
899
|
+
"type": "string",
|
|
900
|
+
"example": "Please restart soul so a default role can be created"
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
"UserNotFoundErrorResponse": {
|
|
905
|
+
"type": "object",
|
|
906
|
+
"properties": {
|
|
907
|
+
"message": {
|
|
908
|
+
"type": "string",
|
|
909
|
+
"example": "User not found"
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
"InvalidRefreshTokenErrorResponse": {
|
|
914
|
+
"type": "object",
|
|
915
|
+
"properties": {
|
|
916
|
+
"message": {
|
|
917
|
+
"type": "string",
|
|
918
|
+
"example": "Invalid refresh token"
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
"ChangePasswordRequestBody": {
|
|
923
|
+
"type": "object",
|
|
924
|
+
"properties": {
|
|
925
|
+
"fields": {
|
|
926
|
+
"type": "object",
|
|
927
|
+
"properties": {
|
|
928
|
+
"currentPassword": {
|
|
929
|
+
"type": "string",
|
|
930
|
+
"example": "Ak22#cPM33@v*#"
|
|
931
|
+
},
|
|
932
|
+
"newPassword": {
|
|
933
|
+
"type": "string",
|
|
934
|
+
"example": "hKB33o@3245CD$"
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
"ChangePasswordSuccessResponse": {
|
|
941
|
+
"type": "object",
|
|
942
|
+
"properties": {
|
|
943
|
+
"message": {
|
|
944
|
+
"type": "string",
|
|
945
|
+
"example": "Password updated successfully"
|
|
946
|
+
},
|
|
947
|
+
"data": {
|
|
948
|
+
"type": "object",
|
|
949
|
+
"properties": {
|
|
950
|
+
"id": {
|
|
951
|
+
"type": "number",
|
|
952
|
+
"example": 1
|
|
953
|
+
},
|
|
954
|
+
"username": {
|
|
955
|
+
"type": "string",
|
|
956
|
+
"example": "@john"
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
"RefreshAccessTokenSuccessResponse": {
|
|
963
|
+
"type": "object",
|
|
964
|
+
"properties": {
|
|
965
|
+
"message": {
|
|
966
|
+
"type": "string",
|
|
967
|
+
"example": "Success"
|
|
968
|
+
},
|
|
969
|
+
"data": {
|
|
970
|
+
"type": "object",
|
|
971
|
+
"properties": {
|
|
972
|
+
"userId": {
|
|
973
|
+
"type": "number",
|
|
974
|
+
"example": 1
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
"InvalidPasswordErrorResponse": {
|
|
981
|
+
"type": "object",
|
|
982
|
+
"properties": {
|
|
983
|
+
"message": {
|
|
984
|
+
"type": "string",
|
|
985
|
+
"example": "Invalid password"
|
|
986
|
+
}
|
|
987
|
+
}
|
|
756
988
|
}
|
|
757
989
|
}
|
|
758
990
|
}
|
package/src/tests/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const { unlink } = require('fs/promises');
|
|
3
|
-
|
|
4
3
|
const db = require('../db/index');
|
|
5
4
|
const { testNames } = require('./testData');
|
|
6
5
|
|
|
@@ -18,7 +17,7 @@ const dropTestDatabase = async (path = 'test.db') => {
|
|
|
18
17
|
|
|
19
18
|
if (fs.existsSync(path + '-wal')) {
|
|
20
19
|
try {
|
|
21
|
-
await Promise.allSettled(unlink(path + '-wal'), unlink(path + '-shm'));
|
|
20
|
+
await Promise.allSettled([unlink(path + '-wal'), unlink(path + '-shm')]);
|
|
22
21
|
} catch (error) {
|
|
23
22
|
console.error('there was an error:', error);
|
|
24
23
|
}
|
|
@@ -27,17 +26,17 @@ const dropTestDatabase = async (path = 'test.db') => {
|
|
|
27
26
|
|
|
28
27
|
const createTestTable = (table = 'users') => {
|
|
29
28
|
db.prepare(
|
|
30
|
-
`CREATE TABLE ${table} (id INTEGER PRIMARY KEY, firstName TEXT, lastName TEXT, email TEXT, username TEXT)
|
|
29
|
+
`CREATE TABLE ${table} (id INTEGER PRIMARY KEY, firstName TEXT, lastName TEXT, email TEXT, username TEXT, createdAt TEXT)`,
|
|
31
30
|
).run();
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
const insertIntoTestTable = (table = 'users') => {
|
|
35
34
|
const statement = db.prepare(
|
|
36
|
-
`INSERT INTO ${table} (firstName, lastName) VALUES (?, ?)
|
|
35
|
+
`INSERT INTO ${table} (firstName, lastName, createdAt) VALUES (?, ?, ?)`,
|
|
37
36
|
);
|
|
38
37
|
|
|
39
38
|
for (const user of testNames) {
|
|
40
|
-
statement.run(user.firstName, user.lastName);
|
|
39
|
+
statement.run(user.firstName, user.lastName, user.createdAt);
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
42
|
|
package/src/tests/testData.js
CHANGED
|
@@ -1,30 +1,75 @@
|
|
|
1
1
|
const testNames = [
|
|
2
|
-
{ firstName: 'Emily', lastName: 'William' },
|
|
3
|
-
{ firstName: 'Michael', lastName: 'Lee' },
|
|
4
|
-
{ firstName: 'Sarah', lastName: 'Johnson' },
|
|
5
|
-
{ firstName: 'David', lastName: 'Chen' },
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{ firstName: '
|
|
12
|
-
{ firstName: '
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{ firstName: '
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
{ firstName: 'Emily', lastName: 'William', createdAt: '2008-01-08 00:00:00' },
|
|
3
|
+
{ firstName: 'Michael', lastName: 'Lee', createdAt: '2009-01-08 00:00:00' },
|
|
4
|
+
{ firstName: 'Sarah', lastName: 'Johnson', createdAt: '2010-01-08 00:00:00' },
|
|
5
|
+
{ firstName: 'David', lastName: 'Chen', createdAt: '2011-01-08 00:00:00' },
|
|
6
|
+
{
|
|
7
|
+
firstName: 'Olivia',
|
|
8
|
+
lastName: 'William',
|
|
9
|
+
createdAt: '2012-01-08 00:00:00',
|
|
10
|
+
},
|
|
11
|
+
{ firstName: 'William', lastName: 'Kim', createdAt: '2013-01-08 00:00:00' },
|
|
12
|
+
{ firstName: 'Sophia', lastName: 'Singh', createdAt: '2013-02-08 00:00:00' },
|
|
13
|
+
{
|
|
14
|
+
firstName: 'James',
|
|
15
|
+
lastName: 'Rodriguez',
|
|
16
|
+
createdAt: '2013-03-08 00:00:00',
|
|
17
|
+
},
|
|
18
|
+
{ firstName: 'Ava', lastName: 'Patel', createdAt: '2013-01-04 00:00:00' },
|
|
19
|
+
{
|
|
20
|
+
firstName: 'Benjamin',
|
|
21
|
+
lastName: 'Garcia',
|
|
22
|
+
createdAt: '2015-01-08 00:00:00',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
firstName: 'Isabella',
|
|
26
|
+
lastName: 'Nguyen',
|
|
27
|
+
createdAt: '2014-01-08 00:00:00',
|
|
28
|
+
},
|
|
29
|
+
{ firstName: 'Ethan', lastName: 'Lee', createdAt: '2016-01-08 00:00:00' },
|
|
30
|
+
{ firstName: 'Mia', lastName: 'Wilson', createdAt: '2017-01-08 00:00:00' },
|
|
31
|
+
{
|
|
32
|
+
firstName: 'Alexander',
|
|
33
|
+
lastName: 'William',
|
|
34
|
+
createdAt: '2018-01-08 00:00:00',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
firstName: 'Charlotte',
|
|
38
|
+
lastName: 'Hernandez',
|
|
39
|
+
createdAt: '2019-01-08 00:00:00',
|
|
40
|
+
},
|
|
41
|
+
{ firstName: 'Liam', lastName: 'Gonzalez', createdAt: '2020-01-08 00:00:00' },
|
|
42
|
+
{ firstName: 'Emma', lastName: 'Gomez', createdAt: '2021-01-08 00:00:00' },
|
|
43
|
+
{ firstName: 'Noah', lastName: 'Perez', createdAt: '2021-01-08 00:00:00' },
|
|
44
|
+
{ firstName: 'Avery', lastName: 'Ramirez', createdAt: '2023-02-08 00:00:00' },
|
|
45
|
+
{ firstName: 'Jacob', lastName: 'Turner', createdAt: '2023-03-08 00:00:00' },
|
|
46
|
+
{
|
|
47
|
+
firstName: 'Abigail',
|
|
48
|
+
lastName: 'Williams',
|
|
49
|
+
createdAt: '2023-02-10 00:00:00',
|
|
50
|
+
},
|
|
51
|
+
{ firstName: 'Elijah', lastName: 'Hall', createdAt: '2023-04-02 00:00:00' },
|
|
52
|
+
{ firstName: 'Mila', lastName: 'Flores', createdAt: '2023-05-13 00:00:00' },
|
|
53
|
+
{
|
|
54
|
+
firstName: 'Evelyn',
|
|
55
|
+
lastName: 'Morales',
|
|
56
|
+
createdAt: '2023-06-05 00:00:00',
|
|
57
|
+
},
|
|
58
|
+
{ firstName: 'Logan', lastName: 'Collins', createdAt: '2023-06-07 00:00:00' },
|
|
59
|
+
{ firstName: null, lastName: 'Flores', createdAt: '2023-06-09 00:00:00' },
|
|
28
60
|
];
|
|
29
61
|
|
|
30
|
-
|
|
62
|
+
const testData = {
|
|
63
|
+
strongPassword: 'HeK34#C44DMJ',
|
|
64
|
+
strongPassword2: 'Mk22#c9@Cv!K',
|
|
65
|
+
weakPassword: '12345678',
|
|
66
|
+
invalidUsername: 'invalid_username',
|
|
67
|
+
invalidPassword: 'invalid_password',
|
|
68
|
+
users: {
|
|
69
|
+
user1: { username: 'Jane' },
|
|
70
|
+
user2: { username: 'Mike' },
|
|
71
|
+
user3: { username: 'John' },
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
module.exports = { testNames, testData };
|