spec.plugins.session.js
This file
Path
spec/spec.plugins.session.js
107 lines · 3.2 KiB · JavaScript
Last changed by
Auto use(Cookie) when use(Session). Closes #183visionmediabefore adoption1f76d5c
History of this fileTake it
Started Session pluginvisionmediabefore adoption7238afb
lines 1–4why, one step back12describe 'Express'3 before_each4 reset()Fixed sessions when testingvisionmediabefore adoption4d5a1b5
lines 5–6why, one step back5 use(Session = require('express/plugins/session').Session)6 Session.store.clear()Started Session pluginvisionmediabefore adoption7238afb
lines 7–9why, one step back7 end8 9 describe 'Session'Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03
lines 10–23why, one step back10 describe 'when sid cookie is not present'11 it 'should set sid cookie'12 get('/login', function(){ return '' })13 get('/login').headers['set-cookie'].should.match(/^sid=(\w+);/)14 end15 end16 17 describe 'when sid cookie is present'18 it 'should not set sid'19 get('/login', function(){ return '' })20 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'set-cookie'21 end22 end23 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
line 24why, one step back24 describe 'session Store.Memory'Added session reapingvisionmediabefore adoption8ed99f6
line 25why, one step back25 before_eachRenamed MemoryStore -> Store.Memoryvisionmediabefore adoption542cab1
line 26why, one step back26 memory = new (require('express/plugins/session').Store.Memory)Added session reapingvisionmediabefore adoption8ed99f6
lines 27–28why, one step back27 end28 Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03
lines 29–40why, one step back29 it 'should persist'30 post('/login', function(){31 return this.session.name = 'tj'32 })33 get('/login', function(){34 return this.session.name35 })36 var headers = { headers: { cookie: 'sid=123' }}37 post('/login', headers)38 get('/login', headers).status.should.eql 20039 get('/login', headers).body.should.eql 'tj'40 endAdded session reapingvisionmediabefore adoption8ed99f6
line 41why, one step back41 Merge branch 'abstract-session'visionmediabefore adoption315c050
lines 42–47why, one step back42 describe '#toString()'43 it 'should return [Memory Store]'44 memory.toString().should.eql '[Memory Store]'45 end46 end47 Added session reapingvisionmediabefore adoption8ed99f6
lines 48–72why, one step back48 describe '#fetch()'49 describe 'when the session does not exist'50 it 'should return a new Session'51 memory.fetch('1').should.have_property 'lastAccess'52 end53 end54 55 describe 'when the session does exist'56 it 'should return the previous session'57 memory.commit({ id: '1', same: true })58 memory.fetch('1').should.have_property 'same', true59 end60 end61 end62 63 describe '#clear()'64 it 'should remove all sessions'65 memory.commit({ id: '1' })66 memory.commit({ id: '2' })67 memory.clear()68 memory.should.not.have_property '1'69 memory.should.not.have_property '2'70 end71 end72 Merge branch 'session-count'visionmediabefore adoptione083321
lines 73–80why, one step back73 describe '#length()'74 it 'should return the number of session'75 memory.commit({ id: '1' })76 memory.commit({ id: '2' })77 memory.length().should.eql 278 end79 end80 Added session reapingvisionmediabefore adoption8ed99f6
lines 81–103why, one step back81 describe '#destroy()'82 it 'should destroy a single session'83 memory.commit({ id: '1' })84 memory.commit({ id: '2' })85 memory.destroy('1')86 memory.store.should.not.have_property '1'87 memory.store.should.have_property '2'88 end89 end90 91 describe '#reap()'92 it 'should destroy sessions older than the given age in milliseconds'93 memory.commit({ id: '1', lastAccess: Number(new Date) - 300 })94 memory.commit({ id: '2', lastAccess: Number(new Date) - 250 })95 memory.commit({ id: '3', lastAccess: Number(new Date) - 100 })96 memory.commit({ id: '4', lastAccess: Number(new Date) })97 memory.reap(200)98 memory.store.should.not.have_property '1'99 memory.store.should.not.have_property '2'100 memory.store.should.have_property '3'101 memory.store.should.have_property '4'102 end103 endStarted Session pluginvisionmediabefore adoption7238afb
line 104why, one step back104 endAdded session reapingvisionmediabefore adoption8ed99f6
line 105why, one step back105 Started Session pluginvisionmediabefore adoption7238afb
lines 106–107why, one step back106 end107end