@@ -540,3 +540,139 @@ test('should save the session', async (t) => {
540540
541541 t . is ( response . statusCode , 200 )
542542} )
543+
544+ test ( 'destroy supports promises' , async t => {
545+ t . plan ( 2 )
546+ const port = await testServer ( async ( request , reply ) => {
547+ await t . notThrowsAsync ( request . session . destroy ( ) )
548+
549+ reply . send ( 200 )
550+ } , DEFAULT_OPTIONS )
551+
552+ const { response } = await request ( `http://localhost:${ port } ` )
553+
554+ t . is ( response . statusCode , 200 )
555+ } )
556+
557+ test ( 'destroy supports rejecting promises' , async t => {
558+ t . plan ( 2 )
559+ const port = await testServer ( async ( request , reply ) => {
560+ await t . throwsAsync ( request . session . destroy ( ) , { message : 'no can do' } )
561+
562+ reply . send ( 200 )
563+ } , {
564+ ...DEFAULT_OPTIONS ,
565+ store : {
566+ set ( id , data , cb ) { cb ( null ) } ,
567+ get ( id , cb ) { cb ( null ) } ,
568+ destroy ( id , cb ) { cb ( new Error ( 'no can do' ) ) }
569+ }
570+ } )
571+
572+ const { response } = await request ( `http://localhost:${ port } ` )
573+
574+ // 200 since we assert inline and swallow the error
575+ t . is ( response . statusCode , 200 )
576+ } )
577+
578+ test ( 'regenerate supports promises' , async t => {
579+ t . plan ( 2 )
580+ const port = await testServer ( async ( request , reply ) => {
581+ await t . notThrowsAsync ( request . session . regenerate ( ) )
582+
583+ reply . send ( 200 )
584+ } , DEFAULT_OPTIONS )
585+
586+ const { response } = await request ( `http://localhost:${ port } ` )
587+
588+ t . is ( response . statusCode , 200 )
589+ } )
590+
591+ test ( 'regenerate supports rejecting promises' , async t => {
592+ t . plan ( 2 )
593+ const port = await testServer ( async ( request , reply ) => {
594+ await t . throwsAsync ( request . session . regenerate ( ) , { message : 'no can do' } )
595+
596+ reply . send ( 200 )
597+ } , {
598+ ...DEFAULT_OPTIONS ,
599+ store : {
600+ set ( id , data , cb ) { cb ( new Error ( 'no can do' ) ) } ,
601+ get ( id , cb ) { cb ( null ) } ,
602+ destroy ( id , cb ) { cb ( null ) }
603+ }
604+ } )
605+
606+ const { response } = await request ( `http://localhost:${ port } ` )
607+
608+ // 200 since we assert inline and swallow the error
609+ t . is ( response . statusCode , 200 )
610+ } )
611+
612+ test ( 'reload supports promises' , async t => {
613+ t . plan ( 2 )
614+ const port = await testServer ( async ( request , reply ) => {
615+ await t . notThrowsAsync ( request . session . reload ( ) )
616+
617+ reply . send ( 200 )
618+ } , DEFAULT_OPTIONS )
619+
620+ const { response } = await request ( `http://localhost:${ port } ` )
621+
622+ t . is ( response . statusCode , 200 )
623+ } )
624+
625+ test ( 'reload supports rejecting promises' , async t => {
626+ t . plan ( 2 )
627+ const port = await testServer ( async ( request , reply ) => {
628+ await t . throwsAsync ( request . session . reload ( ) , { message : 'no can do' } )
629+
630+ reply . send ( 200 )
631+ } , {
632+ ...DEFAULT_OPTIONS ,
633+ store : {
634+ set ( id , data , cb ) { cb ( null ) } ,
635+ get ( id , cb ) { cb ( new Error ( 'no can do' ) ) } ,
636+ destroy ( id , cb ) { cb ( null ) }
637+ }
638+ } )
639+
640+ const { response } = await request ( `http://localhost:${ port } ` )
641+
642+ // 200 since we assert inline and swallow the error
643+ t . is ( response . statusCode , 200 )
644+ } )
645+
646+ test ( 'save supports promises' , async t => {
647+ t . plan ( 2 )
648+ const port = await testServer ( async ( request , reply ) => {
649+ await t . notThrowsAsync ( request . session . save ( ) )
650+
651+ reply . send ( 200 )
652+ } , DEFAULT_OPTIONS )
653+
654+ const { response } = await request ( `http://localhost:${ port } ` )
655+
656+ t . is ( response . statusCode , 200 )
657+ } )
658+
659+ test ( 'save supports rejecting promises' , async t => {
660+ t . plan ( 2 )
661+ const port = await testServer ( async ( request , reply ) => {
662+ await t . throwsAsync ( request . session . save ( ) )
663+
664+ reply . send ( 200 )
665+ } , {
666+ ...DEFAULT_OPTIONS ,
667+ store : {
668+ set ( id , data , cb ) { cb ( new Error ( 'no can do' ) ) } ,
669+ get ( id , cb ) { cb ( null ) } ,
670+ save ( id , cb ) { cb ( null ) }
671+ }
672+ } )
673+
674+ const { response } = await request ( `http://localhost:${ port } ` )
675+
676+ // 200 since we assert inline and swallow the error
677+ t . is ( response . statusCode , 200 )
678+ } )
0 commit comments