Skip to content

Commit 11f3ec7

Browse files
authored
Merge pull request #106 from CatalystCode/thcao/more-unit-tests
Adding more unit tests for iOS
2 parents bf05da8 + 2b9d05f commit 11f3ec7

20 files changed

+1702
-366
lines changed

azure-pipelines.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trigger:
77
- refs/tag/*
88

99
pool:
10-
vmImage: 'macOS-10.13'
10+
vmImage: 'macOS-10.14'
1111

1212
steps:
1313
- script: |
@@ -56,6 +56,8 @@ steps:
5656
- script: |
5757
pod install
5858
sudo cp -R ../node_modules/react-native-azurenotificationhub/ios Pods/RNAzureNotificationHub
59+
sudo chown -R $(id -u):$(id -g) Pods/RNAzureNotificationHub
60+
pod update
5961
displayName: 'Install CocoaPods dependencies'
6062
workingDirectory: '../sample/ios'
6163

@@ -77,7 +79,7 @@ steps:
7779
actions: 'test'
7880
scheme: 'ReactNativeAzureNotificationHubSample'
7981
sdk: 'iphonesimulator'
80-
configuration: 'Release'
82+
configuration: 'Debug'
8183
xcWorkspacePath: '../sample/ios/ReactNativeAzureNotificationHubSample.xcworkspace'
8284
xcodeVersion: '10'
8385
signingOption: 'nosign'

ios/AzureNotificationHubIOS.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const PushNotificationEmitter = new NativeEventEmitter(RCTAzureNotificationHubMa
2121

2222
const _notifHandlers = new Map();
2323

24-
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
25-
const NOTIF_REGISTER_EVENT = 'remoteNotificationsRegistered';
26-
const NOTIF_REGISTRATION_ERROR_EVENT = 'remoteNotificationRegistrationError';
27-
const NOTIF_REGISTER_AZURE_HUB_EVENT = 'azureNotificationHubRegistered';
28-
const NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = 'azureNotificationHubRegistrationError';
29-
const DEVICE_LOCAL_NOTIF_EVENT = 'localNotificationReceived';
24+
const DEVICE_LOCAL_NOTIF_EVENT = 'localNotificationReceived';
25+
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
26+
const NOTIF_REGISTER_EVENT = 'remoteNotificationRegistered';
27+
const NOTIF_REGISTRATION_ERROR_EVENT = 'remoteNotificationRegisteredError';
28+
const NOTIF_REGISTER_AZURE_HUB_EVENT = 'azureNotificationHubRegistered';
29+
const NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = 'azureNotificationHubRegisteredError';
3030

3131
/**
3232
* An event emitted by AzureNotificationHubIOS.

ios/RCTAzureNotificationHubManager.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
16D92203240700B100FB17C6 /* RCTAzureNotificationHub.m in Sources */ = {isa = PBXBuildFile; fileRef = 16D92202240700B100FB17C6 /* RCTAzureNotificationHub.m */; };
11+
4513A3AF24078CC300A0A996 /* RCTAzureNotificationHubUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 4513A3AE24078CC300A0A996 /* RCTAzureNotificationHubUtil.m */; };
12+
4519AACD240773E500A9CED7 /* RCTAzureNotificationHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4519AACB240773E500A9CED7 /* RCTAzureNotificationHandler.m */; };
1013
458BD41D1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 458BD41C1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.h */; };
1114
458BD41F1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 458BD41E1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.m */; };
1215
/* End PBXBuildFile section */
@@ -25,6 +28,12 @@
2528
/* End PBXCopyFilesBuildPhase section */
2629

2730
/* Begin PBXFileReference section */
31+
16D92201240700B100FB17C6 /* RCTAzureNotificationHub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAzureNotificationHub.h; sourceTree = "<group>"; };
32+
16D92202240700B100FB17C6 /* RCTAzureNotificationHub.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHub.m; sourceTree = "<group>"; };
33+
4513A3AD24078CC300A0A996 /* RCTAzureNotificationHubUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAzureNotificationHubUtil.h; sourceTree = "<group>"; };
34+
4513A3AE24078CC300A0A996 /* RCTAzureNotificationHubUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubUtil.m; sourceTree = "<group>"; };
35+
4519AACB240773E500A9CED7 /* RCTAzureNotificationHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHandler.m; sourceTree = "<group>"; };
36+
4519AACC240773E500A9CED7 /* RCTAzureNotificationHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAzureNotificationHandler.h; sourceTree = "<group>"; };
2837
458BD4191D9EDE5E007E3F13 /* libRCTAzureNotificationHubManager.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTAzureNotificationHubManager.a; sourceTree = BUILT_PRODUCTS_DIR; };
2938
458BD41C1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTAzureNotificationHubManager.h; sourceTree = "<group>"; };
3039
458BD41E1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubManager.m; sourceTree = "<group>"; };
@@ -60,6 +69,12 @@
6069
458BD41B1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager */ = {
6170
isa = PBXGroup;
6271
children = (
72+
4513A3AD24078CC300A0A996 /* RCTAzureNotificationHubUtil.h */,
73+
4513A3AE24078CC300A0A996 /* RCTAzureNotificationHubUtil.m */,
74+
4519AACC240773E500A9CED7 /* RCTAzureNotificationHandler.h */,
75+
4519AACB240773E500A9CED7 /* RCTAzureNotificationHandler.m */,
76+
16D92201240700B100FB17C6 /* RCTAzureNotificationHub.h */,
77+
16D92202240700B100FB17C6 /* RCTAzureNotificationHub.m */,
6378
458BD41C1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.h */,
6479
458BD41E1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.m */,
6580
);
@@ -105,6 +120,7 @@
105120
developmentRegion = English;
106121
hasScannedForEncodings = 0;
107122
knownRegions = (
123+
English,
108124
en,
109125
);
110126
mainGroup = 458BD4101D9EDE5E007E3F13;
@@ -122,6 +138,9 @@
122138
isa = PBXSourcesBuildPhase;
123139
buildActionMask = 2147483647;
124140
files = (
141+
4513A3AF24078CC300A0A996 /* RCTAzureNotificationHubUtil.m in Sources */,
142+
4519AACD240773E500A9CED7 /* RCTAzureNotificationHandler.m in Sources */,
143+
16D92203240700B100FB17C6 /* RCTAzureNotificationHub.m in Sources */,
125144
458BD41F1D9EDE5E007E3F13 /* RCTAzureNotificationHubManager.m in Sources */,
126145
);
127146
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#ifndef RCTAzureNotificationHandler_h
11+
#define RCTAzureNotificationHandler_h
12+
13+
#import "React/RCTEventEmitter.h"
14+
15+
@interface RCTAzureNotificationHandler : NSObject
16+
17+
// Class initializer
18+
- (nullable instancetype)initWithEventEmitter:(nonnull RCTEventEmitter *)eventEmitter;
19+
20+
// Handle local notifications
21+
- (void)localNotificationReceived:(nonnull NSNotification *)notification;
22+
23+
// Handle remote notifications
24+
- (void)remoteNotificationReceived:(nonnull NSNotification *)notification;
25+
26+
// Handle successful registration for remote notifications
27+
- (void)remoteNotificationRegistered:(nonnull NSNotification *)notification;
28+
29+
// Handle registration error for remote notifications
30+
- (void)remoteNotificationRegisteredError:(nonnull NSNotification *)notification;
31+
32+
// Handle successful registration for Azure Notification Hub
33+
- (void)azureNotificationHubRegistered:(nonnull NSNotification *)notification;
34+
35+
// Handle registration error for Azure Notification Hub
36+
- (void)azureNotificationHubRegisteredError:(nonnull NSNotification *)notification;
37+
38+
// Handle successful registration for UIUserNotificationSettings
39+
- (void)userNotificationSettingsRegistered:(nonnull NSNotification *)notification;
40+
41+
@end
42+
43+
#endif /* RCTAzureNotificationHandler_h */
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTAzureNotificationHub.h"
11+
#import "RCTAzureNotificationHandler.h"
12+
13+
@implementation RCTAzureNotificationHandler
14+
{
15+
@private
16+
RCTEventEmitter *_eventEmitter;
17+
}
18+
19+
// Class initializer
20+
- (nullable instancetype)initWithEventEmitter:(nonnull RCTEventEmitter *)eventEmitter
21+
{
22+
// Initialize superclass.
23+
self = [super init];
24+
25+
// Handle errors.
26+
if (!self)
27+
{
28+
return nil;
29+
}
30+
31+
_eventEmitter = eventEmitter;
32+
33+
return self;
34+
}
35+
36+
// Handle local notifications
37+
- (void)localNotificationReceived:(nonnull NSNotification *)notification
38+
{
39+
[_eventEmitter sendEventWithName:RCTLocalNotificationReceived
40+
body:notification.userInfo];
41+
}
42+
43+
// Handle remote notifications
44+
- (void)remoteNotificationReceived:(nonnull NSNotification *)notification
45+
{
46+
NSMutableDictionary *userInfo = [notification.userInfo mutableCopy];
47+
userInfo[RCTUserInfoRemote] = @YES;
48+
[_eventEmitter sendEventWithName:RCTRemoteNotificationReceived
49+
body:userInfo];
50+
}
51+
52+
// Handle successful registration for remote notifications
53+
- (void)remoteNotificationRegistered:(nonnull NSNotification *)notification
54+
{
55+
[_eventEmitter sendEventWithName:RCTRemoteNotificationRegistered
56+
body:notification.userInfo];
57+
}
58+
59+
// Handle registration error for remote notifications
60+
- (void)remoteNotificationRegisteredError:(nonnull NSNotification *)notification
61+
{
62+
NSError *error = notification.userInfo[RCTUserInfoError];
63+
NSDictionary *errorDetails = @{
64+
@"message": error.localizedDescription,
65+
@"code": @(error.code),
66+
@"details": error.userInfo,
67+
};
68+
[_eventEmitter sendEventWithName:RCTRemoteNotificationRegisteredError
69+
body:errorDetails];
70+
}
71+
72+
// Handle successful registration for Azure Notification Hub
73+
- (void)azureNotificationHubRegistered:(nonnull NSNotification *)notification
74+
{
75+
[_eventEmitter sendEventWithName:RCTAzureNotificationHubRegistered
76+
body:notification.userInfo];
77+
}
78+
79+
// Handle registration error for Azure Notification Hub
80+
- (void)azureNotificationHubRegisteredError:(nonnull NSNotification *)notification
81+
{
82+
NSError *error = notification.userInfo[RCTUserInfoError];
83+
NSDictionary *errorDetails = @{
84+
@"message": error.localizedDescription,
85+
@"code": @(error.code),
86+
@"details": error.userInfo,
87+
};
88+
89+
[_eventEmitter sendEventWithName:RCTAzureNotificationHubRegisteredError
90+
body:errorDetails];
91+
}
92+
93+
// Handle successful registration for UIUserNotificationSettings
94+
- (void)userNotificationSettingsRegistered:(nonnull NSNotification *)notification
95+
{
96+
RCTPromiseResolveBlock resolve = notification.userInfo[RCTUserInfoResolveBlock];
97+
if (resolve == nil)
98+
{
99+
return;
100+
}
101+
102+
UIUserNotificationSettings *notificationSettings = notification.userInfo[RCTUserInfoNotificationSettings];
103+
NSDictionary *notificationTypes = @{
104+
RCTNotificationTypeAlert: @((notificationSettings.types & UIUserNotificationTypeAlert) > 0),
105+
RCTNotificationTypeSound: @((notificationSettings.types & UIUserNotificationTypeSound) > 0),
106+
RCTNotificationTypeBadge: @((notificationSettings.types & UIUserNotificationTypeBadge) > 0),
107+
};
108+
109+
resolve(notificationTypes);
110+
}
111+
112+
@end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#ifndef RCTAzureNotificationHub_h
11+
#define RCTAzureNotificationHub_h
12+
13+
// Notification Hub events
14+
extern NSString *const RCTLocalNotificationReceived;
15+
extern NSString *const RCTRemoteNotificationReceived;
16+
extern NSString *const RCTRemoteNotificationRegistered;
17+
extern NSString *const RCTRemoteNotificationRegisteredError;
18+
extern NSString *const RCTAzureNotificationHubRegistered;
19+
extern NSString *const RCTAzureNotificationHubRegisteredError;
20+
extern NSString *const RCTUserNotificationSettingsRegistered;
21+
22+
// Config keys used when registering
23+
extern NSString *const RCTConnectionStringKey;
24+
extern NSString *const RCTHubNameKey;
25+
extern NSString *const RCTTagsKey;
26+
27+
// User info
28+
extern NSString *const RCTUserInfoNotificationSettings;
29+
extern NSString *const RCTUserInfoDeviceToken;
30+
extern NSString *const RCTUserInfoRemote;
31+
extern NSString *const RCTUserInfoResolveBlock;
32+
extern NSString *const RCTUserInfoRejectBlock;
33+
extern NSString *const RCTUserInfoSuccess;
34+
extern NSString *const RCTUserInfoError;
35+
36+
// Notification types
37+
extern NSString *const RCTNotificationTypeBadge;
38+
extern NSString *const RCTNotificationTypeSound;
39+
extern NSString *const RCTNotificationTypeAlert;
40+
41+
// Errors
42+
extern NSString *const RCTErrorUnableToRequestPermissions;
43+
extern NSString *const RCTErrorUnableToRequestPermissionsDetails;
44+
extern NSString *const RCTErrorUnableToRequestPermissionsTwice;
45+
extern NSString *const RCTErrorInvalidArguments;
46+
extern NSString *const RCTErrorMissingConnectionString;
47+
extern NSString *const RCTErrorMissingHubName;
48+
49+
// Completion type used in Azure Notification Hub's native methods
50+
typedef void (^RCTNativeCompletion)(NSError *error);
51+
52+
#endif /* RCTAzureNotificationHub_h */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
// Notification Hub events
11+
NSString *const RCTLocalNotificationReceived = @"localNotificationReceived";
12+
NSString *const RCTRemoteNotificationReceived = @"remoteNotificationReceived";
13+
NSString *const RCTRemoteNotificationRegistered = @"remoteNotificationRegistered";
14+
NSString *const RCTRemoteNotificationRegisteredError = @"remoteNotificationRegisteredError";
15+
NSString *const RCTAzureNotificationHubRegistered = @"azureNotificationHubRegistered";
16+
NSString *const RCTAzureNotificationHubRegisteredError = @"azureNotificationHubRegisteredError";
17+
NSString *const RCTUserNotificationSettingsRegistered = @"userNotificationSettingsRegistered";
18+
19+
// Config keys used when registering
20+
NSString *const RCTConnectionStringKey = @"connectionString";
21+
NSString *const RCTHubNameKey = @"hubName";
22+
NSString *const RCTTagsKey = @"tags";
23+
24+
// User info
25+
NSString *const RCTUserInfoNotificationSettings = @"notificationSettings";
26+
NSString *const RCTUserInfoDeviceToken = @"deviceToken";
27+
NSString *const RCTUserInfoRemote = @"remote";
28+
NSString *const RCTUserInfoResolveBlock = @"resolveBlock";
29+
NSString *const RCTUserInfoRejectBlock = @"rejectBlock";
30+
NSString *const RCTUserInfoSuccess = @"success";
31+
NSString *const RCTUserInfoError = @"error";
32+
33+
// Notification types
34+
NSString *const RCTNotificationTypeBadge = @"badge";
35+
NSString *const RCTNotificationTypeSound = @"sound";
36+
NSString *const RCTNotificationTypeAlert = @"alert";
37+
38+
// Errors
39+
NSString *const RCTErrorUnableToRequestPermissions = @"Unabled to request permissions";
40+
NSString *const RCTErrorUnableToRequestPermissionsDetails = @"Requesting push notifications is currently unavailable in an app extension";
41+
NSString *const RCTErrorUnableToRequestPermissionsTwice = @"Cannot call requestPermissions twice before the first has returned.";
42+
NSString *const RCTErrorInvalidArguments = @"Invalid arguments";
43+
NSString *const RCTErrorMissingConnectionString = @"Connection string cannot be null.";
44+
NSString *const RCTErrorMissingHubName = @"Hub name cannot be null.";

0 commit comments

Comments
 (0)