forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryCacheAdapter.spec.js
More file actions
59 lines (51 loc) · 1.34 KB
/
InMemoryCacheAdapter.spec.js
File metadata and controls
59 lines (51 loc) · 1.34 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
57
58
59
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter')
.default;
describe('InMemoryCacheAdapter', function() {
const KEY = 'hello';
const VALUE = 'world';
function wait(sleep) {
return new Promise(function(resolve) {
setTimeout(resolve, sleep);
});
}
it('should expose promisifyed methods', done => {
const cache = new InMemoryCacheAdapter({
ttl: NaN,
});
// Verify all methods return promises.
Promise.all([
cache.put(KEY, VALUE),
cache.del(KEY),
cache.get(KEY),
cache.clear(),
]).then(() => {
done();
});
});
it('should get/set/clear', done => {
const cache = new InMemoryCacheAdapter({
ttl: NaN,
});
cache
.put(KEY, VALUE)
.then(() => cache.get(KEY))
.then(value => expect(value).toEqual(VALUE))
.then(() => cache.clear())
.then(() => cache.get(KEY))
.then(value => expect(value).toEqual(null))
.then(done);
});
it('should expire after ttl', done => {
const cache = new InMemoryCacheAdapter({
ttl: 10,
});
cache
.put(KEY, VALUE)
.then(() => cache.get(KEY))
.then(value => expect(value).toEqual(VALUE))
.then(wait.bind(null, 50))
.then(() => cache.get(KEY))
.then(value => expect(value).toEqual(null))
.then(done);
});
});