@oino-ts/db 0.6.1 → 0.7.1

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.
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { expect, test } from "bun:test";
8
8
 
9
- import { OINODbApi, OINODbApiParams, OINOContentType, OINODataRow, OINODbDataField, OINOStringDataField, OINODb, OINODbFactory, OINODbParams, OINODbMemoryDataSet, OINODbModelSet, OINOBenchmark, OINOConsoleLog, OINODbSqlFilter, OINODbConfig, OINODbSqlOrder, OINOLogLevel, OINOLog, OINODbSqlLimit, OINODbApiResult, OINODbSqlComparison, OINONumberDataField, OINODatetimeDataField, OINODbApiRequestParams, OINODbHtmlTemplate } from "./index.js";
9
+ import { OINODbApi, OINODbApiParams, OINOContentType, OINODataRow, OINODbDataField, OINOStringDataField, OINODb, OINODbFactory, OINODbParams, OINODbMemoryDataSet, OINODbModelSet, OINOBenchmark, OINOConsoleLog, OINODbSqlFilter, OINODbConfig, OINODbSqlOrder, OINOLogLevel, OINOLog, OINODbSqlLimit, OINODbApiResult, OINODbSqlComparison, OINONumberDataField, OINODatetimeDataField, OINODbApiRequestParams, OINODbHtmlTemplate, OINODbParser } from "./index.js";
10
10
 
11
11
  import { OINODbBunSqlite } from "@oino-ts/db-bunsqlite"
12
12
  import { OINODbPostgresql } from "@oino-ts/db-postgresql"
@@ -28,14 +28,14 @@ type OINOTestParams = {
28
28
  putRow: OINODataRow
29
29
  }
30
30
 
31
- const dbs:OINODbParams[] = [
31
+ const DATABASES:OINODbParams[] = [
32
32
  { type: "OINODbBunSqlite", url:"file://./localDb/northwind.sqlite", database: "Northwind" },
33
33
  { type: "OINODbPostgresql", url: "localhost", database: "Northwind", port:5432, user: "node", password: OINODB_POSTGRESQL_TOKEN },
34
34
  { type: "OINODbMariadb", url: "127.0.0.1", database: "Northwind", port:6543, user: "node", password: OINODB_MARIADB_TOKEN },
35
35
  { type: "OINODbMsSql", url: OINOCLOUD_MSSQL_TEST_SRV, database: "Northwind", port:1433, user: OINOCLOUD_MSSQL_TEST_USER, password: OINOCLOUD_MSSQL_TEST_PWD }
36
36
  ]
37
37
 
38
- const api_tests:OINOTestParams[] = [
38
+ const API_TESTS:OINOTestParams[] = [
39
39
  {
40
40
  name: "API 1",
41
41
  apiParams: { apiName: "Orders", tableName: "Orders" },
@@ -75,7 +75,7 @@ const api_tests:OINOTestParams[] = [
75
75
 
76
76
  ]
77
77
 
78
- const owasp_tests:OINOTestParams[] = [
78
+ const OWASP_TESTS:OINOTestParams[] = [
79
79
  {
80
80
  name: "OWASP 1",
81
81
  apiParams: { apiName: "Products", tableName: "Products", failOnOversizedValues: true },
@@ -105,6 +105,25 @@ const owasp_tests:OINOTestParams[] = [
105
105
  }
106
106
  ]
107
107
 
108
+ const API_CROSSCHECKS:string[] = [
109
+ "[HTTP GET] select *: GET JSON 1",
110
+ "[HTTP GET] select * with template: GET HTML 1",
111
+ "[HTTP POST] insert: GET JSON 1",
112
+ "[HTTP POST] insert: GET CSV 1",
113
+ "[HTTP PUT] update JSON: GET JSON 1",
114
+ "[HTTP PUT] update CSV: GET CSV 1",
115
+ "[HTTP PUT] update FORMDATA: GET FORMDATA 1",
116
+ "[HTTP PUT] update URLENCODE: GET URLENCODE 1",
117
+ "[BATCH UPDATE] reversed values: GET reversed data 1",
118
+ "[BATCH UPDATE] reversed values: GET restored data 1"
119
+ ]
120
+
121
+ const OWASP_CROSSCHECKS:string[] = [
122
+ "[OWASP POST] POST: POST JSON 1",
123
+ "[OWASP PUT] PUT: OWASP PUT RESULT 1"
124
+ ]
125
+
126
+
108
127
  Math.random()
109
128
 
110
129
  OINOLog.setLogger(new OINOConsoleLog(OINOLogLevel.error))
@@ -153,7 +172,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
153
172
  const wrong_pwd_params:OINODbParams = Object.assign({}, dbParams)
154
173
  wrong_pwd_params.password = "WRONG_PASSWORD"
155
174
  const wrong_pwd_db:OINODb = await OINODbFactory.createDb( wrong_pwd_params, false, false )
156
- test(target_name + target_db + target_table + target_group + " connection error", async () => {
175
+ await test(target_name + target_db + target_table + target_group + " connection error", async () => {
157
176
  expect(wrong_pwd_db).toBeDefined()
158
177
 
159
178
  const connect_res = await wrong_pwd_db.connect()
@@ -164,13 +183,14 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
164
183
 
165
184
  // const db:OINODb = await OINODbFactory.createDb( dbParams )
166
185
  const db:OINODb = await OINODbFactory.createDb( dbParams )
167
- test(target_name + target_db + target_table + target_group + " connection success", async () => {
186
+ await test(target_name + target_db + target_table + target_group + " connection success", async () => {
168
187
  expect(db).toBeDefined()
169
188
  expect(db.isConnected).toBe(true)
170
189
  expect(db.isValidated).toBe(true)
171
190
  })
172
191
 
173
192
  const api:OINODbApi = await OINODbFactory.createApi(db, testParams.apiParams)
193
+ api.setDebugOnError(true) // we want debug output (e.g. used sql and exceptions) so that we know that failing tests fail for the correct reason
174
194
 
175
195
  const post_dataset:OINODbMemoryDataSet = new OINODbMemoryDataSet([testParams.postRow])
176
196
  const post_modelset:OINODbModelSet = new OINODbModelSet(api.datamodel, post_dataset)
@@ -189,32 +209,32 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
189
209
  request_params_with_filters.sqlParams = testParams.requestParams.sqlParams
190
210
  // OINOLog.debug("OINOTestApi", {request_params:request_params, request_params_with_filters:request_params_with_filters})
191
211
 
192
- // test("dummy", () => {
212
+ // await test("dummy", () => {
193
213
  // expect({foo:"h\\i"}).toMatchSnapshot()
194
214
  // })
195
215
 
196
216
  target_group = "[SCHEMA]"
197
- test(target_name + target_db + target_table + target_group + " public properties", async () => {
217
+ await test(target_name + target_db + target_table + target_group + " public properties", async () => {
198
218
  expect(api.datamodel.printFieldPublicPropertiesJson()).toMatchSnapshot("SCHEMA")
199
219
  })
200
220
 
201
221
  target_group = "[HTTP GET]"
202
- test(target_name + target_db + target_table + target_group + " select *", async () => {
222
+ await test(target_name + target_db + target_table + target_group + " select *", async () => {
203
223
  expect(encodeData(await (await api.doRequest("GET", "", "", empty_params)).data?.writeString())).toMatchSnapshot("GET JSON")
204
224
  })
205
225
 
206
- test(target_name + target_db + target_table + target_group + " select *", async () => {
226
+ await test(target_name + target_db + target_table + target_group + " select *", async () => {
207
227
  expect(encodeData(await (await api.doRequest("GET", "", "", empty_params)).data?.writeString(OINOContentType.csv))).toMatchSnapshot("GET CSV")
208
228
  })
209
229
 
210
- test(target_name + target_db + target_table + target_group + " select * with template", async () => {
230
+ await test(target_name + target_db + target_table + target_group + " select * with template", async () => {
211
231
  const template = createApiTemplate(api)
212
232
  const api_result:OINODbApiResult = await api.doRequest("GET", "", "", empty_params)
213
233
  const html = (await template.renderFromDbData(api_result.data!)).body
214
234
  expect(encodeData(html)).toMatchSnapshot("GET HTML")
215
235
  })
216
236
 
217
- test(target_name + target_db + target_table + target_group + " select * with filter", async () => {
237
+ await test(target_name + target_db + target_table + target_group + " select * with filter", async () => {
218
238
  expect(encodeData(await (await api.doRequest("GET", "", "", request_params_with_filters)).data?.writeString())).toMatchSnapshot("GET JSON FILTER")
219
239
  })
220
240
 
@@ -225,25 +245,25 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
225
245
  target_group = "[HTTP POST]"
226
246
  const post_body_json:string = await post_modelset.writeString(OINOContentType.json)
227
247
  // OINOLog.info("HTTP POST json", {post_body_json:post_body_json})
228
- test(target_name + target_db + target_table + target_group + " insert with id", async () => {
248
+ await test(target_name + target_db + target_table + target_group + " insert with id", async () => {
229
249
  expect(encodeResult((await api.doRequest("POST", new_row_id, post_body_json, empty_params)))).toMatchSnapshot("POST")
230
250
  })
231
- test(target_name + target_db + target_table + target_group + " insert", async () => {
251
+ await test(target_name + target_db + target_table + target_group + " insert", async () => {
232
252
  expect(encodeResult((await api.doRequest("POST", "", post_body_json, empty_params)))).toMatchSnapshot("POST")
233
253
  expect(encodeData(await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString())).toMatchSnapshot("GET JSON")
234
254
  expect(encodeData(await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString(OINOContentType.csv))).toMatchSnapshot("GET CSV")
235
255
  })
236
- test(target_name + target_db + target_table + target_group + " insert no data", async () => {
256
+ await test(target_name + target_db + target_table + target_group + " insert no data", async () => {
237
257
  expect(encodeResult((await api.doRequest("POST", "", "{}", empty_params)))).toMatchSnapshot("POST")
238
258
  })
239
- test(target_name + target_db + target_table + target_group + " insert duplicate", async () => {
259
+ await test(target_name + target_db + target_table + target_group + " insert duplicate", async () => {
240
260
  expect(encodeResult((await api.doRequest("POST", "", post_body_json, empty_params)))).toMatchSnapshot("POST")
241
261
  })
242
262
 
243
263
  target_group = "[HTTP PUT]"
244
264
  const put_body_json = await put_modelset.writeString(OINOContentType.json)
245
265
  // OINOLog.info("HTTP PUT JSON", {put_body_json:put_body_json})
246
- test(target_name + target_db + target_table + target_group + " update JSON", async () => {
266
+ await test(target_name + target_db + target_table + target_group + " update JSON", async () => {
247
267
  request_params.requestType = OINOContentType.json
248
268
  expect(encodeResult((await api.doRequest("PUT", new_row_id, post_body_json, empty_params)))).toMatchSnapshot("PUT JSON reset")
249
269
  expect(encodeResult((await api.doRequest("PUT", new_row_id, put_body_json, request_params)))).toMatchSnapshot("PUT JSON")
@@ -253,7 +273,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
253
273
  put_dataset.first()
254
274
  const put_body_csv = await put_modelset.writeString(OINOContentType.csv)
255
275
  // OINOLog.info("HTTP PUT csv", {put_body_csv:put_body_csv})
256
- test(target_name + target_db + target_table + target_group + " update CSV", async () => {
276
+ await test(target_name + target_db + target_table + target_group + " update CSV", async () => {
257
277
  request_params.requestType = OINOContentType.csv
258
278
  expect(encodeResult((await api.doRequest("PUT", new_row_id, post_body_json, empty_params)))).toMatchSnapshot("PUT CSV reset")
259
279
  expect(encodeResult((await api.doRequest("PUT", new_row_id, put_body_csv, request_params)))).toMatchSnapshot("PUT CSV")
@@ -265,7 +285,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
265
285
  const multipart_boundary = put_body_formdata.substring(0, put_body_formdata.indexOf('\r'))
266
286
  put_body_formdata = put_body_formdata.replaceAll(multipart_boundary, "---------OINO999999999")
267
287
  // OINOLog.info("HTTP PUT FORMDATA", {put_body_formdata:put_body_formdata})
268
- test(target_name + target_db + target_table + target_group + " update FORMDATA", async () => {
288
+ await test(target_name + target_db + target_table + target_group + " update FORMDATA", async () => {
269
289
  request_params.requestType = OINOContentType.formdata
270
290
  request_params.multipartBoundary = "---------OINO999999999"
271
291
  expect(encodeResult(await (await api.doRequest("PUT", new_row_id, post_body_json, empty_params)))).toMatchSnapshot("PUT FORMDATA reset")
@@ -277,7 +297,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
277
297
  put_dataset.first()
278
298
  const put_body_urlencode = await put_modelset.writeString(OINOContentType.urlencode)
279
299
  // OINOLog.info("HTTP PUT URLENCODE", {put_body_urlencode:put_body_urlencode})
280
- test(target_name + target_db + target_table + target_group + " update URLENCODE", async () => {
300
+ await test(target_name + target_db + target_table + target_group + " update URLENCODE", async () => {
281
301
  request_params.requestType = OINOContentType.urlencode
282
302
  request_params.multipartBoundary = undefined // for some reason this needs reset here so previous test value settings does not leak
283
303
  expect(encodeResult((await api.doRequest("PUT", new_row_id, post_body_json, empty_params)))).toMatchSnapshot("PUT URLENCODE reset")
@@ -285,7 +305,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
285
305
  expect(encodeData(await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString(OINOContentType.urlencode))).toMatchSnapshot("GET URLENCODE")
286
306
  })
287
307
 
288
- test(target_name + target_db + target_table + target_group + " update no data", async () => {
308
+ await test(target_name + target_db + target_table + target_group + " update no data", async () => {
289
309
  expect(encodeResult((await api.doRequest("PUT", new_row_id, "{}", empty_params)))).toMatchSnapshot("PUT")
290
310
  })
291
311
 
@@ -297,14 +317,14 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
297
317
  const notnull_fields:OINODbDataField[] = api.datamodel.filterFields((field:OINODbDataField) => { return (field.fieldParams.isPrimaryKey == false) && (field.fieldParams.isNotNull == true) })
298
318
  if (notnull_fields.length > 0) {
299
319
  const invalid_null_value = "[{\"" + id_field + "\":\"" + new_row_id + "\",\"" + notnull_fields[0].name + "\":null}]"
300
- test(target_name + target_db + target_table + target_group + " update with invalid null value", async () => {
320
+ await test(target_name + target_db + target_table + target_group + " update with invalid null value", async () => {
301
321
  expect(encodeResult((await api.doRequest("PUT", new_row_id, invalid_null_value, empty_params)))).toMatchSnapshot("PUT invalid null")
302
322
  })
303
323
  }
304
324
  const maxsize_fields:OINODbDataField[] = api.datamodel.filterFields((field:OINODbDataField) => { return (field instanceof OINOStringDataField) && (field.fieldParams.isPrimaryKey == false) && (field.maxLength > 0) })
305
325
  if (maxsize_fields.length > 0) {
306
326
  const oversized_value = "[{\"" + id_field + "\":\"" + new_row_id + "\",\"" + maxsize_fields[0].name + "\":\"" + "".padEnd(maxsize_fields[0].maxLength+1, "z") + "\"}]"
307
- test(target_name + target_db + target_table + target_group + " update with oversized data", async () => {
327
+ await test(target_name + target_db + target_table + target_group + " update with oversized data", async () => {
308
328
  expect(encodeResult((await api.doRequest("PUT", new_row_id, oversized_value, empty_params)))).toMatchSnapshot("PUT oversized value")
309
329
  })
310
330
  }
@@ -312,7 +332,7 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
312
332
  if (numeric_fields.length > 0) {
313
333
  const nan_value = "[{\"" + id_field + "\":\"" + new_row_id + "\",\"" + numeric_fields[0].name + "\":\"" + "; FOO" + "\"}]"
314
334
  // OINOLog.debug("HTTP PUT NAN-value", {nan_value:nan_value})
315
- test(target_name + target_db + target_table + target_group + " update NAN-value", async () => {
335
+ await test(target_name + target_db + target_table + target_group + " update NAN-value", async () => {
316
336
  expect(encodeResult((await api.doRequest("PUT", new_row_id, nan_value, empty_params)))).toMatchSnapshot("PUT NAN-value")
317
337
  })
318
338
  }
@@ -320,17 +340,63 @@ export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestPar
320
340
  if (date_fields.length > 0) {
321
341
  const non_date = "[{\"" + id_field + "\":\"" + new_row_id + "\",\"" + date_fields[0].name + "\":\"" + "; FOO" + "\"}]"
322
342
  // OINOLog.debug("HTTP PUT invalid date value", {non_date:non_date})
323
- test(target_name + target_db + target_table + target_group + " update invalid date value", async () => {
343
+ await test(target_name + target_db + target_table + target_group + " update invalid date value", async () => {
324
344
  expect(encodeResult((await api.doRequest("PUT", new_row_id, non_date, empty_params)))).toMatchSnapshot("PUT invalid date value")
325
345
  })
326
346
  }
327
347
  }
328
-
348
+
349
+ target_group = "[BATCH UPDATE]"
350
+ const string_fields:OINODbDataField[] = api.datamodel.filterFields((field:OINODbDataField) => { return ((field instanceof OINOStringDataField) || (field instanceof OINONumberDataField)) && (field.fieldParams.isPrimaryKey == false) && (field.fieldParams.isForeignKey == false) })
351
+ if (string_fields.length == 0) {
352
+ OINOLog.info("BATCH UPDATE table " + testParams.apiParams.tableName + " does not have numeric fields and batch update tests are skipped")
353
+ } else {
354
+ const batch_field = string_fields[0]
355
+ const batch_field_name:string = batch_field.name
356
+ const batch_field_index:number = api.datamodel.findFieldIndexByName(batch_field_name)
357
+ const batch_value = testParams.putRow[batch_field_index]
358
+ let batch_reversed_value
359
+ if (batch_field instanceof OINOStringDataField) {
360
+ batch_reversed_value = (batch_value as string).split("").reverse().join("")
361
+ } else {
362
+ batch_reversed_value = -(batch_value as number)
363
+ }
364
+ const batch_rows = [
365
+ [...testParams.putRow] as OINODataRow,
366
+ [...testParams.putRow] as OINODataRow,
367
+ [...testParams.putRow] as OINODataRow
368
+ ]
369
+
370
+ await test(target_name + target_db + target_table + target_group + " reversed values", async () => {
371
+ batch_rows[0][batch_field_index] = batch_reversed_value
372
+ batch_rows[1][batch_field_index] = batch_value
373
+ batch_rows[2][batch_field_index] = batch_reversed_value
374
+ const batch_update_result = await api.doBatchUpdate("PUT", batch_rows, empty_params)
375
+ expect(batch_update_result.success).toBe(true)
376
+ expect(encodeResult(batch_update_result)).toMatchSnapshot("PUT reversed data")
377
+
378
+ const get_reversed_data = await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString(OINOContentType.csv)
379
+ expect(encodeData(get_reversed_data)).toMatchSnapshot("GET reversed data")
380
+
381
+ batch_rows[0][batch_field_index] = batch_value
382
+ batch_rows[1][batch_field_index] = batch_reversed_value
383
+ batch_rows[2][batch_field_index] = batch_value
384
+ const batch_restore_result = await api.doBatchUpdate("PUT", batch_rows, empty_params)
385
+ expect(batch_restore_result.success).toBe(true)
386
+ expect(encodeResult(batch_restore_result)).toMatchSnapshot("PUT restored data")
387
+
388
+ const get_restored_data = await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString(OINOContentType.csv)
389
+ expect(encodeData(get_restored_data)).toMatchSnapshot("GET restored data")
390
+ })
391
+ }
392
+
329
393
  target_group = "[HTTP DELETE]"
330
- test(target_name + target_db + target_table + target_group + " remove", async () => {
394
+ await test(target_name + target_db + target_table + target_group + " remove", async () => {
331
395
  expect(encodeResult((await api.doRequest("DELETE", new_row_id, "", empty_params)))).toMatchSnapshot("DELETE")
332
396
  expect(encodeData(await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString())).toMatchSnapshot("GET JSON")
333
397
  })
398
+
399
+
334
400
  }
335
401
 
336
402
  export async function OINOTestOwasp(dbParams:OINODbParams, testParams: OINOTestParams) {
@@ -362,7 +428,7 @@ export async function OINOTestOwasp(dbParams:OINODbParams, testParams: OINOTestP
362
428
  let target_table:string = "[" + testParams.apiParams.tableName + "]"
363
429
 
364
430
  let target_group = "[OWASP GET]"
365
- test(target_name + target_db + target_table + target_group + " GET with filter", async () => {
431
+ await test(target_name + target_db + target_table + target_group + " GET with filter", async () => {
366
432
  const get_res:OINODbApiResult = await api.doRequest("GET", "", "", request_params_with_filters)
367
433
  if (get_res.success) {
368
434
  expect(encodeData(await get_res.data?.writeString())).toMatchSnapshot("OWASP GET DATA")
@@ -371,7 +437,7 @@ export async function OINOTestOwasp(dbParams:OINODbParams, testParams: OINOTestP
371
437
  }
372
438
  })
373
439
  target_group = "[OWASP POST]"
374
- test(target_name + target_db + target_table + target_group + " POST", async () => {
440
+ await test(target_name + target_db + target_table + target_group + " POST", async () => {
375
441
  const post_body_json:string = await post_modelset.writeString(OINOContentType.json)
376
442
  const post_res:OINODbApiResult = await api.doRequest("POST", "", post_body_json, request_params)
377
443
  expect(encodeResult(post_res)).toMatchSnapshot("OWASP POST RESULT")
@@ -379,7 +445,7 @@ export async function OINOTestOwasp(dbParams:OINODbParams, testParams: OINOTestP
379
445
  })
380
446
 
381
447
  target_group = "[OWASP PUT]"
382
- test(target_name + target_db + target_table + target_group + " PUT", async () => {
448
+ await test(target_name + target_db + target_table + target_group + " PUT", async () => {
383
449
  const put_body_json:string = await put_modelset.writeString(OINOContentType.json)
384
450
  const post_res:OINODbApiResult = await api.doRequest("PUT", new_row_id, put_body_json, request_params)
385
451
  expect(encodeResult(post_res)).toMatchSnapshot("OWASP PUT RESULT")
@@ -387,21 +453,21 @@ export async function OINOTestOwasp(dbParams:OINODbParams, testParams: OINOTestP
387
453
  })
388
454
 
389
455
  target_group = "[OWASP DELETE]"
390
- test(target_name + target_db + target_table + target_group + " DELETE", async () => {
456
+ await test(target_name + target_db + target_table + target_group + " DELETE", async () => {
391
457
  expect(encodeResult((await api.doRequest("DELETE", new_row_id, "", empty_params)))).toMatchSnapshot("DELETE")
392
458
  expect(encodeData(await (await api.doRequest("GET", new_row_id, "", empty_params)).data?.writeString())).toMatchSnapshot("DELETE JSON")
393
459
  })
394
460
  }
395
461
 
396
462
 
397
- for (let db of dbs) {
398
- for (let api_test of api_tests) {
463
+ for (let db of DATABASES) {
464
+ for (let api_test of API_TESTS) {
399
465
  await OINOTestApi(db, api_test)
400
466
  }
401
467
  }
402
468
 
403
- for (let db of dbs) {
404
- for (let owasp_test of owasp_tests) {
469
+ for (let db of DATABASES) {
470
+ for (let owasp_test of OWASP_TESTS) {
405
471
  await OINOTestOwasp(db, owasp_test)
406
472
  }
407
473
  }
@@ -411,36 +477,20 @@ const snapshot_file = Bun.file("./node_modules/@oino-ts/db/src/__snapshots__/OIN
411
477
  await Bun.write("./node_modules/@oino-ts/db/src/__snapshots__/OINODbApi.test.ts.snap.js", snapshot_file) // copy snapshots as .js so require works (note! if run with --update-snapshots, it's still the old file)
412
478
  const snapshots = require("./__snapshots__/OINODbApi.test.ts.snap.js")
413
479
 
414
- const api_crosschecks:string[] = [
415
- "[HTTP GET] select *: GET JSON 1",
416
- "[HTTP GET] select * with template: GET HTML 1",
417
- "[HTTP POST] insert: GET JSON 1",
418
- "[HTTP POST] insert: GET CSV 1",
419
- "[HTTP PUT] update JSON: GET JSON 1",
420
- "[HTTP PUT] update CSV: GET CSV 1",
421
- "[HTTP PUT] update FORMDATA: GET FORMDATA 1",
422
- "[HTTP PUT] update URLENCODE: GET URLENCODE 1"
423
- ]
424
-
425
- const owasp_crosschecks:string[] = [
426
- "[OWASP POST] POST: POST JSON 1",
427
- "[OWASP PUT] PUT: OWASP PUT RESULT 1"
428
- ]
429
-
430
- for (let i=0; i<dbs.length-1; i++) {
431
- const db1:string = dbs[i].type
432
- const db2:string = dbs[i+1].type
433
- for (let api_test of api_tests) {
480
+ for (let i=0; i<DATABASES.length-1; i++) {
481
+ const db1:string = DATABASES[i].type
482
+ const db2:string = DATABASES[i+1].type
483
+ for (let api_test of API_TESTS) {
434
484
  const table_name = api_test.apiParams.tableName
435
- for (let crosscheck of api_crosschecks) {
485
+ for (let crosscheck of API_CROSSCHECKS) {
436
486
  test("cross check {" + db1 + "} and {" + db2 + "} table {" + table_name + "} snapshots on {" + crosscheck + "}", () => {
437
487
  expect(snapshots["[" + api_test.name + "][" + db1 + "][" + table_name + "]" + crosscheck]).toMatch(snapshots["[" + api_test.name + "][" + db2 + "][" + table_name + "]" + crosscheck])
438
488
  })
439
489
  }
440
490
  }
441
- for (let owasp_test of owasp_tests) {
491
+ for (let owasp_test of OWASP_TESTS) {
442
492
  const table_name = owasp_test.apiParams.tableName
443
- for (let crosscheck of owasp_crosschecks) {
493
+ for (let crosscheck of OWASP_CROSSCHECKS) {
444
494
  test("cross check {" + db1 + "} and {" + db2 + "} table {" + table_name + "} snapshots on {" + crosscheck + "}", () => {
445
495
  expect(snapshots["[" + owasp_test.name + "][" + db1 + "][" + table_name + "]" + crosscheck]).toMatch(snapshots["[" + owasp_test.name + "][" + db2 + "][" + table_name + "]" + crosscheck])
446
496
  })