@@ -289,6 +289,28 @@ describe('StreamrClient', function() {
289289 } )
290290 } )
291291
292+ it ( 'should add any subscription options to subscription request' , function ( done ) {
293+ client . connect ( )
294+ client . socket . once ( 'connect' , function ( ) {
295+ client . socket . once ( 'subscribe' , function ( request ) {
296+ if ( request . foo === 'bar' )
297+ done ( )
298+ } )
299+ client . subscribe ( "stream1" , function ( message ) { } , { foo : 'bar' } )
300+ } )
301+ } )
302+
303+ it ( 'should ignore any subscription options that conflict with required ones' , function ( done ) {
304+ client . connect ( )
305+ client . socket . once ( 'connect' , function ( ) {
306+ client . socket . once ( 'subscribe' , function ( request ) {
307+ if ( request . channel === 'stream1' )
308+ done ( )
309+ } )
310+ client . subscribe ( "stream1" , function ( message ) { } , { channel : 'wrong' } )
311+ } )
312+ } )
313+
292314 it ( 'should mark Subscriptions as subscribed when the server responds with subscribed' , function ( done ) {
293315 var subscription = client . subscribe ( "stream1" , function ( message ) { } )
294316 client . connect ( )
@@ -410,6 +432,17 @@ describe('StreamrClient', function() {
410432 } )
411433 } )
412434
435+ it ( 'should emit a resend request with given other options' , function ( done ) {
436+ client . subscribe ( "stream1" , function ( message ) { } , { resend_all :true , foo : 'bar' } )
437+ client . connect ( )
438+
439+ client . socket . once ( 'resend' , function ( request ) {
440+ if ( request . resend_all && request . foo === 'bar' )
441+ done ( )
442+ else throw "Unexpected resend request: " + JSON . stringify ( request )
443+ } )
444+ } )
445+
413446 it ( 'should throw an error if multiple resend options are given' , function ( ) {
414447 assert . throws ( function ( ) {
415448 client . subscribe ( "stream1" , function ( message ) { } , { resend_all :true , resend_last :5 } )
@@ -1026,7 +1059,9 @@ describe('StreamrClient', function() {
10261059 var el = validResendRequests [ 0 ]
10271060 // all fields in the model request must be equal in actual request
10281061 Object . keys ( el ) . forEach ( function ( field ) {
1029- assert . equal ( request [ field ] , el [ field ] )
1062+ if ( request [ field ] !== el [ field ] ) {
1063+ throw "Resend request field " + field + " does not match expected value! Was: " + JSON . stringify ( request ) + ", expected: " + JSON . stringify ( el )
1064+ }
10301065 } )
10311066 validResendRequests . shift ( )
10321067 }
@@ -1168,6 +1203,48 @@ describe('StreamrClient', function() {
11681203 done ( )
11691204 } )
11701205 } )
1206+
1207+ it ( 'should include any subscription options in resend request' , function ( done ) {
1208+ client . subscribe ( "stream1" , function ( message ) { } , { auth :'foo' } )
1209+ client . connect ( )
1210+
1211+ validResendRequests . push ( { channel :"stream1" , resend_from :1 , resend_to :9 } )
1212+
1213+ client . socket . once ( 'subscribed' , function ( ) {
1214+ client . socket . emit ( 'ui' , msg ( "stream1" , 0 ) )
1215+ client . socket . emit ( 'ui' , msg ( "stream1" , 10 ) )
1216+ } )
1217+
1218+ client . socket . once ( 'resend' , function ( request ) {
1219+ assert . equal ( request . auth , 'foo' )
1220+ } )
1221+
1222+ client . socket . once ( 'resent' , function ( ) {
1223+ done ( )
1224+ } )
1225+ } )
1226+
1227+ it ( 'should not include stronger resend requests in gap resend request' , function ( done ) {
1228+ client . subscribe ( "stream1" , function ( message ) { } , { auth :'foo' , resend_all : true } )
1229+ client . connect ( )
1230+
1231+ validResendRequests . push ( { channel :"stream1" , resend_all :true } )
1232+ validResendRequests . push ( { channel :"stream1" , resend_from :1 , resend_to :1 } )
1233+
1234+ client . socket . once ( 'subscribed' , function ( ) {
1235+ client . socket . emit ( 'ui' , msg ( "stream1" , 0 ) )
1236+ client . socket . emit ( 'ui' , msg ( "stream1" , 2 ) )
1237+ } )
1238+
1239+ client . socket . on ( 'resend' , function ( request ) {
1240+ if ( request . resend_from )
1241+ assert . equal ( request . resend_all , undefined )
1242+ } )
1243+
1244+ client . socket . once ( 'resent' , function ( ) {
1245+ done ( )
1246+ } )
1247+ } )
11711248
11721249 it ( 'should not emit another resend request while waiting for resend' , function ( done ) {
11731250 client . subscribe ( "stream1" , function ( message ) { } )
0 commit comments