@@ -76,6 +76,10 @@ describe('PartialResultStream', function() {
7676 { }
7777 ]
7878 } ;
79+ var RESULT_WITHOUT_VALUE = {
80+ resumeToken : '...' ,
81+ values : [ ]
82+ } ;
7983
8084 before ( function ( ) {
8185 partialResultStreamModule = proxyquire ( '../src/partial-result-stream.js' , {
@@ -134,21 +138,22 @@ describe('PartialResultStream', function() {
134138 fakeRequestStream . push ( null ) ;
135139 } ) ;
136140
137- it ( 'should not queue more than 10 results' , function ( done ) {
138- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 1
139- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 2
140- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 3
141- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 4
142- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 5
143-
144- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 6
145- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 7
146- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 8
147- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 9
148- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 10
141+ it ( 'should effectively skip rows without values' , function ( done ) {
142+ fakeRequestStream . push ( RESULT_WITHOUT_VALUE ) ;
143+ fakeRequestStream . push ( null ) ;
149144
150- fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ; // 11
145+ partialResultStream
146+ . on ( 'error' , done )
147+ . pipe ( concat ( function ( rows ) {
148+ assert . strictEqual ( rows . length , 0 ) ;
149+ done ( ) ;
150+ } ) ) ;
151+ } ) ;
151152
153+ it ( 'should not queue more than 10 results' , function ( done ) {
154+ for ( var i = 0 ; i < 11 ; i += 1 ) {
155+ fakeRequestStream . push ( RESULT_WITHOUT_TOKEN ) ;
156+ }
152157 fakeRequestStream . push ( null ) ;
153158
154159 partialResultStream
@@ -225,6 +230,28 @@ describe('PartialResultStream', function() {
225230 } ) ) ;
226231 } ) ;
227232
233+ it ( 'should correctly handle multiple rows' , function ( done ) {
234+ var formattedRows = [ [
235+ { } ,
236+ { }
237+ ] ] ;
238+
239+ partialResultStreamModule . formatRow_ = function ( ) {
240+ return formattedRows ;
241+ } ;
242+
243+ fakeRequestStream . push ( RESULT_WITH_TOKEN ) ;
244+ fakeRequestStream . push ( null ) ;
245+
246+ partialResultStream
247+ . on ( 'error' , done )
248+ . pipe ( concat ( function ( rows ) {
249+ assert . strictEqual ( rows [ 0 ] , formattedRows [ 0 ] [ 0 ] ) ;
250+ assert . strictEqual ( rows [ 1 ] , formattedRows [ 0 ] [ 1 ] ) ;
251+ done ( ) ;
252+ } ) ) ;
253+ } ) ;
254+
228255 it ( 'should resume if there was an error' , function ( done ) {
229256 // This test will emit four rows total:
230257 // - Two rows
@@ -323,6 +350,22 @@ describe('PartialResultStream', function() {
323350 partialResultStream . abort ( ) ;
324351 } ) ;
325352
353+ it ( 'should silently no-op abort if no active request' , function ( done ) {
354+ // If no request is ever made, then there should be no active
355+ // stream to be aborted.
356+ fakeRequestStream . abort = function ( ) {
357+ done ( new Error ( 'No request ever made; nothing to abort.' ) ) ;
358+ } ;
359+
360+ // Create a partial result stream and then abort it, without
361+ // ever sending a request.
362+ var partialResultStream = partialResultStreamModule ( function ( ) {
363+ return fakeRequestStream ;
364+ } ) ;
365+ partialResultStream . abort ( ) ;
366+ done ( ) ;
367+ } ) ;
368+
326369 it ( 'should let user abort the most recent request' , function ( done ) {
327370 fakeRequestStream . abort = function ( ) {
328371 done ( new Error ( 'Wrong stream was aborted.' ) ) ;
@@ -384,6 +427,31 @@ describe('PartialResultStream', function() {
384427 values : VALUES
385428 } ;
386429
430+ it ( 'should omit rows from JSON representation with no name' , function ( ) {
431+ // Define the second field to have no name.
432+ var row = {
433+ metadata : { rowType : { fields : [
434+ { name : 'field-1' } , { }
435+ ] } } ,
436+ values : [ 'value-1' , 'value-2' ] ,
437+ } ;
438+ // Override our `decode` function to pass through the value.
439+ decodeValueOverride = function ( value ) {
440+ return value ;
441+ } ;
442+
443+ // Format the row.
444+ var formattedRows = partialResultStreamModule . formatRow_ ( row ) ;
445+
446+ // Both fields should exist in the formattedRows array.
447+ assert . strictEqual ( formattedRows . length , 2 ) ;
448+ assert . strictEqual ( formattedRows [ 0 ] . value , 'value-1' ) ;
449+ assert . strictEqual ( formattedRows [ 1 ] . value , 'value-2' ) ;
450+
451+ // Only the field with a name should exist in the JSON serialization.
452+ assert . deepEqual ( formattedRows . toJSON ( ) , { 'field-1' : 'value-1' } ) ;
453+ } ) ;
454+
387455 it ( 'should chunk rows with more values than fields' , function ( ) {
388456 decodeValueOverride = function ( value ) {
389457 return value ;
@@ -457,4 +525,4 @@ describe('PartialResultStream', function() {
457525 } ) ;
458526 } ) ;
459527 } ) ;
460- } ) ;
528+ } ) ;
0 commit comments