UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

30 lines (26 loc) 923 B
const ResourceCache = require('../../../../src/cache/classes/resource.cache.class'); class Value { #id; constructor(id) { this.#id = id; } getId = () => this.#id; } describe('Check [Resource Cache] class', () => { it('should store in cache when nominal.', async () => { const cache = new ResourceCache('r', Value, 1); await cache.set(3, new Value(3)); expect(cache.getSize()).toEqual(1); expect(cache.has(3)).toBeTruthy(); const stored = await cache.get(3); expect(stored.getId()).toEqual(3); cache.reset(); expect(cache.getSize()).toEqual(0); }); it('should reject when cache is full.', async () => { const cache = new ResourceCache('r', Value, 1); await cache.set(3, new Value(3)); expect(cache.getSize()).toEqual(1); expect(cache.set(4, new Value(4))).rejects.toThrow('The [r cache] CANNOT be greater than 1.'); }); });