This repository was archived by the owner on Jan 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,22 @@ const mockResponse = () => {
99 return res ;
1010} ;
1111
12- test . todo ( 'should pass' )
12+ const { checkAuth } = require ( './express-handlers' ) ;
13+
14+ // describe('login', () => {});
15+ // describe('logout', () => {});
16+ describe ( 'checkAuth' , ( ) => {
17+ test ( 'should 401 if session data is not set' , async ( ) => {
18+ const req = mockRequest ( ) ;
19+ const res = mockResponse ( ) ;
20+ await checkAuth ( req , res ) ;
21+ expect ( res . status ) . toHaveBeenCalledWith ( 401 ) ;
22+ } ) ;
23+ test ( 'should 200 with username from session if session data is set' , async ( ) => {
24+ const req = mockRequest ( { username : 'hugo' } ) ;
25+ const res = mockResponse ( ) ;
26+ await checkAuth ( req , res ) ;
27+ expect ( res . status ) . toHaveBeenCalledWith ( 200 ) ;
28+ expect ( res . json ) . toHaveBeenCalledWith ( { username : 'hugo' } ) ;
29+ } ) ;
30+ } ) ;
Original file line number Diff line number Diff line change @@ -12,4 +12,19 @@ const mockResponse = () => {
1212 return res ;
1313} ;
1414
15- test . todo ( 'should succeed' )
15+ const { checkAuth } = require ( './express-handlers' ) ;
16+
17+ test ( 'checkAuth > should 401 if session data is not set' , async ( t ) => {
18+ const req = mockRequest ( ) ;
19+ const res = mockResponse ( ) ;
20+ await checkAuth ( req , res ) ;
21+ t . true ( res . status . calledWith ( 401 ) ) ;
22+ } ) ;
23+
24+ test ( 'checkAuth > should 200 with username from session if data is set' , async ( t ) => {
25+ const req = mockRequest ( { username : 'hugo' } ) ;
26+ const res = mockResponse ( ) ;
27+ await checkAuth ( req , res ) ;
28+ t . true ( res . status . calledWith ( 200 ) ) ;
29+ t . true ( res . json . calledWith ( { username : 'hugo' } ) ) ;
30+ } )
You can’t perform that action at this time.
0 commit comments