@@ -1254,4 +1254,74 @@ describe('PushController', () => {
1254
1254
. then ( done , done . fail ) ;
1255
1255
} ) ;
1256
1256
} ) ;
1257
+
1258
+ describe ( 'With expiration defined' , ( ) => {
1259
+ const auth = { isMaster : true } ;
1260
+ const pushController = new PushController ( ) ;
1261
+
1262
+ const config = new Config ( Parse . applicationId ) ;
1263
+
1264
+ const pushes = [ ] ;
1265
+ const pushAdapter = {
1266
+ send ( body , installations ) {
1267
+ pushes . push ( body ) ;
1268
+ return successfulTransmissions ( body , installations ) ;
1269
+ } ,
1270
+ getValidPushTypes ( ) {
1271
+ return [ "ios" ] ;
1272
+ }
1273
+ } ;
1274
+
1275
+ beforeEach ( ( done ) => {
1276
+ reconfigureServer ( {
1277
+ push : { adapter : pushAdapter } ,
1278
+ } ) . then ( done , done . fail ) ;
1279
+ } ) ;
1280
+
1281
+ it ( 'should throw if both expiration_time and expiration_interval are set' , ( ) => {
1282
+ expect ( ( ) => pushController . sendPush ( {
1283
+ expiration_time : '2017-09-25T13:21:20.841Z' ,
1284
+ expiration_interval : 1000 ,
1285
+ } , { } , config , auth ) ) . toThrow ( )
1286
+ } ) ;
1287
+
1288
+ it ( 'should throw on invalid expiration_interval' , ( ) => {
1289
+ expect ( ( ) => pushController . sendPush ( {
1290
+ expiration_interval : - 1
1291
+ } ) ) . toThrow ( ) ;
1292
+ expect ( ( ) => pushController . sendPush ( {
1293
+ expiration_interval : '' ,
1294
+ } ) ) . toThrow ( ) ;
1295
+ } ) ;
1296
+
1297
+ describe ( 'For immediate pushes' , ( ) => {
1298
+ it ( 'should transform the expiration_interval into an absolute time' , ( done ) => {
1299
+ const now = new Date ( '2017-09-25T13:30:10.452Z' ) ;
1300
+
1301
+ reconfigureServer ( {
1302
+ push : { adapter : pushAdapter } ,
1303
+ } )
1304
+ . then ( ( ) =>
1305
+ new Promise ( ( resolve ) => {
1306
+ pushController . sendPush ( {
1307
+ data : {
1308
+ alert : 'immediate push' ,
1309
+ } ,
1310
+ expiration_interval : 20 * 60 , // twenty minutes
1311
+ } , { } , new Config ( Parse . applicationId ) , auth , resolve , now )
1312
+ } ) )
1313
+ . then ( ( pushStatusId ) => {
1314
+ const p = new Parse . Object ( '_PushStatus' ) ;
1315
+ p . id = pushStatusId ;
1316
+ return p . fetch ( { useMasterKey : true } ) ;
1317
+ } )
1318
+ . then ( ( pushStatus ) => {
1319
+ expect ( pushStatus . get ( 'expiry' ) ) . toBeDefined ( 'expiry must be set' ) ;
1320
+ expect ( pushStatus . get ( 'expiry' ) )
1321
+ . toEqual ( new Date ( '2017-09-25T13:50:10.452Z' ) . valueOf ( ) ) ;
1322
+ } )
1323
+ . then ( done , done . fail ) ;
1324
+ } ) ;
1325
+ } ) ;
1326
+ } ) ;
1257
1327
} ) ;
0 commit comments