@@ -108,55 +108,26 @@ test('should fail to connect with an invalid auth token', async (t) => {
108108
109109test ( 'should pass capacity in join payload when provided' , ( t ) => {
110110 return new Promise ( ( done ) => {
111- function createSocket ( endpoint : string , _options : any ) {
112- const socket = new MockSocket ( endpoint , { } , async ( ) => { } ) ;
113-
114- // Override channel method to capture join params
115- const originalChannel = socket . channel . bind ( socket ) ;
116- socket . channel = ( topic : string , params ?: any ) => {
117- const channel = originalChannel ( topic , params ) ;
118- if ( topic === 'worker:queue' ) {
119- t . truthy ( params ) ;
120- t . is ( params . capacity , 10 ) ;
121- }
122- return channel ;
123- } ;
124-
125- return socket ;
126- }
127-
128111 connectToWorkerQueue ( 'www' , 'a' , 'secret' , logger , {
129112 capacity : 10 ,
130- SocketConstructor : createSocket as any ,
131- } ) . on ( 'connect' , ( ) => {
132- t . pass ( 'connected with capacity' ) ;
113+ SocketConstructor : MockSocket as any ,
114+ } ) . on ( 'connect' , ( { socket } ) => {
115+ const channel = socket . allChannels [ 'worker:queue' ] ;
116+ // @ts -ignore - accessing test property
117+ t . is ( channel . _joinParams . capacity , 10 ) ;
133118 done ( ) ;
134119 } ) ;
135120 } ) ;
136121} ) ;
137122
138- test ( 'should not pass capacity in join payload when not provided' , ( t ) => {
123+ test ( 'should pass capacity in join payload when not provided' , ( t ) => {
139124 return new Promise ( ( done ) => {
140- function createSocket ( endpoint : string , _options : any ) {
141- const socket = new MockSocket ( endpoint , { } , async ( ) => { } ) ;
142-
143- // Override channel method to capture join params
144- const originalChannel = socket . channel . bind ( socket ) ;
145- socket . channel = ( topic : string , params ?: any ) => {
146- const channel = originalChannel ( topic , params ) ;
147- if ( topic === 'worker:queue' ) {
148- t . deepEqual ( params , { } ) ;
149- }
150- return channel ;
151- } ;
152-
153- return socket ;
154- }
155-
156125 connectToWorkerQueue ( 'www' , 'a' , 'secret' , logger , {
157- SocketConstructor : createSocket as any ,
158- } ) . on ( 'connect' , ( ) => {
159- t . pass ( 'connected without capacity' ) ;
126+ SocketConstructor : MockSocket as any ,
127+ } ) . on ( 'connect' , ( { socket } ) => {
128+ const channel = socket . allChannels [ 'worker:queue' ] ;
129+ // @ts -ignore - accessing test property
130+ t . is ( channel . _joinParams . capacity , undefined ) ;
160131 done ( ) ;
161132 } ) ;
162133 } ) ;
0 commit comments