@@ -880,3 +880,92 @@ test('Should clear all mocks', async t => {
880880 t . is ( err . statusCode , 404 )
881881 }
882882} )
883+
884+ test ( 'Path should match URL-encoded characters for e.g. comma in multi-index operations' , async t => {
885+ t . plan ( 1 )
886+
887+ const mock = new Mock ( )
888+ const client = new Client ( {
889+ node : 'http://localhost:9200' ,
890+ Connection : mock . getConnection ( )
891+ } )
892+
893+ const spy = ( _req , _res , _params , _store , _searchParams ) => {
894+ t . pass ( 'Callback function was called' )
895+ return { }
896+ }
897+
898+ mock . add (
899+ {
900+ method : 'DELETE' ,
901+ path : '/some-type-index-123tobedeleted%2Csome-type-index-456tobedeleted'
902+ } ,
903+ spy
904+ )
905+
906+ await client . indices . delete ( {
907+ index : [
908+ 'some-type-index-123tobedeleted' ,
909+ 'some-type-index-456tobedeleted'
910+ ]
911+ } )
912+ } )
913+
914+ test ( 'Path should match unencoded comma in path' , async t => {
915+ t . plan ( 1 )
916+
917+ const mock = new Mock ( )
918+ const client = new Client ( {
919+ node : 'http://localhost:9200' ,
920+ Connection : mock . getConnection ( )
921+ } )
922+
923+ const spy = ( _req , _res , _params , _store , _searchParams ) => {
924+ t . pass ( 'Callback function was called' )
925+ return { }
926+ }
927+
928+ mock . add (
929+ {
930+ method : 'DELETE' ,
931+ path : '/some-type-index-123tobedeleted,some-type-index-456tobedeleted'
932+ } ,
933+ spy
934+ )
935+
936+ await client . indices . delete ( {
937+ index : [
938+ 'some-type-index-123tobedeleted' ,
939+ 'some-type-index-456tobedeleted'
940+ ]
941+ } )
942+ } )
943+
944+ test ( 'Validate types on get()' , t => {
945+ t . plan ( 4 )
946+
947+ const mock = new Mock ( )
948+ mock . add (
949+ {
950+ method : 'GET' ,
951+ path : '/foo'
952+ } ,
953+ ( ) => { }
954+ )
955+
956+ try {
957+ mock . get ( { method : 'GET' , path : null } )
958+ t . fail ( 'should throw' )
959+ } catch ( err ) {
960+ t . true ( err instanceof errors . ConfigurationError )
961+ t . is ( err . message , 'The path is not defined' )
962+ }
963+
964+ try {
965+ mock . get ( { method : null , path : '/foo' } )
966+ t . fail ( 'should throw' )
967+ } catch ( err ) {
968+ t . true ( err instanceof errors . ConfigurationError )
969+ t . is ( err . message , 'The method is not defined' )
970+ }
971+ } )
0 commit comments