@@ -11,7 +11,7 @@ const inspect = Symbol.for('nodejs.util.inspect.custom');
11
11
function App ( options : CreateSessionOptions = { } ) {
12
12
const app = new Koa ( ) ;
13
13
app . keys = [ 'a' , 'b' ] ;
14
- options . store = store ;
14
+ options . store = options . store ?? store ;
15
15
app . use ( session ( options , app ) ) ;
16
16
return app ;
17
17
}
@@ -21,14 +21,15 @@ describe('Koa Session External Store', () => {
21
21
22
22
describe ( 'when the session contains a ;' , ( ) => {
23
23
it ( 'should still work' , async ( ) => {
24
- const app = App ( ) ;
24
+ const options : CreateSessionOptions = { store } ;
25
+ const app = App ( options ) ;
25
26
26
27
app . use ( async ( ctx : Koa . Context ) => {
27
28
if ( ctx . method === 'POST' ) {
28
- ctx . session ! . string = ';' ;
29
+ ctx . session . string = ';' ;
29
30
ctx . status = 204 ;
30
31
} else {
31
- ctx . body = ctx . session ! . string ;
32
+ ctx . body = ctx . session . string ;
32
33
}
33
34
} ) ;
34
35
@@ -43,6 +44,37 @@ describe('Koa Session External Store', () => {
43
44
. set ( 'Cookie' , cookie . join ( ';' ) )
44
45
. expect ( ';' ) ;
45
46
} ) ;
47
+
48
+ it ( 'should disable store on options' , async ( ) => {
49
+ const options : CreateSessionOptions = { store } ;
50
+ const app = App ( options ) ;
51
+
52
+ app . use ( async ( ctx : Koa . Context ) => {
53
+ if ( ctx . method === 'POST' ) {
54
+ ctx . session . string = ';' ;
55
+ ctx . status = 204 ;
56
+ } else {
57
+ ctx . body = ctx . session . string ?? 'new session create' ;
58
+ }
59
+ } ) ;
60
+
61
+ const server = app . callback ( ) ;
62
+ const res = await request ( server )
63
+ . post ( '/' )
64
+ . expect ( 204 ) ;
65
+
66
+ const cookie = res . get ( 'Set-Cookie' ) ! ;
67
+ await request ( server )
68
+ . get ( '/' )
69
+ . set ( 'Cookie' , cookie . join ( ';' ) )
70
+ . expect ( ';' ) ;
71
+
72
+ options . store = undefined ;
73
+ await request ( server )
74
+ . get ( '/' )
75
+ . set ( 'Cookie' , cookie . join ( ';' ) )
76
+ . expect ( 'new session create' ) ;
77
+ } ) ;
46
78
} ) ;
47
79
48
80
describe ( 'new session' , ( ) => {
0 commit comments