@@ -664,3 +664,117 @@ test('Define multiple paths and method at once', async t => {
664664 t . deepEqual ( response . body , { status : 'ok' } )
665665 t . is ( response . statusCode , 200 )
666666} )
667+
668+ test ( 'ndjson API support' , async t => {
669+ const mock = new Mock ( )
670+ const client = new Client ( {
671+ node : 'http://localhost:9200' ,
672+ Connection : mock . getConnection ( )
673+ } )
674+
675+ mock . add ( {
676+ method : 'POST' ,
677+ path : '/_bulk'
678+ } , params => {
679+ t . deepEqual ( params . body , [
680+ { foo : 'bar' } ,
681+ { baz : 'fa\nz' }
682+ ] )
683+ return { status : 'ok' }
684+ } )
685+
686+ const response = await client . bulk ( {
687+ body : [
688+ { foo : 'bar' } ,
689+ { baz : 'fa\nz' }
690+ ]
691+ } )
692+ t . deepEqual ( response . body , { status : 'ok' } )
693+ t . is ( response . statusCode , 200 )
694+ } )
695+
696+ test ( 'ndjson API support (with compression)' , async t => {
697+ const mock = new Mock ( )
698+ const client = new Client ( {
699+ node : 'http://localhost:9200' ,
700+ Connection : mock . getConnection ( ) ,
701+ compression : 'gzip'
702+ } )
703+
704+ mock . add ( {
705+ method : 'POST' ,
706+ path : '/_bulk'
707+ } , params => {
708+ t . deepEqual ( params . body , [
709+ { foo : 'bar' } ,
710+ { baz : 'fa\nz' }
711+ ] )
712+ return { status : 'ok' }
713+ } )
714+
715+ const response = await client . bulk ( {
716+ body : [
717+ { foo : 'bar' } ,
718+ { baz : 'fa\nz' }
719+ ]
720+ } )
721+ t . deepEqual ( response . body , { status : 'ok' } )
722+ t . is ( response . statusCode , 200 )
723+ } )
724+
725+ test ( 'ndjson API support (as stream)' , async t => {
726+ const mock = new Mock ( )
727+ const client = new Client ( {
728+ node : 'http://localhost:9200' ,
729+ Connection : mock . getConnection ( )
730+ } )
731+
732+ mock . add ( {
733+ method : 'POST' ,
734+ path : '/_bulk'
735+ } , params => {
736+ t . deepEqual ( params . body , [
737+ { foo : 'bar' } ,
738+ { baz : 'fa\nz' }
739+ ] )
740+ return { status : 'ok' }
741+ } )
742+
743+ const response = await client . bulk ( {
744+ body : intoStream ( client . serializer . ndserialize ( [
745+ { foo : 'bar' } ,
746+ { baz : 'fa\nz' }
747+ ] ) )
748+ } )
749+ t . deepEqual ( response . body , { status : 'ok' } )
750+ t . is ( response . statusCode , 200 )
751+ } )
752+
753+ test ( 'ndjson API support (as stream with compression)' , async t => {
754+ const mock = new Mock ( )
755+ const client = new Client ( {
756+ node : 'http://localhost:9200' ,
757+ Connection : mock . getConnection ( ) ,
758+ compression : 'gzip'
759+ } )
760+
761+ mock . add ( {
762+ method : 'POST' ,
763+ path : '/_bulk'
764+ } , params => {
765+ t . deepEqual ( params . body , [
766+ { foo : 'bar' } ,
767+ { baz : 'fa\nz' }
768+ ] )
769+ return { status : 'ok' }
770+ } )
771+
772+ const response = await client . bulk ( {
773+ body : intoStream ( client . serializer . ndserialize ( [
774+ { foo : 'bar' } ,
775+ { baz : 'fa\nz' }
776+ ] ) )
777+ } )
778+ t . deepEqual ( response . body , { status : 'ok' } )
779+ t . is ( response . statusCode , 200 )
780+ } )
0 commit comments