@naturalcycles/db-lib 9.17.0 → 9.19.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/dist/adapter/inmemory/inMemoryKeyValueDB.d.ts +1 -0
- package/dist/adapter/inmemory/inMemoryKeyValueDB.js +7 -0
- package/dist/commondao/common.dao.d.ts +0 -2
- package/dist/commondao/common.dao.js +6 -0
- package/dist/kv/commonKeyValueDB.d.ts +8 -0
- package/dist/kv/commonKeyValueDao.d.ts +7 -0
- package/dist/kv/commonKeyValueDao.js +9 -0
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +3 -1
- package/dist/testing/keyValueDBTest.js +24 -0
- package/dist/testing/keyValueDaoTest.js +24 -0
- package/package.json +1 -1
- package/src/adapter/inmemory/inMemoryKeyValueDB.ts +10 -0
- package/src/commondao/common.dao.ts +5 -4
- package/src/kv/commonKeyValueDB.ts +9 -0
- package/src/kv/commonKeyValueDao.ts +10 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/keyValueDBTest.ts +29 -0
- package/src/testing/keyValueDaoTest.ts +29 -0
|
@@ -17,4 +17,5 @@ export declare class InMemoryKeyValueDB implements CommonKeyValueDB {
|
|
|
17
17
|
streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
|
|
18
18
|
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
|
|
19
19
|
count(table: string): Promise<number>;
|
|
20
|
+
increment(table: string, id: string, by?: number): Promise<number>;
|
|
20
21
|
}
|
|
@@ -35,5 +35,12 @@ class InMemoryKeyValueDB {
|
|
|
35
35
|
this.data[table] ||= {};
|
|
36
36
|
return Object.keys(this.data[table]).length;
|
|
37
37
|
}
|
|
38
|
+
async increment(table, id, by = 1) {
|
|
39
|
+
this.data[table] ||= {};
|
|
40
|
+
const currentValue = this.data[table][id] ? parseInt(this.data[table][id].toString()) : 0;
|
|
41
|
+
const newValue = currentValue + by;
|
|
42
|
+
this.data[table][id] = Buffer.from(String(newValue));
|
|
43
|
+
return newValue;
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
46
|
exports.InMemoryKeyValueDB = InMemoryKeyValueDB;
|
|
@@ -15,10 +15,8 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
15
15
|
cfg: CommonDaoCfg<BM, DBM, ID>;
|
|
16
16
|
constructor(cfg: CommonDaoCfg<BM, DBM, ID>);
|
|
17
17
|
create(part?: Partial<BM>, opt?: CommonDaoOptions): BM;
|
|
18
|
-
getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
19
18
|
getById(id?: ID | null, opt?: CommonDaoOptions): Promise<BM | null>;
|
|
20
19
|
getByIdOrEmpty(id: ID, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<BM>;
|
|
21
|
-
getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
22
20
|
getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>;
|
|
23
21
|
getByIds(ids: ID[], opt?: CommonDaoOptions): Promise<BM[]>;
|
|
24
22
|
getByIdsAsDBM(ids: ID[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
@@ -53,6 +53,10 @@ class CommonDao {
|
|
|
53
53
|
this.assignIdCreatedUpdated(bm, opt);
|
|
54
54
|
return this.validateAndConvert(bm, this.cfg.bmSchema, undefined, opt);
|
|
55
55
|
}
|
|
56
|
+
// GET
|
|
57
|
+
// overrides are disabled now, as they obfuscate errors when ID branded type is used
|
|
58
|
+
// async getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
59
|
+
// async getById(id?: ID | null, opt?: CommonDaoOptions): Promise<BM | null>
|
|
56
60
|
async getById(id, opt = {}) {
|
|
57
61
|
if (!id)
|
|
58
62
|
return null;
|
|
@@ -73,6 +77,8 @@ class CommonDao {
|
|
|
73
77
|
return bm;
|
|
74
78
|
return this.create({ ...part, id }, opt);
|
|
75
79
|
}
|
|
80
|
+
// async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
81
|
+
// async getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>
|
|
76
82
|
async getByIdAsDBM(id, opt = {}) {
|
|
77
83
|
if (!id)
|
|
78
84
|
return null;
|
|
@@ -36,4 +36,12 @@ export interface CommonKeyValueDB {
|
|
|
36
36
|
streamValues: (table: string, limit?: number) => ReadableTyped<Buffer>;
|
|
37
37
|
streamEntries: (table: string, limit?: number) => ReadableTyped<KeyValueDBTuple>;
|
|
38
38
|
count: (table: string) => Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* Increments the value of a key in a table by a given amount.
|
|
42
|
+
* Default increment is 1 when `by` is not provided.
|
|
43
|
+
*
|
|
44
|
+
* Returns the new value.
|
|
45
|
+
*/
|
|
46
|
+
increment: (table: string, id: string, by?: number) => Promise<number>;
|
|
39
47
|
}
|
|
@@ -62,4 +62,11 @@ export declare class CommonKeyValueDao<T> {
|
|
|
62
62
|
streamIds(limit?: number): ReadableTyped<string>;
|
|
63
63
|
streamValues(limit?: number): ReadableTyped<T>;
|
|
64
64
|
streamEntries(limit?: number): ReadableTyped<KeyValueTuple<string, T>>;
|
|
65
|
+
/**
|
|
66
|
+
* Increments the `id` field by the amount specified in `by`,
|
|
67
|
+
* or by 1 if `by` is not specified.
|
|
68
|
+
*
|
|
69
|
+
* Returns the new value of the field.
|
|
70
|
+
*/
|
|
71
|
+
increment(id: string, by?: number): Promise<number>;
|
|
65
72
|
}
|
|
@@ -157,5 +157,14 @@ class CommonKeyValueDao {
|
|
|
157
157
|
concurrency: 32,
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Increments the `id` field by the amount specified in `by`,
|
|
162
|
+
* or by 1 if `by` is not specified.
|
|
163
|
+
*
|
|
164
|
+
* Returns the new value of the field.
|
|
165
|
+
*/
|
|
166
|
+
async increment(id, by = 1) {
|
|
167
|
+
return await this.cfg.db.increment(this.cfg.table, id, by);
|
|
168
|
+
}
|
|
160
169
|
}
|
|
161
170
|
exports.CommonKeyValueDao = CommonKeyValueDao;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runCommonDaoTest } from './daoTest';
|
|
2
2
|
import { CommonDBImplementationQuirks, runCommonDBTest } from './dbTest';
|
|
3
|
+
import { runCommonKeyValueDaoTest } from './keyValueDaoTest';
|
|
3
4
|
import { runCommonKeyValueDBTest } from './keyValueDBTest';
|
|
4
5
|
import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, TestItemBM, testItemBMJsonSchema, testItemBMSchema, TestItemDBM, TestItemTM, testItemTMSchema } from './test.model';
|
|
5
6
|
export type { CommonDBImplementationQuirks, TestItemBM, TestItemDBM, TestItemTM };
|
|
6
|
-
export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, };
|
|
7
|
+
export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDaoTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, };
|
package/dist/testing/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.testItemTMSchema = exports.testItemBMSchema = exports.testItemBMJsonSchema = exports.TEST_TABLE = exports.runCommonKeyValueDBTest = exports.runCommonDBTest = exports.runCommonDaoTest = exports.createTestItemsDBM = exports.createTestItemsBM = exports.createTestItemDBM = exports.createTestItemBM = void 0;
|
|
3
|
+
exports.testItemTMSchema = exports.testItemBMSchema = exports.testItemBMJsonSchema = exports.TEST_TABLE = exports.runCommonKeyValueDBTest = exports.runCommonKeyValueDaoTest = exports.runCommonDBTest = exports.runCommonDaoTest = exports.createTestItemsDBM = exports.createTestItemsBM = exports.createTestItemDBM = exports.createTestItemBM = void 0;
|
|
4
4
|
const daoTest_1 = require("./daoTest");
|
|
5
5
|
Object.defineProperty(exports, "runCommonDaoTest", { enumerable: true, get: function () { return daoTest_1.runCommonDaoTest; } });
|
|
6
6
|
const dbTest_1 = require("./dbTest");
|
|
7
7
|
Object.defineProperty(exports, "runCommonDBTest", { enumerable: true, get: function () { return dbTest_1.runCommonDBTest; } });
|
|
8
|
+
const keyValueDaoTest_1 = require("./keyValueDaoTest");
|
|
9
|
+
Object.defineProperty(exports, "runCommonKeyValueDaoTest", { enumerable: true, get: function () { return keyValueDaoTest_1.runCommonKeyValueDaoTest; } });
|
|
8
10
|
const keyValueDBTest_1 = require("./keyValueDBTest");
|
|
9
11
|
Object.defineProperty(exports, "runCommonKeyValueDBTest", { enumerable: true, get: function () { return keyValueDBTest_1.runCommonKeyValueDBTest; } });
|
|
10
12
|
const test_model_1 = require("./test.model");
|
|
@@ -6,6 +6,18 @@ const test_model_1 = require("./test.model");
|
|
|
6
6
|
const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
|
|
7
7
|
const testEntries = testIds.map(id => [id, Buffer.from(`${id}value`)]);
|
|
8
8
|
function runCommonKeyValueDBTest(db) {
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
// Tests in this suite are not isolated,
|
|
11
|
+
// and failing tests can leave the DB in an unexpected state for other tests,
|
|
12
|
+
// including the following test run.
|
|
13
|
+
// Here we clear the table before running the tests.
|
|
14
|
+
const ids = await db.streamIds(test_model_1.TEST_TABLE).toArray();
|
|
15
|
+
await db.deleteByIds(test_model_1.TEST_TABLE, ids);
|
|
16
|
+
});
|
|
17
|
+
afterAll(async () => {
|
|
18
|
+
const ids = await db.streamIds(test_model_1.TEST_TABLE).toArray();
|
|
19
|
+
await db.deleteByIds(test_model_1.TEST_TABLE, ids);
|
|
20
|
+
});
|
|
9
21
|
test('ping', async () => {
|
|
10
22
|
await db.ping();
|
|
11
23
|
});
|
|
@@ -70,4 +82,16 @@ function runCommonKeyValueDBTest(db) {
|
|
|
70
82
|
const results = await db.getByIds(test_model_1.TEST_TABLE, testIds);
|
|
71
83
|
expect(results).toEqual([]);
|
|
72
84
|
});
|
|
85
|
+
test('increment on a non-existing field should set the value to 1', async () => {
|
|
86
|
+
const result = await db.increment(test_model_1.TEST_TABLE, 'nonExistingField');
|
|
87
|
+
expect(result).toBe(1);
|
|
88
|
+
});
|
|
89
|
+
test('increment on a existing field should increase the value by one', async () => {
|
|
90
|
+
const result = await db.increment(test_model_1.TEST_TABLE, 'nonExistingField');
|
|
91
|
+
expect(result).toBe(2);
|
|
92
|
+
});
|
|
93
|
+
test('increment should increase the value by the specified amount', async () => {
|
|
94
|
+
const result = await db.increment(test_model_1.TEST_TABLE, 'nonExistingField', 2);
|
|
95
|
+
expect(result).toBe(4);
|
|
96
|
+
});
|
|
73
97
|
}
|
|
@@ -5,6 +5,18 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
|
|
6
6
|
const testEntries = testIds.map(id => [id, Buffer.from(`${id}value`)]);
|
|
7
7
|
function runCommonKeyValueDaoTest(dao) {
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
// Tests in this suite are not isolated,
|
|
10
|
+
// and failing tests can leave the DB in an unexpected state for other tests,
|
|
11
|
+
// including the following test run.
|
|
12
|
+
// Here we clear the table before running the tests.
|
|
13
|
+
const ids = await dao.streamIds().toArray();
|
|
14
|
+
await dao.deleteByIds(ids);
|
|
15
|
+
});
|
|
16
|
+
afterAll(async () => {
|
|
17
|
+
const ids = await dao.streamIds().toArray();
|
|
18
|
+
await dao.deleteByIds(ids);
|
|
19
|
+
});
|
|
8
20
|
test('ping', async () => {
|
|
9
21
|
await dao.ping();
|
|
10
22
|
});
|
|
@@ -63,4 +75,16 @@ function runCommonKeyValueDaoTest(dao) {
|
|
|
63
75
|
const results = await dao.getByIds(testIds);
|
|
64
76
|
expect(results).toEqual([]);
|
|
65
77
|
});
|
|
78
|
+
test('increment on a non-existing field should set the value to 1', async () => {
|
|
79
|
+
const result = await dao.increment('nonExistingField');
|
|
80
|
+
expect(result).toBe(1);
|
|
81
|
+
});
|
|
82
|
+
test('increment on a existing field should increase the value by one', async () => {
|
|
83
|
+
const result = await dao.increment('nonExistingField');
|
|
84
|
+
expect(result).toBe(2);
|
|
85
|
+
});
|
|
86
|
+
test('increment should increase the value by the specified amount', async () => {
|
|
87
|
+
const result = await dao.increment('nonExistingField', 2);
|
|
88
|
+
expect(result).toBe(4);
|
|
89
|
+
});
|
|
66
90
|
}
|
package/package.json
CHANGED
|
@@ -47,4 +47,14 @@ export class InMemoryKeyValueDB implements CommonKeyValueDB {
|
|
|
47
47
|
this.data[table] ||= {}
|
|
48
48
|
return Object.keys(this.data[table]).length
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
async increment(table: string, id: string, by = 1): Promise<number> {
|
|
52
|
+
this.data[table] ||= {}
|
|
53
|
+
|
|
54
|
+
const currentValue = this.data[table][id] ? parseInt(this.data[table][id].toString()) : 0
|
|
55
|
+
const newValue = currentValue + by
|
|
56
|
+
this.data[table][id] = Buffer.from(String(newValue))
|
|
57
|
+
|
|
58
|
+
return newValue
|
|
59
|
+
}
|
|
50
60
|
}
|
|
@@ -112,8 +112,9 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
// GET
|
|
115
|
-
|
|
116
|
-
async getById(id
|
|
115
|
+
// overrides are disabled now, as they obfuscate errors when ID branded type is used
|
|
116
|
+
// async getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
117
|
+
// async getById(id?: ID | null, opt?: CommonDaoOptions): Promise<BM | null>
|
|
117
118
|
async getById(id?: ID | null, opt: CommonDaoOptions = {}): Promise<BM | null> {
|
|
118
119
|
if (!id) return null
|
|
119
120
|
const op = `getById(${id})`
|
|
@@ -137,8 +138,8 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
137
138
|
return this.create({ ...part, id }, opt)
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
141
|
-
async getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>
|
|
141
|
+
// async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
142
|
+
// async getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>
|
|
142
143
|
async getByIdAsDBM(id?: ID | null, opt: CommonDaoOptions = {}): Promise<DBM | null> {
|
|
143
144
|
if (!id) return null
|
|
144
145
|
const op = `getByIdAsDBM(${id})`
|
|
@@ -49,4 +49,13 @@ export interface CommonKeyValueDB {
|
|
|
49
49
|
streamEntries: (table: string, limit?: number) => ReadableTyped<KeyValueDBTuple>
|
|
50
50
|
|
|
51
51
|
count: (table: string) => Promise<number>
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* Increments the value of a key in a table by a given amount.
|
|
56
|
+
* Default increment is 1 when `by` is not provided.
|
|
57
|
+
*
|
|
58
|
+
* Returns the new value.
|
|
59
|
+
*/
|
|
60
|
+
increment: (table: string, id: string, by?: number) => Promise<number>
|
|
52
61
|
}
|
|
@@ -252,4 +252,14 @@ export class CommonKeyValueDao<T> {
|
|
|
252
252
|
},
|
|
253
253
|
)
|
|
254
254
|
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Increments the `id` field by the amount specified in `by`,
|
|
258
|
+
* or by 1 if `by` is not specified.
|
|
259
|
+
*
|
|
260
|
+
* Returns the new value of the field.
|
|
261
|
+
*/
|
|
262
|
+
async increment(id: string, by = 1): Promise<number> {
|
|
263
|
+
return await this.cfg.db.increment(this.cfg.table, id, by)
|
|
264
|
+
}
|
|
255
265
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { runCommonDaoTest } from './daoTest'
|
|
2
2
|
import { CommonDBImplementationQuirks, runCommonDBTest } from './dbTest'
|
|
3
|
+
import { runCommonKeyValueDaoTest } from './keyValueDaoTest'
|
|
3
4
|
import { runCommonKeyValueDBTest } from './keyValueDBTest'
|
|
4
5
|
import {
|
|
5
6
|
createTestItemBM,
|
|
@@ -24,6 +25,7 @@ export {
|
|
|
24
25
|
createTestItemsDBM,
|
|
25
26
|
runCommonDaoTest,
|
|
26
27
|
runCommonDBTest,
|
|
28
|
+
runCommonKeyValueDaoTest,
|
|
27
29
|
runCommonKeyValueDBTest,
|
|
28
30
|
TEST_TABLE,
|
|
29
31
|
testItemBMJsonSchema,
|
|
@@ -7,6 +7,20 @@ const testIds = _range(1, 4).map(n => `id${n}`)
|
|
|
7
7
|
const testEntries: KeyValueDBTuple[] = testIds.map(id => [id, Buffer.from(`${id}value`)])
|
|
8
8
|
|
|
9
9
|
export function runCommonKeyValueDBTest(db: CommonKeyValueDB): void {
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
// Tests in this suite are not isolated,
|
|
12
|
+
// and failing tests can leave the DB in an unexpected state for other tests,
|
|
13
|
+
// including the following test run.
|
|
14
|
+
// Here we clear the table before running the tests.
|
|
15
|
+
const ids = await db.streamIds(TEST_TABLE).toArray()
|
|
16
|
+
await db.deleteByIds(TEST_TABLE, ids)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
const ids = await db.streamIds(TEST_TABLE).toArray()
|
|
21
|
+
await db.deleteByIds(TEST_TABLE, ids)
|
|
22
|
+
})
|
|
23
|
+
|
|
10
24
|
test('ping', async () => {
|
|
11
25
|
await db.ping()
|
|
12
26
|
})
|
|
@@ -85,4 +99,19 @@ export function runCommonKeyValueDBTest(db: CommonKeyValueDB): void {
|
|
|
85
99
|
const results = await db.getByIds(TEST_TABLE, testIds)
|
|
86
100
|
expect(results).toEqual([])
|
|
87
101
|
})
|
|
102
|
+
|
|
103
|
+
test('increment on a non-existing field should set the value to 1', async () => {
|
|
104
|
+
const result = await db.increment(TEST_TABLE, 'nonExistingField')
|
|
105
|
+
expect(result).toBe(1)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('increment on a existing field should increase the value by one', async () => {
|
|
109
|
+
const result = await db.increment(TEST_TABLE, 'nonExistingField')
|
|
110
|
+
expect(result).toBe(2)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('increment should increase the value by the specified amount', async () => {
|
|
114
|
+
const result = await db.increment(TEST_TABLE, 'nonExistingField', 2)
|
|
115
|
+
expect(result).toBe(4)
|
|
116
|
+
})
|
|
88
117
|
}
|
|
@@ -6,6 +6,20 @@ const testIds = _range(1, 4).map(n => `id${n}`)
|
|
|
6
6
|
const testEntries: KeyValueDBTuple[] = testIds.map(id => [id, Buffer.from(`${id}value`)])
|
|
7
7
|
|
|
8
8
|
export function runCommonKeyValueDaoTest(dao: CommonKeyValueDao<Buffer>): void {
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
// Tests in this suite are not isolated,
|
|
11
|
+
// and failing tests can leave the DB in an unexpected state for other tests,
|
|
12
|
+
// including the following test run.
|
|
13
|
+
// Here we clear the table before running the tests.
|
|
14
|
+
const ids = await dao.streamIds().toArray()
|
|
15
|
+
await dao.deleteByIds(ids)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
afterAll(async () => {
|
|
19
|
+
const ids = await dao.streamIds().toArray()
|
|
20
|
+
await dao.deleteByIds(ids)
|
|
21
|
+
})
|
|
22
|
+
|
|
9
23
|
test('ping', async () => {
|
|
10
24
|
await dao.ping()
|
|
11
25
|
})
|
|
@@ -76,4 +90,19 @@ export function runCommonKeyValueDaoTest(dao: CommonKeyValueDao<Buffer>): void {
|
|
|
76
90
|
const results = await dao.getByIds(testIds)
|
|
77
91
|
expect(results).toEqual([])
|
|
78
92
|
})
|
|
93
|
+
|
|
94
|
+
test('increment on a non-existing field should set the value to 1', async () => {
|
|
95
|
+
const result = await dao.increment('nonExistingField')
|
|
96
|
+
expect(result).toBe(1)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('increment on a existing field should increase the value by one', async () => {
|
|
100
|
+
const result = await dao.increment('nonExistingField')
|
|
101
|
+
expect(result).toBe(2)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('increment should increase the value by the specified amount', async () => {
|
|
105
|
+
const result = await dao.increment('nonExistingField', 2)
|
|
106
|
+
expect(result).toBe(4)
|
|
107
|
+
})
|
|
79
108
|
}
|