Skip to content

Commit 4ab77e2

Browse files
author
richard.turton
committed
Fixes incorrect assertion of 2 week in advance PushDate and adds unit tests to verify
1 parent a4eb075 commit 4ab77e2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Parse/Internal/Push/State/PFPushState.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ - (void)setPushDate:(NSDate *)pushDate {
4949
if (self.pushDate != pushDate) {
5050
NSTimeInterval interval = pushDate.timeIntervalSinceNow;
5151
PFParameterAssert(interval > 0, @"Can't set the scheduled push time in the past.");
52-
PFParameterAssert(interval <= 60 * 24 * 14, @"Can't set the schedule push time more than two weeks from now.");
52+
PFParameterAssert(interval <= 60 * 60 * 24 * 14, @"Can't set the schedule push time more than two weeks from now.");
5353
_pushDate = pushDate;
5454
}
5555
}

Tests/Unit/PushStateTests.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ - (void)testSetPushTimeValidation {
132132
PFMutablePushState *state = [[PFMutablePushState alloc] init];
133133
PFAssertThrowsInvalidArgumentException(state.pushDate = [NSDate distantPast]);
134134
PFAssertThrowsInvalidArgumentException(state.pushDate = [NSDate distantFuture]);
135+
136+
NSDate *slightlyPast = [NSDate dateWithTimeIntervalSinceNow:-1];
137+
PFAssertThrowsInvalidArgumentException(state.pushDate = slightlyPast);
138+
139+
NSDateComponents *toAdd = [[NSDateComponents alloc] init];
140+
toAdd.day = 13;
141+
NSDate *withinTwoWeeks = [[NSCalendar currentCalendar] dateByAddingComponents:toAdd toDate:[NSDate date] options:0];
142+
XCTAssertNoThrow(state.pushDate = withinTwoWeeks);
143+
toAdd.day = 14;
144+
toAdd.minute = 1;
145+
NSDate *beyondTwoWeeks = [[NSCalendar currentCalendar] dateByAddingComponents:toAdd toDate:[NSDate date] options:0];
146+
PFAssertThrowsInvalidArgumentException(state.pushDate = beyondTwoWeeks);
135147
}
136148

137149
@end

0 commit comments

Comments
 (0)