defaultrepo.test.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const expect = require('chai').expect;
const DefaultMemRepo= require('../lib/repo/default.js');
describe('default repo', () => {
let memRepo;
beforeEach(()=>{
memRepo = new DefaultMemRepo();
});
describe('constructor()', ()=>{
it('should create an object and initialize cache property', ()=>{
expect(memRepo.cache).to.be.an.instanceof(Set);
});
});
describe('getByKeys()', () => {
it('should get cache value', (done) => {
memRepo.cache = new Set(['key1','key2','key3']);
memRepo.getByKeys(['key1', 'key4']).then( ([key1, key4]) => {
expect(key1).to.be.true;
expect(key4).to.be.false;
done();
});
});
});
describe('setByKeys()', ()=>{
it('should set cache value to null', (done)=>{
memRepo.cache = new Set(['key1','key2','key3']);
memRepo.setByKeys(['key2','key4']).then( () => {
expect(memRepo.cache.has('key4')).to.be.true;
expect(memRepo.cache.has('key2')).to.be.true;
done();
});
});
});
describe('dispose()', ()=>{
it('should clear cache', (done)=>{
memRepo.cache = new Set(['key1','key2','key3']);
memRepo.getByKeys(['key0', 'key3']).then( ([key0, key3]) => {
expect(key0).to.be.false;
expect(key3).to.be.true;
return memRepo.setByKeys(['key1','key2']);
}).then( () => {
expect(memRepo.cache.has('key1')).to.be.true;
expect(memRepo.cache.has('key2')).to.be.true;
return memRepo.dispose();
}).then(() => {
expect(memRepo.cache).to.be.a('null');
done();
});
});
});
});