@@ -7,6 +7,7 @@ import socketioClient from '@feathersjs/socketio-client'
77import authClient from '../../src'
88import getApp from './fixture'
99import commonTests from './commons'
10+ import { AuthenticationResult } from '@feathersjs/authentication/lib'
1011
1112describe ( '@feathersjs/authentication-client Socket.io integration' , ( ) => {
1213 let app : Application
@@ -52,6 +53,35 @@ describe('@feathersjs/authentication-client Socket.io integration', () => {
5253 assert . strictEqual ( dummy . headers . authorization , `Bearer ${ accessToken } ` )
5354 } )
5455
56+ it ( 'reconnects after socket disconnection' , async ( ) => {
57+ const user = { email : 'disconnecttest@example.com' , password : 'alsosecret' }
58+ const socket = io ( 'http://localhost:9777' , {
59+ timeout : 500 ,
60+ reconnection : true ,
61+ reconnectionDelay : 100
62+ } )
63+ const client = feathers ( ) . configure ( socketioClient ( socket ) ) . configure ( authClient ( ) )
64+
65+ await app . service ( 'users' ) . create ( user )
66+ await client . authenticate ( {
67+ strategy : 'local' ,
68+ ...user
69+ } )
70+
71+ const onLogin = new Promise < AuthenticationResult > ( ( resolve ) => app . once ( 'login' , ( data ) => resolve ( data ) ) )
72+
73+ socket . once ( 'disconnect' , ( ) => socket . connect ( ) )
74+ socket . disconnect ( )
75+
76+ const {
77+ authentication : { strategy }
78+ } = await onLogin
79+ const dummy = await client . service ( 'dummy' ) . find ( )
80+
81+ assert . strictEqual ( strategy , 'jwt' )
82+ assert . strictEqual ( dummy . user . email , user . email )
83+ } )
84+
5585 commonTests (
5686 ( ) => app ,
5787 ( ) => {
0 commit comments