w-orm-lowdb 1.0.5 → 1.0.7

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.
@@ -1,6 +1,7 @@
1
- import assert from 'assert'
2
- import WOrm from '../src/WOrmLowdb.mjs'
3
- import w from 'wsemi'
1
+ import assert from 'assert'
2
+ import fs from 'node:fs/promises'
3
+ import WOrm from '../src/WOrmLowdb.mjs'
4
+ import w from 'wsemi'
4
5
 
5
6
 
6
7
  function isWindows() {
@@ -346,6 +347,69 @@ if (isWindows()) {
346
347
  assert.strict.deepStrictEqual(vget[10], vans[10])
347
348
  })
348
349
 
349
- })
350
- }
350
+ })
351
+
352
+ describe('save autoInsert', function() {
353
+ let url = './tmp/save-autoinsert.test.json'
354
+
355
+ beforeEach(async function() {
356
+ await fs.mkdir('./tmp', { recursive: true })
357
+ await fs.rm(url, { force: true })
358
+ })
359
+
360
+ afterEach(async function() {
361
+ await fs.rm(url, { force: true })
362
+ })
363
+
364
+ it('should preserve updated data when a later item is auto inserted', async function() {
365
+ let wo = WOrm({
366
+ url,
367
+ db: 'worm',
368
+ cl: 'items',
369
+ })
370
+
371
+ await wo.insert({
372
+ id: 'a',
373
+ n: 1,
374
+ })
375
+
376
+ let res = await wo.save([
377
+ {
378
+ id: 'a',
379
+ n: 2,
380
+ },
381
+ {
382
+ id: 'b',
383
+ n: 3,
384
+ },
385
+ ])
386
+
387
+ assert.strict.deepStrictEqual(res, [
388
+ {
389
+ n: 1,
390
+ nModified: 1,
391
+ ok: 1,
392
+ },
393
+ {
394
+ n: 1,
395
+ nInserted: 1,
396
+ ok: 1,
397
+ },
398
+ ])
399
+
400
+ let rows = await wo.select()
401
+ assert.strict.deepStrictEqual(rows, [
402
+ {
403
+ id: 'a',
404
+ n: 2,
405
+ },
406
+ {
407
+ id: 'b',
408
+ n: 3,
409
+ },
410
+ ])
411
+ })
412
+
413
+ })
414
+ }
351
415