-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
increment
to CommonKeyValueDao
- Loading branch information
1 parent
00da6d6
commit e13d94f
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CommonKeyValueDao } from '../kv/commonKeyValueDao' | ||
import { runCommonKeyValueDaoTest } from './keyValueDaoTest' | ||
|
||
export function runCommonHashKeyValueDaoTest(dao: CommonKeyValueDao<Buffer>): void { | ||
beforeAll(async () => { | ||
// Tests in this suite are not isolated, | ||
// and failing tests can leave the DB in an unexpected state for other tests, | ||
// including the following test run. | ||
// Here we clear the table before running the tests. | ||
const ids = await dao.streamIds().toArray() | ||
await dao.deleteByIds(ids) | ||
}) | ||
|
||
afterAll(async () => { | ||
const ids = await dao.streamIds().toArray() | ||
await dao.deleteByIds(ids) | ||
}) | ||
|
||
runCommonKeyValueDaoTest(dao) | ||
|
||
test('increment on a non-existing field should set the value to 1', async () => { | ||
const result = await dao.increment('nonExistingField') | ||
expect(result).toBe(1) | ||
}) | ||
|
||
test('increment on a existing field should increase the value by one', async () => { | ||
const result = await dao.increment('nonExistingField') | ||
expect(result).toBe(2) | ||
}) | ||
|
||
test('increment should increase the value by the specified amount', async () => { | ||
const result = await dao.increment('nonExistingField', 2) | ||
expect(result).toBe(4) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters