@@ -20,7 +20,7 @@ test('gritty: listen: args: no', (t) => {
2020 t . end ( ) ;
2121} ) ;
2222
23- test ( 'gritty: listen: args: authCheck ' , ( t ) => {
23+ test ( 'gritty: listen: args: auth ' , ( t ) => {
2424 const socket = { } ;
2525 const on = sinon . stub ( ) . returns ( socket )
2626 const of = sinon . stub ( ) . returns ( socket ) ;
@@ -29,10 +29,10 @@ test('gritty: listen: args: authCheck', (t) => {
2929 socket . of = of ;
3030
3131 const fn = ( ) => gritty . listen ( socket , {
32- authCheck : 'hello'
32+ auth : 'hello'
3333 } ) ;
3434
35- t . throws ( fn , / o p t i o n s .a u t h C h e c k s h o u l d b e a f u n c t i o n ! / , 'should throw when no args' ) ;
35+ t . throws ( fn , / o p t i o n s .a u t h s h o u l d b e a f u n c t i o n ! / , 'should throw when no args' ) ;
3636
3737 t . end ( ) ;
3838} ) ;
@@ -158,15 +158,15 @@ test('gritty: server: socket: emit data', (t) => {
158158 } ) ;
159159} ) ;
160160
161- test ( 'gritty: server: socket: authCheck ' , ( t ) => {
162- const authCheck = currify ( ( accept , reject , username , password ) => {
161+ test ( 'gritty: server: socket: auth ' , ( t ) => {
162+ const auth = currify ( ( accept , reject , username , password ) => {
163163 if ( username !== 'hello' || password !== 'world' )
164164 return reject ( ) ;
165165
166166 accept ( ) ;
167167 } ) ;
168168
169- before ( { authCheck } , ( port , after ) => {
169+ before ( { auth } , ( port , after ) => {
170170 const socket = io ( `http://localhost:${ port } /gritty` ) ;
171171
172172 socket . once ( 'connect' , ( ) => {
@@ -248,7 +248,36 @@ test('gritty: server: socket: test env', (t) => {
248248 } ) ;
249249} ) ;
250250
251+ test ( 'gritty: server: socket: authCheck' , ( t ) => {
252+ const authCheck = ( socket , connection ) => {
253+ socket . on ( 'auth' , ( { username, password} ) => {
254+ if ( username !== 'hello' || password !== 'world' )
255+ return socket . emit ( 'reject' ) ;
256+
257+ connection ( ) ;
258+ socket . emit ( 'accept' ) ;
259+ } ) ;
260+ } ;
261+
262+ before ( { authCheck} , ( port , after ) => {
263+ const socket = io ( `http://localhost:${ port } /gritty` ) ;
264+
265+ socket . once ( 'connect' , ( ) => {
266+ socket . emit ( 'auth' , {
267+ username : 'hello' ,
268+ password : 'world' ,
269+ } ) ;
270+
271+ socket . on ( 'accept' , ( ) => {
272+ t . pass ( 'should emit accepet' ) ;
273+ socket . close ( ) ;
274+ after ( ) ;
275+ t . end ( ) ;
276+ } ) ;
277+ } ) ;
278+ } ) ;
279+ } ) ;
280+
251281function clean ( name ) {
252282 delete require . cache [ require . resolve ( name ) ] ;
253283}
254-
0 commit comments