@@ -211,6 +211,7 @@ describe('OutgoingWebSocket', () => {
211211 const mockCustomRequestHandler = {
212212 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
213213 customRequestList : { customRequestId : { resolve : spy ( ) } } ,
214+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
214215 } ;
215216 customRequestHandler = stub (
216217 CustomRequestHandler ,
@@ -233,6 +234,7 @@ describe('OutgoingWebSocket', () => {
233234 const mockCustomRequestHandler = {
234235 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
235236 customRequestList : { customRequestId : { resolve : spy ( ) } } ,
237+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
236238 } ;
237239 customRequestHandler = stub (
238240 CustomRequestHandler ,
@@ -256,6 +258,7 @@ describe('OutgoingWebSocket', () => {
256258 const mockCustomRequestHandler = {
257259 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
258260 customRequestList : { customRequestId : { resolve : spy ( ) } } ,
261+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
259262 } ;
260263 customRequestHandler = stub (
261264 CustomRequestHandler ,
@@ -297,6 +300,25 @@ describe('OutgoingWebSocket', () => {
297300 assert ( msgSpy . calledOnce ) ;
298301 assert ( msgSpy . calledWith ( kMessageReceived , msg ) ) ;
299302 } ) ;
303+
304+ it ( 'should not handle custom requests when no custom requests are pending' , ( ) => {
305+ const mockCustomRequestHandler = {
306+ getList : stub ( ) . returns ( { customRequestId : { } } ) ,
307+ customRequestList : { customRequestId : { resolve : spy ( ) } } ,
308+ isCustomRequestListEmpty : stub ( ) . returns ( true ) ,
309+ } ;
310+ customRequestHandler = stub (
311+ CustomRequestHandler ,
312+ 'getInstance'
313+ ) . returns ( mockCustomRequestHandler ) ;
314+ outgoingWsCustom = new OutgoingWebSocketWithMock ( upstreamUrl , headers ) ;
315+ msgSpy = spy ( ) ;
316+ outgoingWsCustom . emit = msgSpy ;
317+ const msg = '{"id": "customRequestId"}' ;
318+ outgoingWsCustom . messageHandler ( msg ) ;
319+ assert ( msgSpy . calledOnce ) ;
320+ assert ( msgSpy . calledWith ( kMessageReceived , msg ) ) ;
321+ } ) ;
300322 } ) ;
301323 } ) ;
302324
@@ -385,6 +407,7 @@ describe('OutgoingWebSocket', () => {
385407 const mockCustomRequestHandler = {
386408 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
387409 customRequestList : { customRequestId : { reject : spy ( ) } } ,
410+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
388411 } ;
389412 customRequestHandler = stub (
390413 CustomRequestHandler ,
@@ -407,6 +430,7 @@ describe('OutgoingWebSocket', () => {
407430 const mockCustomRequestHandler = {
408431 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
409432 customRequestList : { customRequestId : { reject : spy ( ) } } ,
433+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
410434 } ;
411435 customRequestHandler = stub (
412436 CustomRequestHandler ,
@@ -430,6 +454,7 @@ describe('OutgoingWebSocket', () => {
430454 const mockCustomRequestHandler = {
431455 getList : stub ( ) . returns ( { customRequestId : { } } ) ,
432456 customRequestList : { customRequestId : { reject : spy ( ) } } ,
457+ isCustomRequestListEmpty : stub ( ) . returns ( false ) ,
433458 } ;
434459 customRequestHandler = stub (
435460 CustomRequestHandler ,
@@ -471,6 +496,26 @@ describe('OutgoingWebSocket', () => {
471496 assert ( msgSpy . calledOnce ) ;
472497 assert ( msgSpy . calledWith ( kError , msg ) ) ;
473498 } ) ;
499+
500+ it ( 'should not handle custom requests when no custom requests are pending' , ( ) => {
501+ // Mock CustomRequestHandler
502+ const mockCustomRequestHandler = {
503+ getList : stub ( ) . returns ( { customRequestId : { } } ) ,
504+ customRequestList : { customRequestId : { resolve : spy ( ) } } ,
505+ isCustomRequestListEmpty : stub ( ) . returns ( true ) ,
506+ } ;
507+ customRequestHandler = stub (
508+ CustomRequestHandler ,
509+ 'getInstance'
510+ ) . returns ( mockCustomRequestHandler ) ;
511+ outgoingWsCustom = new OutgoingWebSocketWithMock ( upstreamUrl , headers ) ;
512+ msgSpy = spy ( ) ;
513+ outgoingWsCustom . emit = msgSpy ;
514+ const msg = '{"id": "customRequestId"}' ;
515+ outgoingWsCustom . errorHandler ( msg ) ;
516+ assert ( msgSpy . calledOnce ) ;
517+ assert ( msgSpy . calledWith ( kError , msg ) ) ;
518+ } ) ;
474519 } ) ;
475520 } ) ;
476521
0 commit comments