UNPKG

3.09 kBJavaScriptView Raw
1var t = require('../test-lib/test.js');
2var assert = require('assert');
3
4describe('Caches', function() {
5
6 after(function(done) {
7 return t.destroy(apos, done);
8 });
9
10 this.timeout(t.timeout);
11
12 var apos;
13 var cache;
14 it('should exist on the apos object', function(done) {
15 apos = require('../index.js')({
16 root: module,
17 shortName: 'test',
18
19 modules: {
20 'apostrophe-express': {
21 secret: 'xxx',
22 port: 7900,
23 csrf: false
24 }
25 },
26
27 afterInit: function(callback) {
28 assert(apos.caches);
29 apos.argv._ = [];
30 return callback(null);
31 },
32
33 afterListen: function(err) {
34 console.error(err);
35 assert(!err);
36 return done();
37 }
38 });
39 });
40 it('should give us a cache object', function() {
41 cache = apos.caches.get('testMonkeys');
42 });
43 it('should not crash on clear', function(done) {
44 cache.clear(done);
45 });
46 it('should not contain capuchin yet', function(done) {
47 return cache.get('capuchin', function(err, monkey) {
48 assert(!err);
49 assert(!monkey);
50 return done();
51 });
52 });
53 it('should allow us to store capuchin', function(done) {
54 return cache.set('capuchin', { message: 'eek eek' }, function(err) {
55 assert(!err);
56 return done();
57 });
58 });
59 it('should now contain capuchin', function(done) {
60 return cache.get('capuchin', function(err, monkey) {
61 assert(!err);
62 assert(monkey);
63 assert(monkey.message === 'eek eek');
64 return done();
65 });
66 });
67 it('should not crash on clear #2', function(done) {
68 cache.clear(done);
69 });
70 it('should not contain capuchin anymore', function(done) {
71 return cache.get('capuchin', function(err, monkey) {
72 assert(!err);
73 assert(!monkey);
74 return done();
75 });
76 });
77
78 it('should not crash on clear with promise', function() {
79 return cache.clear();
80 });
81 it('should not contain capuchin yet', function() {
82 return cache.get('capuchin')
83 .then(function(monkey) {
84 assert(!monkey);
85 return true;
86 });
87 });
88 it('should allow us to store capuchin', function() {
89 return cache.set('capuchin', { message: 'eek eek' });
90 });
91 it('should now contain capuchin', function() {
92 return cache.get('capuchin')
93 .then(function(monkey) {
94 assert(monkey);
95 assert(monkey.message === 'eek eek');
96 return true;
97 });
98 });
99 it('should allow us to store a value with a lifetime using a promise', function() {
100 return cache.set('colobus', { message: 'oop oop' }, 86400);
101 });
102 it('should now contain colobus', function() {
103 return cache.get('colobus')
104 .then(function(monkey) {
105 assert(monkey);
106 assert(monkey.message === 'oop oop');
107 return true;
108 });
109 });
110 it('should not crash on clear #2', function() {
111 return cache.clear();
112 });
113 it('should not contain capuchin anymore', function() {
114 return cache.get('capuchin')
115 .then(function(monkey) {
116 assert(!monkey);
117 return true;
118 });
119 });
120});