@@ -71,32 +71,19 @@ jest.mock('./globals', () => ({
7171 setGlobal : ( ) => null ,
7272} ) ) ;
7373
74- let mockNgrokPath ;
7574const mockDispatch = jest . fn ( ) ;
7675jest . mock ( './state/store' , ( ) => ( {
7776 store : {
7877 dispatch : action => mockDispatch ( action ) ,
7978 } ,
8079 getSettings : ( ) => ( {
81- framework : {
82- ngrokPath : mockNgrokPath ,
83- } ,
80+ framework : { } ,
8481 } ) ,
8582} ) ) ;
8683
87- let mockGetSpawnStatus : any = jest . fn ( ( ) => ( { triedToSpawn : true } ) ) ;
88- let mockRunningStatus ;
8984const mockRecycle = jest . fn ( ( ) => null ) ;
9085const mockEmulator = {
9186 framework : { serverUrl : 'http://[::]:8090' } ,
92- ngrok : {
93- getSpawnStatus : ( ) => mockGetSpawnStatus ( ) ,
94- ngrokEmitter : {
95- once : ( _eventName , cb ) => cb ( ) ,
96- } ,
97- recycle : ( ) => mockRecycle ( ) ,
98- running : ( ) => mockRunningStatus ,
99- } ,
10087} ;
10188jest . mock ( './emulator' , ( ) => ( {
10289 Emulator : {
@@ -178,15 +165,12 @@ describe('Protocol handler tests', () => {
178165 } ,
179166 ] ,
180167 } ;
181- mockRunningStatus = true ;
182- mockNgrokPath = 'path/to/ngrok.exe' ;
183168 mockSendNotificationToClient = jest . fn ( ( ) => null ) ;
184169 mockGotReturnValue = {
185170 statusCode : 200 ,
186171 body : '["activity1", "activity2", "activity3"]' ,
187172 } ;
188173 mockRecycle . mockClear ( ) ;
189- mockGetSpawnStatus . mockClear ( ) ;
190174 mockDispatch . mockClear ( ) ;
191175 } ) ;
192176
@@ -377,7 +361,7 @@ describe('Protocol handler tests', () => {
377361 } ) ;
378362 } ) ;
379363
380- it ( 'should open a bot when ngrok is running ' , async ( ) => {
364+ it ( 'should open a bot' , async ( ) => {
381365 const protocol = {
382366 parsedArgs : {
383367 id : 'someIdOverride' ,
@@ -388,9 +372,6 @@ describe('Protocol handler tests', () => {
388372 const overrides = { endpoint : parseEndpointOverrides ( protocol . parsedArgs ) } ;
389373 const overriddenBot = applyBotConfigOverrides ( mockOpenedBot , overrides ) ;
390374
391- // ngrok should be kick-started if it hasn't tried to spawn yet
392- mockGetSpawnStatus = jest . fn ( ( ) => ( { triedToSpawn : false } ) ) ;
393-
394375 await ProtocolHandler . openBot ( protocol ) ;
395376
396377 expect ( mockRecycle ) . toHaveBeenCalled ( ) ;
@@ -409,96 +390,6 @@ describe('Protocol handler tests', () => {
409390 } ) ;
410391 } ) ;
411392
412- it ( 'should open a bot when ngrok is configured but not running' , async ( ) => {
413- mockRunningStatus = false ;
414- const protocol = {
415- parsedArgs : {
416- id : 'someIdOverride' ,
417- path : 'path/to/bot.bot' ,
418- secret : 'someSecret' ,
419- } ,
420- } ;
421- const overrides = { endpoint : parseEndpointOverrides ( protocol . parsedArgs ) } ;
422- const overriddenBot = applyBotConfigOverrides ( mockOpenedBot , overrides ) ;
423-
424- await ProtocolHandler . openBot ( protocol ) ;
425-
426- expect ( mockCallsMade ) . toHaveLength ( 2 ) ;
427- expect ( mockCallsMade [ 0 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . Open ) ;
428- expect ( mockCallsMade [ 0 ] . args ) . toEqual ( [ 'path/to/bot.bot' , 'someSecret' ] ) ;
429- expect ( mockCallsMade [ 1 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . SetActive ) ;
430- expect ( mockCallsMade [ 1 ] . args ) . toEqual ( [ overriddenBot ] ) ;
431- expect ( mockRemoteCallsMade ) . toHaveLength ( 1 ) ;
432- expect ( mockRemoteCallsMade [ 0 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . Load ) ;
433- expect ( mockRemoteCallsMade [ 0 ] . args ) . toEqual ( [ overriddenBot ] ) ;
434- expect ( mockTrackEvent ) . toHaveBeenCalledWith ( 'bot_open' , {
435- method : 'protocol' ,
436- numOfServices : 1 ,
437- source : 'path' ,
438- } ) ;
439- } ) ;
440-
441- it ( 'should open a bot when ngrok is not configured' , async ( ) => {
442- mockNgrokPath = undefined ;
443- const protocol = {
444- parsedArgs : {
445- id : 'someIdOverride' ,
446- path : 'path/to/bot.bot' ,
447- secret : 'someSecret' ,
448- } ,
449- } ;
450- const overrides = { endpoint : parseEndpointOverrides ( protocol . parsedArgs ) } ;
451- const overriddenBot = applyBotConfigOverrides ( mockOpenedBot , overrides ) ;
452-
453- await ProtocolHandler . openBot ( protocol ) ;
454-
455- expect ( mockCallsMade ) . toHaveLength ( 2 ) ;
456- expect ( mockCallsMade [ 0 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . Open ) ;
457- expect ( mockCallsMade [ 0 ] . args ) . toEqual ( [ 'path/to/bot.bot' , 'someSecret' ] ) ;
458- expect ( mockCallsMade [ 1 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . SetActive ) ;
459- expect ( mockCallsMade [ 1 ] . args ) . toEqual ( [ overriddenBot ] ) ;
460- expect ( mockRemoteCallsMade ) . toHaveLength ( 1 ) ;
461- expect ( mockRemoteCallsMade [ 0 ] . commandName ) . toBe ( SharedConstants . Commands . Bot . Load ) ;
462- expect ( mockRemoteCallsMade [ 0 ] . args ) . toEqual ( [ overriddenBot ] ) ;
463- expect ( mockTrackEvent ) . toHaveBeenCalledWith ( 'bot_open' , {
464- method : 'protocol' ,
465- numOfServices : 1 ,
466- source : 'path' ,
467- } ) ;
468- } ) ;
469-
470- it ( 'should throw if ngrok failed to spawn while opening a bot' , async ( ) => {
471- try {
472- const protocol = {
473- parsedArgs : {
474- id : 'someIdOverride' ,
475- path : 'path/to/bot.bot' ,
476- secret : 'someSecret' ,
477- } ,
478- } ;
479- mockGetSpawnStatus = jest . fn ( ( ) => ( { triedToSpawn : true , err : 'Some ngrok error' } ) ) ;
480- await ProtocolHandler . openBot ( protocol ) ;
481- } catch ( e ) {
482- expect ( e ) . toEqual ( new Error ( 'Error while trying to spawn ngrok instance: Some ngrok error' ) ) ;
483- }
484- } ) ;
485-
486- it ( 'should throw if ngrok failed to spawn while opening a livechat' , async ( ) => {
487- try {
488- const protocol = {
489- parsedArgs : {
490- botUrl : 'someUrl' ,
491- msaAppId : 'someAppId' ,
492- msaPassword : 'somePw' ,
493- } ,
494- } ;
495- mockGetSpawnStatus = jest . fn ( ( ) => ( { triedToSpawn : true , err : 'Some ngrok error' } ) ) ;
496- await ProtocolHandler . openBot ( protocol ) ;
497- } catch ( e ) {
498- expect ( e ) . toEqual ( new Error ( 'Error while trying to spawn ngrok instance: Some ngrok error' ) ) ;
499- }
500- } ) ;
501-
502393 it ( 'should open a transcript from a url' , async ( ) => {
503394 const protocol = {
504395 parsedArgs : { url : 'https://www.test.com/convo1.transcript' } ,
0 commit comments