-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the api cache and refactor
Signed-off-by: Axel Boberg <[email protected]>
- Loading branch information
1 parent
cc1f3d0
commit 7eb8f29
Showing
2 changed files
with
45 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-FileCopyrightText: 2022 Sveriges Television AB | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
const Cache = require('./Cache') | ||
const cache = new Cache(5) | ||
|
||
test('cache a provider', () => { | ||
cache.cache('myKey', () => 10) | ||
expect(cache.get('myKey')).resolves.toBe(10) | ||
}) | ||
|
||
test('respect the max entry count', () => { | ||
cache.cache('myKey1', () => 10) | ||
cache.cache('myKey2', () => 10) | ||
cache.cache('myKey3', () => 10) | ||
cache.cache('myKey4', () => 10) | ||
cache.cache('myKey5', () => 10) | ||
cache.cache('myKey6', () => 10) | ||
expect(cache.get('myKey1')).resolves.toBe(undefined) | ||
}) |