spec.plugins.session.js
This file
Path
spec/spec.plugins.session.js
102 lines · 3.1 KiB · JavaScript
Last changed by
Merge branch 'session-count'visionmediabefore adoptione083321
History of this fileTake it
Started Session pluginvisionmediabefore adoption7238afb
lines 1–5why, one step back12describe 'Express'3 before_each4 reset()5 use(require('express/plugins/cookie').Cookie)Fixed sessions when testingvisionmediabefore adoption4d5a1b5
lines 6–7why, one step back6 use(Session = require('express/plugins/session').Session)7 Session.store.clear()Started Session pluginvisionmediabefore adoption7238afb
lines 8–10why, one step back8 end9 10 describe 'Session'Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03
lines 11–24why, one step back11 describe 'when sid cookie is not present'12 it 'should set sid cookie'13 get('/login', function(){ return '' })14 get('/login').headers['set-cookie'].should.match(/^sid=(\w+);/)15 end16 end17 18 describe 'when sid cookie is present'19 it 'should not set sid'20 get('/login', function(){ return '' })21 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'set-cookie'22 end23 end24 Added session reapingvisionmediabefore adoption8ed99f6
lines 25–29why, one step back25 describe 'MemoryStore'26 before_each27 memory = new (require('express/plugins/session').MemoryStore)28 end29 Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03
lines 30–41why, one step back30 it 'should persist'31 post('/login', function(){32 return this.session.name = 'tj'33 })34 get('/login', function(){35 return this.session.name36 })37 var headers = { headers: { cookie: 'sid=123' }}38 post('/login', headers)39 get('/login', headers).status.should.eql 20040 get('/login', headers).body.should.eql 'tj'41 endAdded session reapingvisionmediabefore adoption8ed99f6
lines 42–67why, one step back42 43 describe '#fetch()'44 describe 'when the session does not exist'45 it 'should return a new Session'46 memory.fetch('1').should.have_property 'lastAccess'47 end48 end49 50 describe 'when the session does exist'51 it 'should return the previous session'52 memory.commit({ id: '1', same: true })53 memory.fetch('1').should.have_property 'same', true54 end55 end56 end57 58 describe '#clear()'59 it 'should remove all sessions'60 memory.commit({ id: '1' })61 memory.commit({ id: '2' })62 memory.clear()63 memory.should.not.have_property '1'64 memory.should.not.have_property '2'65 end66 end67 Merge branch 'session-count'visionmediabefore adoptione083321
lines 68–75why, one step back68 describe '#length()'69 it 'should return the number of session'70 memory.commit({ id: '1' })71 memory.commit({ id: '2' })72 memory.length().should.eql 273 end74 end75 Added session reapingvisionmediabefore adoption8ed99f6
lines 76–98why, one step back76 describe '#destroy()'77 it 'should destroy a single session'78 memory.commit({ id: '1' })79 memory.commit({ id: '2' })80 memory.destroy('1')81 memory.store.should.not.have_property '1'82 memory.store.should.have_property '2'83 end84 end85 86 describe '#reap()'87 it 'should destroy sessions older than the given age in milliseconds'88 memory.commit({ id: '1', lastAccess: Number(new Date) - 300 })89 memory.commit({ id: '2', lastAccess: Number(new Date) - 250 })90 memory.commit({ id: '3', lastAccess: Number(new Date) - 100 })91 memory.commit({ id: '4', lastAccess: Number(new Date) })92 memory.reap(200)93 memory.store.should.not.have_property '1'94 memory.store.should.not.have_property '2'95 memory.store.should.have_property '3'96 memory.store.should.have_property '4'97 end98 endStarted Session pluginvisionmediabefore adoption7238afb
line 99why, one step back99 endAdded session reapingvisionmediabefore adoption8ed99f6
line 100why, one step back100 Started Session pluginvisionmediabefore adoption7238afb
lines 101–102why, one step back101 end102end