Skip to content

Commit 2505e60

Browse files
committed
Test to ensure we register after apns response
* This new test is similar to the existing testNotificationPermissionsAcceptedBeforeAddingOneSiganl_waitsForAPNSTokenBeforePlayerCreate test above it however we are testing to ensure we register even when noitification permisions are note enabled.
1 parent 66b3d4f commit 2505e60

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,30 @@ - (void)testNotificationPermissionsAcceptedBeforeAddingOneSiganl_waitsForAPNSTok
739739
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"identifier"], @"0000000000000000000000000000000000000000000000000000000000000000");
740740
}
741741

742+
// We don't want wait for the developer to prompt for notifications, just register as as soon as we have an APNS token
743+
- (void)testWaitsForAPNSTokenBeforePlayerCreate {
744+
// 1. Set that notification permissions to unanwsered
745+
UNUserNotificationCenterOverrider.authorizationStatus = [NSNumber numberWithInteger:UNAuthorizationStatusNotDetermined];
746+
747+
// 2. Setup delay of APNs reaponse
748+
[UIApplicationOverrider setBlockApnsResponse:true];
749+
750+
// 3. Init OneSignal
751+
[UnitTestCommonMethods initOneSignal_andThreadWait];
752+
[NSObjectOverrider runPendingSelectors];
753+
754+
// 4. Don't make a network call right away
755+
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest);
756+
757+
// 5. Simulate APNs now giving us a push token
758+
[UIApplicationOverrider setBlockApnsResponse:false];
759+
[UnitTestCommonMethods runBackgroundThreads];
760+
761+
// 6. Ensure we registered with push token and it has the correct notification_types
762+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @-18);
763+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"identifier"], @"0000000000000000000000000000000000000000000000000000000000000000");
764+
}
765+
742766
- (void)testNotificationTypesWhenAlreadyAcceptedWithAutoPromptOffOnFristStartPreIos10 {
743767
OneSignalHelperOverrider.mockIOSVersion = 9;
744768
[UnitTestCommonMethods setCurrentNotificationPermission:true];

0 commit comments

Comments
 (0)