@@ -138,8 +138,8 @@ describe('PushController', () => {
138
138
'push_time' : timeStr
139
139
}
140
140
141
- var time = PushController . getPushTime ( body ) ;
142
- expect ( time ) . toEqual ( new Date ( timeStr ) ) ;
141
+ var { date } = PushController . getPushTime ( body ) ;
142
+ expect ( date ) . toEqual ( new Date ( timeStr ) ) ;
143
143
done ( ) ;
144
144
} ) ;
145
145
@@ -150,8 +150,8 @@ describe('PushController', () => {
150
150
'push_time' : timeNumber
151
151
}
152
152
153
- var time = PushController . getPushTime ( body ) . valueOf ( ) ;
154
- expect ( time ) . toEqual ( timeNumber * 1000 ) ;
153
+ var { date } = PushController . getPushTime ( body ) ;
154
+ expect ( date . valueOf ( ) ) . toEqual ( timeNumber * 1000 ) ;
155
155
done ( ) ;
156
156
} ) ;
157
157
@@ -640,16 +640,36 @@ describe('PushController', () => {
640
640
expect ( PushController . getPushTime ( ) ) . toBe ( undefined ) ;
641
641
expect ( PushController . getPushTime ( {
642
642
'push_time' : 1000
643
- } ) ) . toEqual ( new Date ( 1000 * 1000 ) ) ;
643
+ } ) . date ) . toEqual ( new Date ( 1000 * 1000 ) ) ;
644
644
expect ( PushController . getPushTime ( {
645
645
'push_time' : '2017-01-01'
646
- } ) ) . toEqual ( new Date ( '2017-01-01' ) ) ;
646
+ } ) . date ) . toEqual ( new Date ( '2017-01-01' ) ) ;
647
+
647
648
expect ( ( ) => { PushController . getPushTime ( {
648
649
'push_time' : 'gibberish-time'
649
650
} ) } ) . toThrow ( ) ;
650
651
expect ( ( ) => { PushController . getPushTime ( {
651
652
'push_time' : Number . NaN
652
653
} ) } ) . toThrow ( ) ;
654
+
655
+ expect ( PushController . getPushTime ( {
656
+ push_time : '2017-09-06T13:42:48.369Z'
657
+ } ) ) . toEqual ( {
658
+ date : new Date ( '2017-09-06T13:42:48.369Z' ) ,
659
+ isLocalTime : false ,
660
+ } ) ;
661
+ expect ( PushController . getPushTime ( {
662
+ push_time : '2007-04-05T12:30-02:00' ,
663
+ } ) ) . toEqual ( {
664
+ date : new Date ( '2007-04-05T12:30-02:00' ) ,
665
+ isLocalTime : false ,
666
+ } ) ;
667
+ expect ( PushController . getPushTime ( {
668
+ push_time : '2007-04-05T12:30' ,
669
+ } ) ) . toEqual ( {
670
+ date : new Date ( '2007-04-05T12:30' ) ,
671
+ isLocalTime : true ,
672
+ } ) ;
653
673
} ) ;
654
674
655
675
it ( 'should not schedule push when not configured' , ( done ) => {
@@ -979,4 +999,86 @@ describe('PushController', () => {
979
999
done ( ) ;
980
1000
} ) . catch ( done . fail ) ;
981
1001
} ) ;
1002
+
1003
+ describe ( 'pushTimeHasTimezoneComponent' , ( ) => {
1004
+ it ( 'should be accurate' , ( ) => {
1005
+ expect ( PushController . pushTimeHasTimezoneComponent ( '2017-09-06T17:14:01.048Z' ) )
1006
+ . toBe ( true , 'UTC time' ) ;
1007
+ expect ( PushController . pushTimeHasTimezoneComponent ( '2007-04-05T12:30-02:00' ) )
1008
+ . toBe ( true , 'Timezone offset' ) ;
1009
+ expect ( PushController . pushTimeHasTimezoneComponent ( '2007-04-05T12:30:00.000Z-02:00' ) )
1010
+ . toBe ( true , 'Seconds + Milliseconds + Timezone offset' ) ;
1011
+
1012
+ expect ( PushController . pushTimeHasTimezoneComponent ( '2017-09-06T17:14:01.048' ) )
1013
+ . toBe ( false , 'No timezone' ) ;
1014
+ expect ( PushController . pushTimeHasTimezoneComponent ( '2017-09-06' ) )
1015
+ . toBe ( false , 'YY-MM-DD' ) ;
1016
+ } ) ;
1017
+ } ) ;
1018
+
1019
+ describe ( 'formatPushTime' , ( ) => {
1020
+ it ( 'should format as ISO string' , ( ) => {
1021
+ expect ( PushController . formatPushTime ( {
1022
+ date : new Date ( '2017-09-06T17:14:01.048Z' ) ,
1023
+ isLocalTime : false ,
1024
+ } ) ) . toBe ( '2017-09-06T17:14:01.048Z' , 'UTC time' ) ;
1025
+ expect ( PushController . formatPushTime ( {
1026
+ date : new Date ( '2007-04-05T12:30-02:00' ) ,
1027
+ isLocalTime : false
1028
+ } ) ) . toBe ( '2007-04-05T14:30:00.000Z' , 'Timezone offset' ) ;
1029
+
1030
+ expect ( PushController . formatPushTime ( {
1031
+ date : new Date ( '2017-09-06T17:14:01.048' ) ,
1032
+ isLocalTime : true ,
1033
+ } ) ) . toBe ( '2017-09-06T17:14:01.048' , 'No timezone' ) ;
1034
+ expect ( PushController . formatPushTime ( {
1035
+ date : new Date ( '2017-09-06' ) ,
1036
+ isLocalTime : true
1037
+ } ) ) . toBe ( '2017-09-06T00:00:00.000' , 'YY-MM-DD' ) ;
1038
+ } ) ;
1039
+ } ) ;
1040
+
1041
+ describe ( 'Scheduling pushes in local time' , ( ) => {
1042
+ it ( 'should preserve the push time' , ( done ) => {
1043
+ const auth = { isMaster : true } ;
1044
+ const pushAdapter = {
1045
+ send ( body , installations ) {
1046
+ return successfulTransmissions ( body , installations ) ;
1047
+ } ,
1048
+ getValidPushTypes ( ) {
1049
+ return [ "ios" ] ;
1050
+ }
1051
+ } ;
1052
+
1053
+ const pushTime = '2017-09-06T17:14:01.048' ;
1054
+
1055
+ reconfigureServer ( {
1056
+ push : { adapter : pushAdapter } ,
1057
+ scheduledPush : true
1058
+ } )
1059
+ . then ( ( ) => {
1060
+ const config = new Config ( Parse . applicationId ) ;
1061
+ return new Promise ( ( resolve , reject ) => {
1062
+ const pushController = new PushController ( ) ;
1063
+ pushController . sendPush ( {
1064
+ data : {
1065
+ alert : "Hello World!" ,
1066
+ badge : "Increment" ,
1067
+ } ,
1068
+ push_time : pushTime
1069
+ } , { } , config , auth , resolve )
1070
+ . catch ( reject ) ;
1071
+ } )
1072
+ } )
1073
+ . then ( ( pushStatusId ) => {
1074
+ const q = new Parse . Query ( '_PushStatus' ) ;
1075
+ return q . get ( pushStatusId , { useMasterKey : true } ) ;
1076
+ } )
1077
+ . then ( ( pushStatus ) => {
1078
+ expect ( pushStatus . get ( 'status' ) ) . toBe ( 'scheduled' ) ;
1079
+ expect ( pushStatus . get ( 'pushTime' ) ) . toBe ( '2017-09-06T17:14:01.048' ) ;
1080
+ } )
1081
+ . then ( done , done . fail ) ;
1082
+ } ) ;
1083
+ } ) ;
982
1084
} ) ;
0 commit comments