Skip to content

Commit 9f2bf56

Browse files
authored
Merge pull request #992 from OneSignal/unittest/add_waits_for_apns_response
Test to ensure we register after apns response
2 parents a87f4a8 + 2505e60 commit 9f2bf56

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)