@@ -227,3 +227,46 @@ test('radar', async (t) => {
227
227
validate ( t , vehicles , 'movements' , 'vehicles' )
228
228
t . end ( )
229
229
} )
230
+
231
+ test ( 'subscribing to a journey works' , async ( t ) => {
232
+ const { journeys} = await client . journeys ( ludwigshafen , meckesheim , {
233
+ departure : when , results : 1 ,
234
+ } )
235
+ const journey = journeys [ 0 ]
236
+ const channelId = 'some-channel'
237
+
238
+ const userId = await client . createSubscriptionsUser ( [ channelId ] )
239
+ t . equal ( typeof userId , 'string' )
240
+ t . ok ( userId )
241
+ t . deepEqual ( await client . subscriptions ( userId ) , [ ] )
242
+
243
+ const subId = await client . subscribeToJourney ( userId , [ channelId ] , journey . refreshToken )
244
+ t . ok ( subId !== undefined && subId !== null , 'subId' )
245
+
246
+ const {
247
+ subscription : sub , rtEvents, himEvents,
248
+ } = await client . subscription ( userId , subId , { activeDays : true } )
249
+ t . ok ( sub )
250
+ t . equal ( sub . id , subId )
251
+ t . deepEqual ( sub . hysteresis , { minDeviationInterval : 1 , notificationStart : 30 } )
252
+ t . deepEqual ( sub . monitorFlags , [ 'AF' , 'DF' , 'DV' , 'FTF' , 'OF' , 'PF' ] )
253
+ t . ok ( Array . isArray ( sub . connectionInfo ) )
254
+ t . ok ( sub . connectionInfo . length > 0 )
255
+ t . equal ( sub . journeyRefreshToken , journey . refreshToken )
256
+ t . ok ( sub . activeDays )
257
+ t . ok ( Array . isArray ( rtEvents ) )
258
+ t . ok ( Array . isArray ( himEvents ) )
259
+
260
+ const subs = await client . subscriptions ( userId )
261
+ t . deepEqual ( subs , [ {
262
+ id : subId ,
263
+ status : 'ACTIVE' ,
264
+ channels : [ { id : channelId } ] ,
265
+ journeyRefreshToken : journey . refreshToken ,
266
+ } ] )
267
+
268
+ await client . unsubscribe ( userId , subId )
269
+ t . deepEqual ( await client . subscriptions ( userId ) , [ ] )
270
+
271
+ t . end ( )
272
+ } )
0 commit comments