spec.plugins.cache.js
This file
Path
spec/spec.plugins.cache.js
120 lines · 3.1 KiB · JavaScript
Last changed by
Added memory store specsvisionmediabefore adoptionf2d08aa
History of this fileTake it
Started caching apivisionmediabefore adoptionc161750
lines 1–4why, one step back12describe 'Express'3 before_each4 reset()Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 5–6why, one step back5 use(require('express/plugins/cache').Cache)6 cache = require('express/plugins/cache')Started caching apivisionmediabefore adoptionc161750
lines 7–16why, one step back7 end8 9 describe 'Cache'10 describe 'Request'11 describe '#cache'12 it 'should use memory store by default'13 get('/item', function(){14 return this.cache.toString()15 })16 get('/item').body.should.eql '[Memory Store]'Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 17–23why, one step back17 end18 end19 end20 end21 22 describe 'Store'23 describe 'Memory'Added memory store specsvisionmediabefore adoptionf2d08aa
lines 24–27why, one step back24 before_each25 store = new cache.Store.Memory26 end27 Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 28–29why, one step back28 describe '#toString()'29 it 'should return [Memory Store]'Added memory store specsvisionmediabefore adoptionf2d08aa
line 30why, one step back30 store.toString().should.eql '[Memory Store]'Started caching apivisionmediabefore adoptionc161750
lines 31–32why, one step back31 end32 endAdded memory store specsvisionmediabefore adoptionf2d08aa
lines 33–117why, one step back33 34 describe '#set()'35 describe 'given a key and value'36 it 'should set the cache data'37 store.set('foo', 'bar')38 store.get('foo').should.eql 'bar'39 end40 41 it 'should override existing data'42 store.set('foo', 'bar')43 store.set('foo', 'baz')44 store.get('foo').should.eql 'baz'45 end46 end47 48 describe 'given a key only'49 it 'should delete previous data'50 store.set('foo', 'bar')51 store.set('foo')52 store.get('foo').should.be_null53 end54 end55 56 describe 'given an abitrary key'57 it 'should throw an error'58 -{ store.set({}, 'foo') }.should.throw_error59 end60 end61 62 describe 'given an abitrary value'63 it 'should throw an error'64 -{ store.set('foo', {}) }.should.throw_error65 end66 end67 end68 69 describe '#get()'70 describe 'given a key'71 it 'should return cached value'72 store.set('foo', 'bar')73 store.get('foo').should.eql 'bar'74 end75 end76 77 describe 'given wildcards'78 it 'should return a set of caches'79 store.set('user:1', 'a')80 store.set('user:2', 'b')81 store.set('foo', 'bar')82 store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' }83 end84 end85 end86 87 describe '#clear()'88 describe 'given a key'89 it 'should delete previous data'90 store.set('foo', 'bar')91 store.clear('foo')92 store.get('foo').should.be_null93 end94 95 it 'should return deleted data'96 store.set('foo', 'bar')97 store.clear('foo').should.eql 'bar'98 end99 end100 101 describe 'given wildcards'102 it 'should clear a set of caches'103 store.set('user:one', '1')104 store.set('user:two', '2')105 store.clear('user:*')106 store.get('user:one').should.be_null107 store.get('user:two').should.be_null108 end109 110 it 'should return deleted data'111 store.set('user:one', '1')112 store.set('user:two', '2')113 store.clear('user:*').should.eql { 'user:one': '1', 'user:two': '2' }114 end115 end116 end117 Started caching apivisionmediabefore adoptionc161750
lines 118–120why, one step back118 end119 end120end