@naturalcycles/db-lib 10.58.0 → 10.60.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.
@@ -14,7 +14,7 @@ export async function runCommonDaoTest(
14
14
  quirks: CommonDBImplementationQuirks = {},
15
15
  ): Promise<void> {
16
16
  // this is because vitest cannot be "required" from cjs
17
- const { test, expect } = await import('vitest')
17
+ const { afterAll, beforeAll, expect, it } = await import('vitest')
18
18
 
19
19
  const { support } = db
20
20
  const dao = new CommonDao({
@@ -33,20 +33,14 @@ export async function runCommonDaoTest(
33
33
  updated: expect.any(Number),
34
34
  }))
35
35
 
36
- test('ping', async () => {
37
- await dao.ping()
38
- })
39
-
40
- // CREATE TABLE, DROP
41
- if (support.createTable) {
42
- test('createTable, dropIfExists=true', async () => {
36
+ beforeAll(async () => {
37
+ // Tests in this suite are not isolated: a failed run can leave rows behind for the next run
38
+ if (support.createTable) {
43
39
  await dao.createTable(testItemBMSchema.build(), { dropIfExists: true })
44
- })
45
- }
40
+ }
46
41
 
47
- if (support.queries) {
48
42
  // DELETE ALL initially
49
- test('deleteByIds test items', async () => {
43
+ if (support.queries) {
50
44
  const rows = await dao.query().select(['id']).runQuery()
51
45
  await db.deleteByQuery(
52
46
  DBQuery.create(TEST_TABLE).filter(
@@ -55,44 +49,46 @@ export async function runCommonDaoTest(
55
49
  rows.map(r => r.id),
56
50
  ),
57
51
  )
58
- })
52
+ }
53
+ })
54
+
55
+ afterAll(async () => {
56
+ // CLEAN UP
57
+ if (support.queries) {
58
+ await dao.query().deleteByQuery()
59
+ }
60
+ })
59
61
 
62
+ it('should respond to ping', async () => {
63
+ await dao.ping()
64
+ })
65
+
66
+ if (support.queries) {
60
67
  // QUERY empty
61
- test('runQuery(all), runQueryCount should return empty', async () => {
68
+ it('should return no rows and a count of 0 for an empty table', async () => {
62
69
  expect(await dao.query().runQuery()).toEqual([])
63
70
  expect(await dao.query().runQueryCount()).toBe(0)
64
71
  })
65
72
  }
66
73
 
67
74
  // GET empty
68
- test('getByIds(item1.id) should return empty', async () => {
75
+ it('should return no row for an id that is not saved yet', async () => {
69
76
  const [item1Loaded] = await dao.getByIds([item1.id])
70
77
  expect(item1Loaded).toBeUndefined()
71
78
  expect(await dao.getById(item1.id)).toBeNull()
72
79
  })
73
80
 
74
- test('getByIds([]) should return []', async () => {
81
+ it('should return an empty array for getByIds without ids', async () => {
75
82
  expect(await dao.getByIds([])).toEqual([])
76
83
  })
77
84
 
78
- test('getByIds(...) should return empty', async () => {
85
+ it('should return an empty array for unknown ids', async () => {
79
86
  expect(await dao.getByIds(['abc', 'abcd'])).toEqual([])
80
87
  })
81
88
 
82
- // TimeMachine
83
- if (support.timeMachine) {
84
- test('getByIds(...) 10 minutes ago should return []', async () => {
85
- expect(
86
- await dao.getByIds([item1.id, 'abc'], {
87
- readAt: localTime.now().minus(10, 'minute').unix,
88
- }),
89
- ).toEqual([])
90
- })
91
- }
92
-
93
89
  // SAVE
94
90
  if (support.nullValues) {
95
- test('should allow to save and load null values', async () => {
91
+ it('should allow to save and load null values', async () => {
96
92
  const item3 = {
97
93
  ...createTestItemBM(3),
98
94
  k2: null,
@@ -107,7 +103,7 @@ export async function runCommonDaoTest(
107
103
  })
108
104
  }
109
105
 
110
- test('undefined values should not be saved/loaded', async () => {
106
+ it('should not store undefined properties but keep them on the input object', async () => {
111
107
  const item3 = {
112
108
  ...createTestItemBM(3),
113
109
  k2: undefined,
@@ -128,7 +124,7 @@ export async function runCommonDaoTest(
128
124
  expect(item3.k2).toBeUndefined()
129
125
  })
130
126
 
131
- test('saveBatch test items', async () => {
127
+ it('should save the test items and return the same objects', async () => {
132
128
  const itemsSaved = await dao.saveBatch(items)
133
129
  expect(itemsSaved[0]).toBe(items[0]) // expect "same object" returned
134
130
 
@@ -140,7 +136,7 @@ export async function runCommonDaoTest(
140
136
  })
141
137
 
142
138
  if (support.increment) {
143
- test('increment', async () => {
139
+ it('should increment a property by a different amount per id', async () => {
144
140
  await dao.incrementBatch('k3', { id1: 1, id2: 2 })
145
141
  let rows = await dao.query().runQuery()
146
142
  rows = _sortBy(rows, r => r.id)
@@ -168,7 +164,7 @@ export async function runCommonDaoTest(
168
164
  }
169
165
 
170
166
  // GET not empty
171
- test('getByIds all items', async () => {
167
+ it('should return all saved items by ids, skipping unknown ids', async () => {
172
168
  const rows = await dao.getByIds(items.map(i => i.id).concat('abcd'))
173
169
  expectMatch(
174
170
  expectedItems,
@@ -177,16 +173,25 @@ export async function runCommonDaoTest(
177
173
  )
178
174
  })
179
175
 
176
+ // TimeMachine
177
+ if (support.timeMachine) {
178
+ it('should not return the saved items when reading 10 minutes back in time', async () => {
179
+ const ids = items.map(i => i.id)
180
+ const readAt = localTime.now().minus(10, 'minute').unix
181
+ expect(await dao.getByIds(ids, { readAt })).toEqual([])
182
+ })
183
+ }
184
+
180
185
  // QUERY
181
186
  if (support.queries) {
182
- test('runQuery(all) should return all items', async () => {
187
+ it('should return all items from a query without conditions', async () => {
183
188
  let rows = await dao.query().runQuery()
184
189
  rows = _sortBy(rows, r => r.id)
185
190
  expectMatch(expectedItems, rows, quirks)
186
191
  })
187
192
 
188
193
  if (support.dbQueryFilter) {
189
- test('query even=true', async () => {
194
+ it('should filter rows by equality', async () => {
190
195
  let rows = await dao.query().filter('even', '==', true).runQuery()
191
196
  rows = _sortBy(rows, r => r.id)
192
197
  expectMatch(
@@ -196,7 +201,7 @@ export async function runCommonDaoTest(
196
201
  )
197
202
  })
198
203
 
199
- test('query nested property', async () => {
204
+ it('should filter rows by a nested property', async () => {
200
205
  let rows = await dao
201
206
  .query()
202
207
  .filter('nested.foo' as any, '==', 1)
@@ -211,14 +216,14 @@ export async function runCommonDaoTest(
211
216
  }
212
217
 
213
218
  if (support.dbQueryOrder) {
214
- test('query order by k1 desc', async () => {
219
+ it('should order rows descending', async () => {
215
220
  const rows = await dao.query().order('k1', true).runQuery()
216
221
  expectMatch(expectedItems.toReversed(), rows, quirks)
217
222
  })
218
223
  }
219
224
 
220
225
  if (support.dbQuerySelectFields) {
221
- test('projection query with only ids', async () => {
226
+ it('should select only the id', async () => {
222
227
  let rows = await dao.query().select(['id']).runQuery()
223
228
  rows = _sortBy(rows, r => r.id)
224
229
  expectMatch(
@@ -229,14 +234,14 @@ export async function runCommonDaoTest(
229
234
  })
230
235
  }
231
236
 
232
- test('runQueryCount should return 3', async () => {
237
+ it('should count all saved items', async () => {
233
238
  expect(await dao.query().runQueryCount()).toBe(3)
234
239
  })
235
240
  }
236
241
 
237
242
  // STREAM
238
243
  if (support.streaming) {
239
- test('streamQueryForEach all', async () => {
244
+ it('should stream all items to forEachSync', async () => {
240
245
  let rows: TestItemBM[] = []
241
246
  await dao
242
247
  .query()
@@ -247,14 +252,14 @@ export async function runCommonDaoTest(
247
252
  expectMatch(expectedItems, rows, quirks)
248
253
  })
249
254
 
250
- test('streamQuery all', async () => {
255
+ it('should stream all items to an array', async () => {
251
256
  let rows: TestItemBM[] = await dao.query().streamQuery().toArray()
252
257
 
253
258
  rows = _sortBy(rows, r => r.id)
254
259
  expectMatch(expectedItems, rows, quirks)
255
260
  })
256
261
 
257
- test('streamQueryIdsForEach all', async () => {
262
+ it('should stream all ids to forEachSync', async () => {
258
263
  let ids: string[] = []
259
264
  await dao
260
265
  .query()
@@ -268,7 +273,7 @@ export async function runCommonDaoTest(
268
273
  )
269
274
  })
270
275
 
271
- test('streamQueryIds all', async () => {
276
+ it('should stream all ids to an array', async () => {
272
277
  let ids = await dao.query().streamQueryIds().toArray()
273
278
  ids = ids.sort()
274
279
  expectMatch(
@@ -278,7 +283,7 @@ export async function runCommonDaoTest(
278
283
  )
279
284
  })
280
285
 
281
- test('streamSave', async () => {
286
+ it('should save the items of a stream', async () => {
282
287
  const items2 = createTestItemsBM(2).map(i => ({ ...i, id: i.id + '_str' }))
283
288
  const ids = items2.map(i => i.id)
284
289
 
@@ -294,16 +299,11 @@ export async function runCommonDaoTest(
294
299
 
295
300
  // DELETE BY
296
301
  if (support.queries) {
297
- test('deleteByQuery even=false', async () => {
302
+ it('should delete rows by a filter and return the deleted count', async () => {
298
303
  const deleted = await dao.query().filter('even', '==', false).deleteByQuery()
299
304
  expect(deleted).toBe(items.filter(item => !item.even).length)
300
305
  expect(await dao.query().runQueryCount()).toBe(1)
301
306
  })
302
-
303
- test('cleanup', async () => {
304
- // CLEAN UP
305
- await dao.query().deleteByQuery()
306
- })
307
307
  }
308
308
 
309
309
  if (support.transactions) {
@@ -319,7 +319,7 @@ export async function runCommonDaoTest(
319
319
  return itemsToSave
320
320
  }
321
321
 
322
- test('transaction happy path', async () => {
322
+ it('should commit the saves and deletes made in runInTransaction', async () => {
323
323
  // cleanup
324
324
  await dao.query().deleteByQuery()
325
325
 
@@ -353,11 +353,15 @@ export async function runCommonDaoTest(
353
353
 
354
354
  const rows = await dao.query().runQuery()
355
355
  const expected = [items[0], { ...items[2]!, k1: 'k1_mod' }]
356
- expectMatch(expected, rows, quirks)
356
+ expectMatch(
357
+ expected,
358
+ _sortBy(rows, r => r.id),
359
+ quirks,
360
+ )
357
361
  })
358
362
 
359
363
  if (support.createTransaction) {
360
- test('createTransaction happy path', async () => {
364
+ it('should commit the saves and deletes made in a created transaction', async () => {
361
365
  // cleanup
362
366
  await dao.query().deleteByQuery()
363
367
 
@@ -391,11 +395,15 @@ export async function runCommonDaoTest(
391
395
 
392
396
  const rows = await dao.query().runQuery()
393
397
  const expected = [items[0], { ...items[2]!, k1: 'k1_mod' }]
394
- expectMatch(expected, rows, quirks)
398
+ expectMatch(
399
+ expected,
400
+ _sortBy(rows, r => r.id),
401
+ quirks,
402
+ )
395
403
  })
396
404
  }
397
405
 
398
- test('transaction rollback', async () => {
406
+ it('should roll back runInTransaction when a save fails validation', async () => {
399
407
  const expected = await prepare()
400
408
 
401
409
  let err: any
@@ -413,34 +421,28 @@ export async function runCommonDaoTest(
413
421
  expect(err).toBeInstanceOf(Error)
414
422
 
415
423
  const rows = await dao.query().runQuery()
416
- expectMatch(expected, rows, quirks)
424
+ expectMatch(
425
+ expected,
426
+ _sortBy(rows, r => r.id),
427
+ quirks,
428
+ )
417
429
  })
418
430
 
419
431
  if (support.createTransaction) {
420
- test('createTransaction rollback', async () => {
432
+ it('should leave the data unchanged when a created transaction is rolled back after a failed save', async () => {
421
433
  const expected = await prepare()
422
434
 
423
- let err: any
424
- try {
425
- const tx = await dao.createTransaction()
426
- await tx.deleteById(dao, items[2]!.id)
427
- await tx.save(dao, { ...items[0]!, k1: 5 as any }) // it should fail here
428
- await tx.commit()
429
- } catch (err2) {
430
- err = err2
431
- }
432
-
433
- expect(err).toBeDefined()
434
- expect(err).toBeInstanceOf(Error)
435
+ const tx = await dao.createTransaction()
436
+ await tx.deleteById(dao, items[2]!.id)
437
+ await expect(tx.save(dao, { ...items[0]!, k1: 5 as any })).rejects.toThrow() // it should fail here
438
+ await tx.rollback()
435
439
 
436
440
  const rows = await dao.query().runQuery()
437
- expectMatch(expected, rows, quirks)
438
- })
439
- }
440
-
441
- if (support.queries) {
442
- test('transaction cleanup', async () => {
443
- await dao.query().deleteByQuery()
441
+ expectMatch(
442
+ expected,
443
+ _sortBy(rows, r => r.id),
444
+ quirks,
445
+ )
444
446
  })
445
447
  }
446
448
  }
@@ -11,7 +11,7 @@ const testEntries: KeyValueTuple<string, Buffer>[] = testIds.map(id => [
11
11
  ])
12
12
 
13
13
  export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<void> {
14
- const { afterAll, beforeAll, expect, test } = await import('vitest')
14
+ const { afterAll, beforeAll, expect, it } = await import('vitest')
15
15
 
16
16
  beforeAll(async () => {
17
17
  // Tests in this suite are not isolated,
@@ -29,28 +29,30 @@ export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<voi
29
29
 
30
30
  const { support } = db
31
31
 
32
- test('ping', async () => {
32
+ it('should respond to ping', async () => {
33
33
  await db.ping()
34
34
  })
35
35
 
36
- test('createTable', async () => {
36
+ it('should create the table, dropping an existing one', async () => {
37
37
  await db.createTable(TEST_TABLE, { dropIfExists: true })
38
38
  })
39
39
 
40
- test('deleteByIds non existing', async () => {
40
+ it('should not throw when deleting ids that do not exist', async () => {
41
41
  await db.deleteByIds(TEST_TABLE, testIds)
42
42
  })
43
43
 
44
- test('getByIds should return empty', async () => {
44
+ it('should return no entries for ids that do not exist', async () => {
45
45
  const results = await db.getByIds(TEST_TABLE, testIds)
46
46
  expect(results).toEqual([])
47
47
  })
48
48
 
49
- test('count should be 0', async () => {
50
- expect(await db.count(TEST_TABLE)).toBe(0)
51
- })
49
+ if (support.count) {
50
+ it('should count 0 entries in an empty table', async () => {
51
+ expect(await db.count(TEST_TABLE)).toBe(0)
52
+ })
53
+ }
52
54
 
53
- test('saveBatch, then getByIds', async () => {
55
+ it('should return the saved entries by ids', async () => {
54
56
  await db.saveBatch(TEST_TABLE, testEntries)
55
57
 
56
58
  const entries = await db.getByIds(TEST_TABLE, testIds)
@@ -59,18 +61,18 @@ export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<voi
59
61
  })
60
62
 
61
63
  if (support.count) {
62
- test('count should be 3', async () => {
64
+ it('should count the saved entries', async () => {
63
65
  expect(await db.count(TEST_TABLE)).toBe(3)
64
66
  })
65
67
  }
66
68
 
67
- test('streamIds', async () => {
69
+ it('should stream all ids', async () => {
68
70
  const ids = await db.streamIds(TEST_TABLE).toArray()
69
71
  ids.sort()
70
72
  expect(ids).toEqual(testIds)
71
73
  })
72
74
 
73
- test('streamIds limited', async () => {
75
+ it('should stream as many ids as the limit', async () => {
74
76
  const idsLimited = await db.streamIds(TEST_TABLE, 2).toArray()
75
77
  // Order is non-deterministic, so, cannot compare values
76
78
  // idsLimited.sort()
@@ -78,58 +80,64 @@ export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<voi
78
80
  expect(idsLimited.length).toBe(2)
79
81
  })
80
82
 
81
- test('streamValues', async () => {
83
+ it('should stream all values', async () => {
82
84
  const values = await db.streamValues(TEST_TABLE).toArray()
83
85
  values.sort()
84
86
  expect(values).toEqual(testEntries.map(e => e[1]))
85
87
  })
86
88
 
87
- test('streamValues limited', async () => {
89
+ it('should stream as many values as the limit', async () => {
88
90
  const valuesLimited = await db.streamValues(TEST_TABLE, 2).toArray()
89
91
  // valuesLimited.sort()
90
92
  // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
91
93
  expect(valuesLimited.length).toBe(2)
92
94
  })
93
95
 
94
- test('streamEntries', async () => {
96
+ it('should stream all entries', async () => {
95
97
  const entries = await db.streamEntries(TEST_TABLE).toArray()
96
98
  entries.sort()
97
99
  expect(entries).toEqual(testEntries)
98
100
  })
99
101
 
100
- test('streamEntries limited', async () => {
102
+ it('should stream as many entries as the limit', async () => {
101
103
  const entriesLimited = await db.streamEntries(TEST_TABLE, 2).toArray()
102
104
  // entriesLimited.sort()
103
105
  // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
104
106
  expect(entriesLimited.length).toBe(2)
105
107
  })
106
108
 
107
- test('deleteByIds should clear', async () => {
109
+ it('should delete the entries by ids', async () => {
108
110
  await db.deleteByIds(TEST_TABLE, testIds)
109
111
  const results = await db.getByIds(TEST_TABLE, testIds)
110
112
  expect(results).toEqual([])
111
113
  })
112
114
 
115
+ if (support.count) {
116
+ it('should count 0 entries after deleting them', async () => {
117
+ expect(await db.count(TEST_TABLE)).toBe(0)
118
+ })
119
+ }
120
+
113
121
  if (support.increment) {
114
122
  const id = 'nonExistingField'
115
123
  const id2 = 'nonExistingField2'
116
124
 
117
- test('increment on a non-existing field should set the value to 1', async () => {
125
+ it('should increment a missing key from 0', async () => {
118
126
  const result = await db.incrementBatch(TEST_TABLE, [[id, 1]])
119
127
  expect(result).toEqual([[id, 1]])
120
128
  })
121
129
 
122
- test('increment on a existing field should increase the value by one', async () => {
130
+ it('should increment an existing key by 1', async () => {
123
131
  const result = await db.incrementBatch(TEST_TABLE, [[id, 1]])
124
132
  expect(result).toEqual([[id, 2]])
125
133
  })
126
134
 
127
- test('increment should increase the value by the specified amount', async () => {
135
+ it('should increment an existing key by the given amount', async () => {
128
136
  const result = await db.incrementBatch(TEST_TABLE, [[id, 2]])
129
137
  expect(result).toEqual([[id, 4]])
130
138
  })
131
139
 
132
- test('increment 2 ids at the same time', async () => {
140
+ it('should increment two keys in one batch', async () => {
133
141
  const result = await db.incrementBatch(TEST_TABLE, [
134
142
  [id, 1],
135
143
  [id2, 2],
@@ -8,7 +8,7 @@ const testIds = testItems.map(e => e.id)
8
8
  const testEntries: KeyValueDBTuple[] = testItems.map(e => [e.id, Buffer.from(`${e.id}value`)])
9
9
 
10
10
  export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<void> {
11
- const { afterAll, beforeAll, expect, test } = await import('vitest')
11
+ const { afterAll, beforeAll, expect, it } = await import('vitest')
12
12
 
13
13
  const dao = new CommonKeyValueDao({
14
14
  db,
@@ -31,24 +31,24 @@ export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<vo
31
31
  await dao.deleteByIds(ids)
32
32
  })
33
33
 
34
- test('ping', async () => {
34
+ it('should respond to ping', async () => {
35
35
  await dao.ping()
36
36
  })
37
37
 
38
- test('createTable', async () => {
38
+ it('should create the table, dropping an existing one', async () => {
39
39
  await dao.createTable({ dropIfExists: true })
40
40
  })
41
41
 
42
- test('deleteByIds non existing', async () => {
42
+ it('should not throw when deleting ids that do not exist', async () => {
43
43
  await dao.deleteByIds(testIds)
44
44
  })
45
45
 
46
- test('getByIds should return empty', async () => {
46
+ it('should return no entries for ids that do not exist', async () => {
47
47
  const results = await dao.getByIds(testIds)
48
48
  expect(results).toEqual([])
49
49
  })
50
50
 
51
- test('saveBatch, then getByIds', async () => {
51
+ it('should return the saved entries by ids', async () => {
52
52
  await dao.saveBatch(testEntries)
53
53
 
54
54
  const entries = await dao.getByIds(testIds)
@@ -60,13 +60,13 @@ export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<vo
60
60
  // expect(entries.map(e => e[1].toString())).toEqual(testEntries.map(e => e[1].toString()))
61
61
  })
62
62
 
63
- test('streamIds', async () => {
63
+ it('should stream all ids', async () => {
64
64
  const ids = await dao.streamIds().toArray()
65
65
  ids.sort()
66
66
  expect(ids).toEqual(testIds)
67
67
  })
68
68
 
69
- test('streamIds limited', async () => {
69
+ it('should stream as many ids as the limit', async () => {
70
70
  const idsLimited = await dao.streamIds(2).toArray()
71
71
  // Order is non-deterministic, so, cannot compare values
72
72
  // idsLimited.sort()
@@ -74,33 +74,33 @@ export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<vo
74
74
  expect(idsLimited.length).toBe(2)
75
75
  })
76
76
 
77
- test('streamValues', async () => {
77
+ it('should stream all values', async () => {
78
78
  const values = await dao.streamValues().toArray()
79
79
  values.sort()
80
80
  expect(values).toEqual(testEntries.map(e => e[1]))
81
81
  })
82
82
 
83
- test('streamValues limited', async () => {
83
+ it('should stream as many values as the limit', async () => {
84
84
  const valuesLimited = await dao.streamValues(2).toArray()
85
85
  // valuesLimited.sort()
86
86
  // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
87
87
  expect(valuesLimited.length).toBe(2)
88
88
  })
89
89
 
90
- test('streamEntries', async () => {
90
+ it('should stream all entries', async () => {
91
91
  const entries = await dao.streamEntries().toArray()
92
92
  entries.sort()
93
93
  expect(entries).toEqual(testEntries)
94
94
  })
95
95
 
96
- test('streamEntries limited', async () => {
96
+ it('should stream as many entries as the limit', async () => {
97
97
  const entriesLimited = await dao.streamEntries(2).toArray()
98
98
  // entriesLimited.sort()
99
99
  // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
100
100
  expect(entriesLimited.length).toBe(2)
101
101
  })
102
102
 
103
- test('deleteByIds should clear', async () => {
103
+ it('should delete the entries by ids', async () => {
104
104
  await dao.deleteByIds(testIds)
105
105
  const results = await dao.getByIds(testIds)
106
106
  expect(results).toEqual([])
@@ -110,22 +110,22 @@ export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<vo
110
110
  const id = 'nonExistingField'
111
111
  const id2 = 'nonExistingField2'
112
112
 
113
- test('increment on a non-existing field should set the value to 1', async () => {
113
+ it('should increment a missing key from 0', async () => {
114
114
  const result = await dao.increment(id)
115
115
  expect(result).toBe(1)
116
116
  })
117
117
 
118
- test('increment on a existing field should increase the value by one', async () => {
118
+ it('should increment an existing key by 1', async () => {
119
119
  const result = await dao.increment(id)
120
120
  expect(result).toBe(2)
121
121
  })
122
122
 
123
- test('increment should increase the value by the specified amount', async () => {
123
+ it('should increment an existing key by the given amount', async () => {
124
124
  const result = await dao.increment(id, 2)
125
125
  expect(result).toBe(4)
126
126
  })
127
127
 
128
- test('increment 2 ids at the same time', async () => {
128
+ it('should increment two keys in one batch', async () => {
129
129
  const result = await dao.incrementBatch([
130
130
  [id, 1],
131
131
  [id2, 2],