@@ -364,4 +364,50 @@ describe('PaddleIntegration', () => {
364
364
expect ( isActive ) . to . be . false
365
365
} )
366
366
} )
367
+
368
+ describe ( '.getStartAndEndDates' , ( ) => {
369
+ it ( 'returns only start date if theres no end date' , async ( ) => {
370
+ const subscriptionId = uuid ( )
371
+ const startTimeString = new Date ( ) . toISOString ( )
372
+ const createPayload = Object . assign ( { } , subscriptionCreated ,
373
+ {
374
+ subscription_id : subscriptionId , passthrough : JSON . stringify ( { ids } ) ,
375
+ event_time : startTimeString
376
+ }
377
+ )
378
+ await paddleIntegration . addSubscriptionCreatedStatus ( createPayload )
379
+
380
+ const { subscription : sub } = await storage . get ( ids )
381
+ const { start, end } = await paddleIntegration . getStartAndEndDates ( sub )
382
+ expect ( start ) . to . equal ( startTimeString )
383
+ expect ( end ) . to . be . null
384
+ } )
385
+ it ( 'returns start and end date' , async ( ) => {
386
+ const subscriptionId = uuid ( )
387
+ const startTimeString = new Date ( ) . toISOString ( )
388
+ const endTimeString = new Date ( new Date ( ) . getTime ( ) + 1000 * 3600 * 24 * 33 ) . toISOString ( )
389
+
390
+ const createPayload = Object . assign ( { } , subscriptionCreated ,
391
+ {
392
+ subscription_id : subscriptionId , passthrough : JSON . stringify ( { ids } ) ,
393
+ event_time : startTimeString
394
+ }
395
+ )
396
+ await paddleIntegration . addSubscriptionCreatedStatus ( createPayload )
397
+
398
+ const payload = Object . assign ( { } , subscriptionCancelled ,
399
+ {
400
+ subscription_id : subscriptionId ,
401
+ passthrough : JSON . stringify ( { ids } ) ,
402
+ cancellation_effective_date : endTimeString
403
+ }
404
+ )
405
+ await paddleIntegration . addSubscriptionCancelledStatus ( payload )
406
+
407
+ const { subscription : sub } = await storage . get ( ids )
408
+ const { start, end } = await paddleIntegration . getStartAndEndDates ( sub )
409
+ expect ( start ) . to . equal ( startTimeString )
410
+ expect ( end ) . to . equal ( endTimeString )
411
+ } )
412
+ } )
367
413
} )
0 commit comments