Skip to content

Commit

Permalink
New unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalmo Cirne committed Nov 17, 2015
1 parent d0c357a commit 1afe756
Show file tree
Hide file tree
Showing 24 changed files with 496 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
* Adopted the Objective-C Nullability syntax
* Serializing kit configurations rather than kit instances
* Defined default subspecs
* New and updated unit tests

## 5.1.2

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions Example/Tests/MPAppNotificationHandlerTests.m
@@ -0,0 +1,125 @@
//
// MPAppNotificationHandlerTests.m
//
// Copyright 2015 mParticle, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <XCTest/XCTest.h>
#import "MPAppNotificationHandler.h"
#import "MPPersistenceController.h"

@interface MPAppNotificationHandlerTests : XCTestCase

@end

@interface MPAppNotificationHandler(Tests)

@property (nonatomic, unsafe_unretained) MPUserNotificationRunningMode runningMode;

@end


@implementation MPAppNotificationHandlerTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (void)testFailedToRegisterForRemoteNotification {
MPAppNotificationHandler *appNotificationHandler = [MPAppNotificationHandler sharedInstance];
XCTAssertNotNil(appNotificationHandler, @"Should not have been nil.");

NSError *error = [NSError errorWithDomain:@"com.mParticle" code:123 userInfo:@{@"some":@"error"}];
[appNotificationHandler didFailToRegisterForRemoteNotificationsWithError:error];

NSArray *forwardedRecords = [[MPPersistenceController sharedInstance] fetchForwardRecords];
XCTAssertNil(forwardedRecords, @"Should have been nil.");

error = nil;
[appNotificationHandler didFailToRegisterForRemoteNotificationsWithError:error];

forwardedRecords = [[MPPersistenceController sharedInstance] fetchForwardRecords];
XCTAssertNil(forwardedRecords, @"Should have been nil.");
}

- (void)testRegisterForRemoteNotification {
MPAppNotificationHandler *appNotificationHandler = [MPAppNotificationHandler sharedInstance];
XCTAssertNotNil(appNotificationHandler, @"Should not have been nil.");

NSData *deviceToken = [@"<1234 5678>" dataUsingEncoding:NSUTF8StringEncoding];
[appNotificationHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];

NSArray *forwardedRecords = [[MPPersistenceController sharedInstance] fetchForwardRecords];
XCTAssertNil(forwardedRecords, @"Should have been nil.");

deviceToken = nil;
[appNotificationHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];

forwardedRecords = [[MPPersistenceController sharedInstance] fetchForwardRecords];
XCTAssertNil(forwardedRecords, @"Should have been nil.");
}

- (void)testHandleActionWithIdentifierForRemoteNotification {
MPAppNotificationHandler *appNotificationHandler = [MPAppNotificationHandler sharedInstance];

NSString *actionIdentifier = @"Action 1";
NSDictionary *notificationDictionary = @{};
[appNotificationHandler handleActionWithIdentifier:actionIdentifier forRemoteNotification:notificationDictionary];

actionIdentifier = nil;
notificationDictionary = nil;
[appNotificationHandler handleActionWithIdentifier:actionIdentifier forRemoteNotification:notificationDictionary];

NSArray *forwardedRecords = [[MPPersistenceController sharedInstance] fetchForwardRecords];
XCTAssertNil(forwardedRecords, @"Should have been nil.");
}

- (void)testOpenURLOptions {
MPAppNotificationHandler *appNotificationHandler = [MPAppNotificationHandler sharedInstance];

NSURL *url = [NSURL URLWithString:@"http://mparticle.com"];
NSDictionary *options = @{UIApplicationOpenURLOptionsSourceApplicationKey:@"testApp"};
[appNotificationHandler openURL:url options:options];

url = nil;
options = @{};
[appNotificationHandler openURL:url options:options];

url = nil;
options = nil;
[appNotificationHandler openURL:url options:options];
}

- (void)testReceivedUserNotification {
MPAppNotificationHandler *appNotificationHandler = [MPAppNotificationHandler sharedInstance];

NSDictionary *notification = @{};
NSString *action = @"";
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeRemote];
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeLocal];
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeAutoDetect];

notification = nil;
action = nil;
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeRemote];
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeLocal];
[appNotificationHandler receivedUserNotification:notification actionIdentifier:action userNoticicationMode:MPUserNotificationModeAutoDetect];
}

@end
3 changes: 2 additions & 1 deletion Example/Tests/MPConsumerInfoTests.m
Expand Up @@ -78,7 +78,8 @@ - (void)testInstance {
XCTAssertNotNil(consumerInfo, @"Consumer info instance should not have been nil.");

consumerInfo = [[MPConsumerInfo alloc] init];
[consumerInfo updateWithConfiguration:nil];
NSDictionary *nilDictionary = nil;
[consumerInfo updateWithConfiguration:nilDictionary];
XCTAssertNotNil(consumerInfo, @"Consumer info instance should not have been nil.");

consumerInfo = [[MPConsumerInfo alloc] init];
Expand Down

0 comments on commit 1afe756

Please sign in to comment.