@@ -557,3 +557,110 @@ test('.add should throw if method and path are not defined', async t => {
557557 t . is ( err . message , 'The resolver function is not defined' )
558558 }
559559} )
560+
561+ test ( 'Define multiple methods at once' , async t => {
562+ const mock = new Mock ( )
563+ const client = new Client ( {
564+ node : 'http://localhost:9200' ,
565+ Connection : mock . getConnection ( )
566+ } )
567+
568+ mock . add ( {
569+ method : [ 'GET' , 'POST' ] ,
570+ path : '/:index/_search'
571+ } , ( ) => {
572+ return { status : 'ok' }
573+ } )
574+
575+ let response = await client . search ( {
576+ index : 'test' ,
577+ q : 'foo:bar'
578+ } )
579+ t . deepEqual ( response . body , { status : 'ok' } )
580+ t . is ( response . statusCode , 200 )
581+
582+ response = await client . search ( {
583+ index : 'test' ,
584+ body : {
585+ query : { match : { foo : 'bar' } }
586+ }
587+ } )
588+ t . deepEqual ( response . body , { status : 'ok' } )
589+ t . is ( response . statusCode , 200 )
590+ } )
591+
592+ test ( 'Define multiple paths at once' , async t => {
593+ const mock = new Mock ( )
594+ const client = new Client ( {
595+ node : 'http://localhost:9200' ,
596+ Connection : mock . getConnection ( )
597+ } )
598+
599+ mock . add ( {
600+ method : 'GET' ,
601+ path : [ '/test1/_search' , '/test2/_search' ]
602+ } , ( ) => {
603+ return { status : 'ok' }
604+ } )
605+
606+ let response = await client . search ( {
607+ index : 'test1' ,
608+ q : 'foo:bar'
609+ } )
610+ t . deepEqual ( response . body , { status : 'ok' } )
611+ t . is ( response . statusCode , 200 )
612+
613+ response = await client . search ( {
614+ index : 'test2' ,
615+ q : 'foo:bar'
616+ } )
617+ t . deepEqual ( response . body , { status : 'ok' } )
618+ t . is ( response . statusCode , 200 )
619+ } )
620+
621+ test ( 'Define multiple paths and method at once' , async t => {
622+ const mock = new Mock ( )
623+ const client = new Client ( {
624+ node : 'http://localhost:9200' ,
625+ Connection : mock . getConnection ( )
626+ } )
627+
628+ mock . add ( {
629+ method : [ 'GET' , 'POST' ] ,
630+ path : [ '/test1/_search' , '/test2/_search' ]
631+ } , ( ) => {
632+ return { status : 'ok' }
633+ } )
634+
635+ let response = await client . search ( {
636+ index : 'test1' ,
637+ q : 'foo:bar'
638+ } )
639+ t . deepEqual ( response . body , { status : 'ok' } )
640+ t . is ( response . statusCode , 200 )
641+
642+ response = await client . search ( {
643+ index : 'test2' ,
644+ q : 'foo:bar'
645+ } )
646+ t . deepEqual ( response . body , { status : 'ok' } )
647+ t . is ( response . statusCode , 200 )
648+
649+ response = await client . search ( {
650+ index : 'test1' ,
651+ body : {
652+ query : { match : { foo : 'bar' } }
653+ }
654+ } )
655+ t . deepEqual ( response . body , { status : 'ok' } )
656+ t . is ( response . statusCode , 200 )
657+
658+ response = await client . search ( {
659+ index : 'test2' ,
660+ body : {
661+ query : { match : { foo : 'bar' } }
662+ }
663+ } )
664+ t . deepEqual ( response . body , { status : 'ok' } )
665+ t . is ( response . statusCode , 200 )
666+ } )
0 commit comments