Skip to content

Commit

Permalink
cleaning up UnitTests.m
Browse files Browse the repository at this point in the history
  • Loading branch information
emawby committed Aug 4, 2020
1 parent 0fa5af4 commit 9d4afb4
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,11 @@ - (void)backgroundModesDisabledInXcode {
}

- (void)registerForPushNotifications {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[OneSignal registerForPushNotifications];
[self backgroundApp];
}

- (void)backgroundApp {
UIApplicationOverrider.currentUIApplicationState = UIApplicationStateBackground;
if (@available(iOS 13.0, *)) {
NSDictionary *sceneManifest = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationSceneManifest"];
if (sceneManifest) {
[[NSNotificationCenter defaultCenter] postNotificationName:UISceneWillDeactivateNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:UISceneDidEnterBackgroundNotification object:nil];
return;
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification object:nil];

#pragma clang diagnostic pop
[UnitTestCommonMethods backgroundApp];
}

- (UNNotificationResponse*)createBasiciOSNotificationResponse {
Expand Down Expand Up @@ -394,7 +382,7 @@ - (void)testCallingMethodsWorks_beforeInit {
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"tags"][@"key"], @"value");
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);

[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods runBackgroundThreads];
[UnitTestCommonMethods clearStateForAppRestart:self];

Expand Down Expand Up @@ -600,7 +588,7 @@ - (void)testPermissionChangeObserverWithNativeiOS10PromptCall {
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError* error) {}];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods runBackgroundThreads];

XCTAssertEqual(observer->fireCount, 1);
Expand Down Expand Up @@ -633,7 +621,7 @@ - (void)testTestPermissionChangeObserverWithNativeiOS10PromptCall {
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError* error) {}];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
// Full bug details explained in answerNotifiationPrompt
[UnitTestCommonMethods answerNotificationPrompt:true];
[UnitTestCommonMethods runBackgroundThreads];
Expand All @@ -655,7 +643,7 @@ - (void)testDeliverQuietly {
OSPermissionStateTestObserver* observer = [OSPermissionStateTestObserver new];
[OneSignal addPermissionObserver:observer];

[self backgroundApp];
[UnitTestCommonMethods backgroundApp];

//answer the prompt to allow notification
[UnitTestCommonMethods answerNotificationPrompt:true];
Expand Down Expand Up @@ -817,7 +805,7 @@ - (void)testPromptForPushNotificationsWithUserResponse {
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
didAccept = accepted;
}];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods answerNotificationPrompt:true];
[UnitTestCommonMethods runBackgroundThreads];
XCTAssertTrue(didAccept);
Expand All @@ -833,7 +821,7 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS8 {
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
didAccept = accepted;
}];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods answerNotificationPrompt:true];
[UnitTestCommonMethods runBackgroundThreads];
XCTAssertTrue(didAccept);
Expand All @@ -849,7 +837,7 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS7 {
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
didAccept = accepted;
}];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods answerNotificationPrompt:true];
[UnitTestCommonMethods runBackgroundThreads];
XCTAssertTrue(didAccept);
Expand Down Expand Up @@ -927,9 +915,12 @@ - (void)testIdsAvailableNotAcceptingNotifications {
settings:@{kOSSettingsKeyAutoPrompt: @false}];

__block BOOL idsAvailable1Called = false;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
idsAvailable1Called = true;
}];
#pragma clang diagnostic pop

[UnitTestCommonMethods runBackgroundThreads];

Expand All @@ -946,9 +937,12 @@ - (void)testIdsAvailableNotAcceptingNotifications {
settings:@{kOSSettingsKeyAutoPrompt: @false}];

__block BOOL idsAvailable2Called = false;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
idsAvailable2Called = true;
}];
#pragma clang diagnostic pop

[UnitTestCommonMethods runBackgroundThreads];
XCTAssertTrue(idsAvailable2Called);
Expand Down Expand Up @@ -1403,6 +1397,8 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
XCTAssertEqualObjects(localNotif.category, @"__dynamic__");
XCTAssertEqualObjects(localNotif.userInfo, userInfo);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
let categories = [UIApplication sharedApplication].currentUserNotificationSettings.categories;

XCTAssertEqual(categories.count, 1);
Expand All @@ -1411,6 +1407,7 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
XCTAssertEqualObjects(category.identifier, @"__dynamic__");

let actions = [category actionsForContext:UIUserNotificationActionContextDefault];
#pragma clang diagnostic pop
XCTAssertEqualObjects(actions[0].identifier, @"id1");
XCTAssertEqualObjects(actions[0].title, @"text1");
}
Expand All @@ -1419,7 +1416,7 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
- (void)testGeneratingLocalNotificationWithButtonsiOS8_osdata_format {
OneSignalHelperOverrider.mockIOSVersion = 8;
[UnitTestCommonMethods initOneSignalAndThreadWait];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];

let userInfo = @{@"aps": @{@"content_available": @1},
@"os_data": @{
Expand All @@ -1438,7 +1435,7 @@ - (void)testGeneratingLocalNotificationWithButtonsiOS8_osdata_format {
- (void)testGeneratingLocalNotificationWithButtonsiOS8 {
OneSignalHelperOverrider.mockIOSVersion = 8;
[UnitTestCommonMethods initOneSignalAndThreadWait];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];

let userInfo = @{@"aps": @{@"content_available": @1},
@"m": @"alert body only",
Expand Down Expand Up @@ -1668,8 +1665,8 @@ - (void)permissionChangedInSettingsOutsideOfApp: (BOOL)useSceneDelegate {

XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @0);
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest[@"identifier"]);
[self backgroundApp];

[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods setCurrentNotificationPermission:true];
[UnitTestCommonMethods foregroundApp];
[UnitTestCommonMethods runBackgroundThreads];
Expand All @@ -1686,7 +1683,7 @@ - (void)testPermissionChangedOutsideOfAppOverWithNewSession {
[self backgroundModesDisabledInXcode];

[UnitTestCommonMethods initOneSignalAndThreadWait];
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods runBackgroundThreads];
[UnitTestCommonMethods setCurrentNotificationPermission:true];

Expand All @@ -1709,15 +1706,15 @@ - (void) testOnSessionWhenResuming {
[UnitTestCommonMethods initOneSignalAndThreadWait];

// Don't make an on_session call if only out of the app for 20 secounds
[self backgroundApp];
NSDateOverrider.timeOffset = 10;
[UnitTestCommonMethods backgroundApp];
[NSDateOverrider advanceSystemTimeBy:10];
[UnitTestCommonMethods foregroundApp];
[UnitTestCommonMethods runBackgroundThreads];
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);

// Anything over 30 secounds should count as a session.
[self backgroundApp];
NSDateOverrider.timeOffset = 41;
[UnitTestCommonMethods backgroundApp];
[NSDateOverrider advanceSystemTimeBy:41];
[UnitTestCommonMethods foregroundApp];
[UnitTestCommonMethods runBackgroundThreads];

Expand All @@ -1731,7 +1728,7 @@ - (void) testOnSessionOnColdStart {
[UnitTestCommonMethods initOneSignalAndThreadWait];

// 2. Kill the app and wait 31 seconds
[self backgroundApp];
[UnitTestCommonMethods backgroundApp];
[UnitTestCommonMethods runBackgroundThreads];
[UnitTestCommonMethods clearStateForAppRestart:self];
[NSDateOverrider advanceSystemTimeBy:31];
Expand Down Expand Up @@ -2771,8 +2768,11 @@ - (void)testAllowsIncreasedAPNSTokenSize
}

- (void)testHexStringFromDataWithInvalidValues {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertNil([NSString hexStringFromData:nil]);
XCTAssertNil([NSString hexStringFromData:NULL]);
#pragma clang diagnostic pop
XCTAssertNil([NSString hexStringFromData:[NSData new]]);
}

Expand Down

0 comments on commit 9d4afb4

Please sign in to comment.