Commit e6281eb0 authored by yogevbd's avatar yogevbd

Move ios and android commands to designated classes

parent 5cd92c2e
......@@ -8,5 +8,5 @@ sidebar_label: Android specific
refreshToken
```js
Notifications.refreshToken();
Notifications.android.refreshToken();
```
......@@ -8,7 +8,7 @@ sidebar_label: General
Return the notification that caused the app to launch from dead state.
```js
const notification: Notification = await getInitialNotification();
const notification: Notification = await Notifications.getInitialNotification();
```
## postLocalNotification(notification, id?)
......@@ -36,5 +36,5 @@ Notifications.cancelLocalNotification(id);
Check if the app has permissions to send remote notifications.
```js
const hasPermissions: boolean = await getInitialNotification();
const hasPermissions: boolean = await Notifications.getInitialNotification();
```
......@@ -8,61 +8,68 @@ sidebar_label: iOS specific
request permissions
```js
Notifications.requestPermissions();
Notifications.ios.requestPermissions();
```
## checkPermissions
checkPermissions
```js
Notifications.checkPermissions();
Notifications.ios.checkPermissions();
```
## abandonPermissions
Unregister for all remote notifications received via Apple Push Notification service
```js
Notifications.ios.abandonPermissions();
```
## registerPushKit
registerPushKit
```js
Notifications.registerPushKit();
Notifications.ios.registerPushKit();
```
## cancelAllLocalNotifications
cancelAllLocalNotifications
```js
Notifications.cancelAllLocalNotifications();
Notifications.ios.cancelAllLocalNotifications();
```
## getDeliveredNotifications
getDeliveredNotifications
```js
Notifications.getDeliveredNotifications();
Notifications.ios.getDeliveredNotifications();
```
## removeAllDeliveredNotifications
removeAllDeliveredNotifications
```js
Notifications.removeAllDeliveredNotifications();
Notifications.ios.removeAllDeliveredNotifications();
```
## removeDeliveredNotifications
removeDeliveredNotifications
```js
Notifications.removeDeliveredNotifications();
Notifications.ios.removeDeliveredNotifications();
```
## getBadgeCount
getBadgeCount
```js
Notifications.getBadgeCount();
Notifications.ios.getBadgeCount();
```
## setBadgeCount
setBadgeCount
```js
Notifications.setBadgeCount(1);
Notifications.ios.setBadgeCount(1);
```
\ No newline at end of file
......@@ -48,7 +48,7 @@ class NotificationsExampleApp extends Component {
}
requestPermissions() {
Notifications.requestPermissions();
Notifications.ios.requestPermissions();
}
setCategories() {
......
......@@ -6,8 +6,13 @@ import { Notification } from './DTO/Notification';
import { UniqueIdProvider } from './adapters/UniqueIdProvider';
import { CompletionCallbackWrapper } from './adapters/CompletionCallbackWrapper';
import { NotificationCategory } from './interfaces/NotificationCategory';
import { NotificationsIOS } from './NotificationsIOS';
import { NotificationsAndroid } from './NotificationsAndroid';
export class NotificationsRoot {
public readonly ios: NotificationsIOS;
public readonly android: NotificationsAndroid;
private readonly nativeEventsReceiver: NativeEventsReceiver;
private readonly nativeCommandsSender: NativeCommandsSender;
private readonly commands: Commands;
......@@ -25,22 +30,11 @@ export class NotificationsRoot {
this.uniqueIdProvider
);
this.eventsRegistry = new EventsRegistry(this.nativeEventsReceiver, this.completionCallbackWrapper);
}
/**
* Request permissions to send remote notifications - iOS only
*/
public requestPermissions() {
return this.commands.requestPermissions();
this.ios = new NotificationsIOS(this.commands);
this.android = new NotificationsAndroid(this.commands);
}
/**
* registerPushKit - iOS only
*/
public registerPushKit() {
return this.commands.registerPushKit();
}
/**
* postLocalNotification
*/
......@@ -62,21 +56,6 @@ export class NotificationsRoot {
this.commands.setCategories(categories);
}
/**
* getBadgesCount
*/
public getBadgeCount(): Promise<number> {
return this.commands.getBadgeCount();
}
/**
* setBadgeCount
* @param count number of the new badge count
*/
public setBadgeCount(count: number) {
return this.commands.setBadgeCount(count);
}
/**
* cancelLocalNotification
*/
......@@ -84,13 +63,6 @@ export class NotificationsRoot {
return this.commands.cancelLocalNotification(notificationId);
}
/**
* cancelAllLocalNotifications
*/
public cancelAllLocalNotifications() {
this.commands.cancelAllLocalNotifications();
}
/**
* isRegisteredForRemoteNotifications
*/
......@@ -98,39 +70,10 @@ export class NotificationsRoot {
return this.commands.isRegisteredForRemoteNotifications();
}
/**
* checkPermissions
*/
public checkPermissions() {
return this.commands.checkPermissions();
}
/**
* removeAllDeliveredNotifications
*/
public removeAllDeliveredNotifications() {
return this.commands.removeAllDeliveredNotifications();
}
/**
* removeDeliveredNotifications
* @param identifiers Array of notification identifiers
*/
public removeDeliveredNotifications(identifiers: Array<string>) {
return this.commands.removeDeliveredNotifications(identifiers);
}
/**
* Obtain the events registry instance
*/
public events(): EventsRegistry {
return this.eventsRegistry;
}
/**
* getDeliveredNotifications
*/
public getDeliveredNotifications(): Array<Notification> {
return this.commands.getDeliveredNotifications();
}
}
import { Commands } from './commands/Commands';
import { Platform } from 'react-native';
export class NotificationsAndroid {
constructor(private readonly commands: Commands) {
return new Proxy(this, {
get(target, name) {
if (Platform.OS === 'android') {
return (target as any)[name];
} else {
return () => {};
}
}
});
}
/**
* Refresh FCM token
*/
public refreshToken() {
return this.commands.refreshToken();
}
}
import { Notification } from './DTO/Notification';
import { Commands } from './commands/Commands';
import { Platform } from 'react-native';
export class NotificationsIOS {
constructor(private readonly commands: Commands) {
return new Proxy(this, {
get(target, name) {
if (Platform.OS === 'ios') {
return (target as any)[name];
} else {
return () => {};
}
}
});
}
/**
* Request permissions to send remote notifications
*/
public requestPermissions() {
return this.commands.requestPermissions();
}
/**
* Unregister for all remote notifications received via Apple Push Notification service
*/
public abandonPermissions() {
return this.commands.abandonPermissions();
}
/**
* registerPushKit
*/
public registerPushKit() {
return this.commands.registerPushKit();
}
/**
* getBadgesCount
*/
public getBadgeCount(): Promise<number> {
return this.commands.getBadgeCount();
}
/**
* setBadgeCount
* @param count number of the new badge count
*/
public setBadgeCount(count: number) {
return this.commands.setBadgeCount(count);
}
/**
* cancelAllLocalNotifications
*/
public cancelAllLocalNotifications() {
this.commands.cancelAllLocalNotifications();
}
/**
* checkPermissions
*/
public checkPermissions() {
return this.commands.checkPermissions();
}
/**
* removeAllDeliveredNotifications
*/
public removeAllDeliveredNotifications() {
return this.commands.removeAllDeliveredNotifications();
}
/**
* removeDeliveredNotifications
* @param identifiers Array of notification identifiers
*/
public removeDeliveredNotifications(identifiers: Array<string>) {
return this.commands.removeDeliveredNotifications(identifiers);
}
/**
* getDeliveredNotifications
*/
public getDeliveredNotifications(): Array<Notification> {
return this.commands.getDeliveredNotifications();
}
}
......@@ -9,6 +9,7 @@ interface NativeCommandsModule {
postLocalNotification(notification: Notification, id: number): void;
requestPermissions(): void;
abandonPermissions(): void;
refreshToken(): void;
registerPushKit(): void;
getBadgeCount(): Promise<number>;
setBadgeCount(count: number): void;
......@@ -46,6 +47,10 @@ export class NativeCommandsSender {
return this.nativeCommandsModule.abandonPermissions();
}
refreshToken() {
return this.nativeCommandsModule.refreshToken();
}
registerPushKit() {
return this.nativeCommandsModule.registerPushKit();
}
......
......@@ -75,4 +75,8 @@ export class Commands {
public getDeliveredNotifications(): Array<Notification> {
return this.nativeCommandsSender.getDeliveredNotifications();
}
public refreshToken() {
return this.nativeCommandsSender.refreshToken();
}
}
describe('Notifications-Android', () => {
let libUnderTest;
let deviceEventEmitterListenerStub;
let WixRNNotifications;
beforeEach(() => {
jest.mock('react-native', () => {
return {
NativeModules: {
WixRNNotifications: {
refreshToken: jest.fn(),
getInitialNotification: jest.fn(),
postLocalNotification: jest.fn(),
cancelLocalNotification: jest.fn()
}
},
DeviceEventEmitter: {
addListener: jest.fn()
}
};
});
deviceEventEmitterListenerStub = require('react-native').DeviceEventEmitter.addListener;
WixRNNotifications = require('react-native').NativeModules.WixRNNotifications;
libUnderTest = require('../lib/src/index.android');
});
describe('Registration token API', () => {
it('should assign callback to native event upon listener registration', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListener = () => {};
libUnderTest.NotificationsAndroid.setRegistrationTokenUpdateListener(userListener);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledWith('remoteNotificationsRegistered', userListener);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(1);
});
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListener = () => {};
const nativeListener = {
remove: jest.fn()
};
deviceEventEmitterListenerStub.mockReturnValueOnce(nativeListener);
libUnderTest.NotificationsAndroid.setRegistrationTokenUpdateListener(userListener);
libUnderTest.NotificationsAndroid.clearRegistrationTokenUpdateListener();
expect(nativeListener.remove).toHaveBeenCalledTimes(1);
});
it('shouldn`t fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearRegistrationTokenUpdateListener();
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
});
});
describe('notification-opening API', () => {
it('should assign callback to native event upon registration', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListenerStub = jest.fn();
libUnderTest.NotificationsAndroid.setNotificationOpenedListener(userListenerStub);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(1);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledWith('notificationOpened', expect.any(Function));
});
it('should assign a wrapper-callback upon registration', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListenerStub = jest.fn();
const notification = { foo: 'bar' };
libUnderTest.NotificationsAndroid.setNotificationOpenedListener(userListenerStub);
expect(userListenerStub).toHaveBeenCalledTimes(0);
deviceEventEmitterListenerStub.mock.calls[0][1](notification);
expect(userListenerStub).toHaveBeenCalledTimes(1);
expect(userListenerStub.mock.calls[0][0].getData()).toEqual(notification);
});
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListener = () => {};
const nativeListener = {
remove: jest.fn()
};
deviceEventEmitterListenerStub.mockReturnValueOnce(nativeListener);
libUnderTest.NotificationsAndroid.setNotificationOpenedListener(userListener);
libUnderTest.NotificationsAndroid.clearNotificationOpenedListener();
expect(nativeListener.remove).toHaveBeenCalledTimes(1);
});
it('shouldnt fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearNotificationOpenedListener();
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
});
});
describe('notification-receive API', () => {
it('should assign callback to native event upon registration', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListenerStub = jest.fn();
libUnderTest.NotificationsAndroid.setNotificationReceivedListener(userListenerStub);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(1);
expect(deviceEventEmitterListenerStub).toHaveBeenCalledWith('notificationReceived', expect.any(Function));
});
it('should assign a wrapper-callback upon registration', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListenerStub = jest.fn();
const notification = { foo: 'bar' };
libUnderTest.NotificationsAndroid.setNotificationReceivedListener(userListenerStub);
expect(userListenerStub).toHaveBeenCalledTimes(0);
deviceEventEmitterListenerStub.mock.calls[0][1](notification);
expect(userListenerStub).toHaveBeenCalledTimes(1);
expect(userListenerStub.mock.calls[0][0].getData()).toEqual(notification);
});
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
const userListener = () => {};
const nativeListener = {
remove: jest.fn()
};
deviceEventEmitterListenerStub.mockReturnValueOnce(nativeListener);
libUnderTest.NotificationsAndroid.setNotificationReceivedListener(userListener);
libUnderTest.NotificationsAndroid.clearNotificationReceivedListener();
expect(nativeListener.remove).toHaveBeenCalledTimes(1);
});
it('shouldn`t fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearNotificationReceivedListener();
expect(deviceEventEmitterListenerStub).toHaveBeenCalledTimes(0);
});
});
describe('Notification token', () => {
it('should refresh notification token upon refreshing request by the user', () => {
expect(WixRNNotifications.refreshToken).toHaveBeenCalledTimes(0);
libUnderTest.NotificationsAndroid.refreshToken();
expect(WixRNNotifications.refreshToken).toHaveBeenCalledTimes(1);
});
});
describe('Initial notification API', () => {
it('should return initial notification data if available', (done) => {
expect(WixRNNotifications.getInitialNotification).toHaveBeenCalledTimes(0);
const rawNotification = {foo: 'bar'};
WixRNNotifications.getInitialNotification.mockReturnValueOnce(Promise.resolve(rawNotification));
libUnderTest.PendingNotifications.getInitialNotification()
.then((notification) => {
expect(notification.getData()).toEqual(rawNotification);
done();
})
.catch((err) => done(err));
});
it('should return empty notification if not available', (done) => {
expect(WixRNNotifications.getInitialNotification).toHaveBeenCalledTimes(0);
WixRNNotifications.getInitialNotification.mockReturnValueOnce(Promise.resolve(null));
libUnderTest.PendingNotifications.getInitialNotification()
.then((notification) => {
expect(notification).toBeUndefined();
done();
})
.catch((err) => done(err));
});
});
describe('Local notification', () => {
const notification = {
title: 'notification-title',
body: 'notification-body'
};
it('should get published when posted manually', () => {
expect(WixRNNotifications.postLocalNotification).toHaveBeenCalledTimes(0);
const id = libUnderTest.NotificationsAndroid.localNotification(notification);
expect(id).toBeDefined();
expect(WixRNNotifications.postLocalNotification).toHaveBeenCalledWith(notification, id);
});
it('should be called with a unique ID', () => {
expect(WixRNNotifications.postLocalNotification).toHaveBeenCalledTimes(0);
const id = libUnderTest.NotificationsAndroid.localNotification(notification);
const id2 = libUnderTest.NotificationsAndroid.localNotification(notification);
expect(id).toBeDefined();
expect(id2).toBeDefined();
expect(id).not.toBe(id2);
});
it('should be cancellable with an ID', () => {
expect(WixRNNotifications.cancelLocalNotification).toHaveBeenCalledTimes(0);
libUnderTest.NotificationsAndroid.cancelLocalNotification(666);
expect(WixRNNotifications.cancelLocalNotification).toHaveBeenCalledWith(666);
});
});
});
describe('NotificationsIOS', () => {
let deviceEvents = [
'pushKitRegistered',
'remoteNotificationsRegistered',
'remoteNotificationsRegistrationFailed',
'notificationReceivedForeground',
'notificationOpened'
];
let NotificationsIOS, NotificationAction, NotificationCategory;
let constantGuid = 'some-random-uuid';
let identifiers = ['some-random-uuid', 'other-random-uuid'];
let someHandler = () => {};
let nativeModule;
let DeviceEventEmitter;
beforeEach(() => {
jest.mock('react-native', () => {
const RNBridgeModule = {
requestPermissionsWithCategories: jest.fn(),
abandonPermissions: jest.fn(),
registerPushKit: jest.fn(),
backgroundTimeRemaining: jest.fn(),
localNotification: jest.fn(),
cancelLocalNotification: jest.fn(),
cancelAllLocalNotifications: jest.fn(),
getBadgesCount: jest.fn(),
setBadgesCount: jest.fn(),
isRegisteredForRemoteNotifications: jest.fn(),
checkPermissions: jest.fn(),
removeAllDeliveredNotifications: jest.fn(),
removeDeliveredNotifications: jest.fn(),
getDeliveredNotifications: jest.fn()
};
return {
NativeModules: {
RNBridgeModule
},
DeviceEventEmitter: {
addListener: jest.fn(() => {
return {
remove: jest.fn()
};
})
}
};
});
nativeModule = require('react-native').NativeModules.RNBridgeModule;
DeviceEventEmitter = require('react-native').DeviceEventEmitter;
jest.mock('uuid', () => {
return {
v4: () => 'some-random-uuid'
};
});
let libUnderTest = require('../lib/src/index.ios');
NotificationsIOS = libUnderTest.default;
NotificationAction = libUnderTest.NotificationAction;
NotificationCategory = libUnderTest.NotificationCategory;
});
describe('Add Event Listener', () => {
deviceEvents.forEach(event => {
it(`should subscribe the given handler to device event: ${event}`, () => {
NotificationsIOS.addEventListener(event, someHandler);
expect(DeviceEventEmitter.addListener).toHaveBeenCalledWith(event, expect.any(Function));
});
});
it('should not subscribe to unknown device events', () => {
NotificationsIOS.addEventListener('someUnsupportedEvent', someHandler);
expect(DeviceEventEmitter.addListener).toHaveBeenCalledTimes(0);
});
});
describe('Remove Event Listener', () => {
deviceEvents.forEach(event => {
it(`should unsubscribe the given handler from device event: ${event}`, () => {
const removeCallback = jest.fn();
DeviceEventEmitter.addListener.mockReturnValueOnce({
remove: removeCallback
});
NotificationsIOS.addEventListener(event, someHandler);
NotificationsIOS.removeEventListener(event, someHandler);
expect(removeCallback).toHaveBeenCalledTimes(1);
});
});
it('should not unsubscribe to unknown device events', () => {
let someUnsupportedEvent = 'someUnsupportedEvent';
const removeCallback = jest.fn();
DeviceEventEmitter.addListener.mockReturnValueOnce({
remove: removeCallback
});
NotificationsIOS.addEventListener(someUnsupportedEvent, someHandler);
NotificationsIOS.removeEventListener(someUnsupportedEvent, someHandler);
expect(removeCallback).toHaveBeenCalledTimes(0);
});
});
describe('Notification actions handling', () => {
let someAction, someCategory;
let actionOpts = {
activationMode: 'foreground',
title: 'someAction',
behavior: 'default',
identifier: 'SOME_ACTION'
};
beforeEach(() => {
someAction = new NotificationAction(actionOpts, () => {});
someCategory = new NotificationCategory({
identifier: 'SOME_CATEGORY',
actions: [someAction],
context: 'default'
});
});
describe('register push notifications', () => {
it('should call native request permissions with array of categories', () => {
NotificationsIOS.requestPermissions([someCategory]);
expect(nativeModule.requestPermissionsWithCategories).toHaveBeenCalledWith([{
identifier: 'SOME_CATEGORY',
actions: [actionOpts],
context: 'default'
}]);
});
it('should call native request permissions with empty array if no categories specified', () => {
NotificationsIOS.requestPermissions();
expect(nativeModule.requestPermissionsWithCategories).toHaveBeenCalledWith([]);
});
});
describe('get badges count', () => {
it('should call native getBadgesCount', () => {
const callback = (count) => console.log(count);
NotificationsIOS.getBadgesCount(callback);
expect(nativeModule.getBadgesCount).toHaveBeenCalledWith(callback);
});
});
describe('set badges count', () => {
it('should call native setBadgesCount', () => {
NotificationsIOS.setBadgesCount(44);
expect(nativeModule.setBadgesCount).toHaveBeenCalledWith(44);
});
});
});
describe('register push kit for background notifications', function () {
it('should call native register push kit method', function () {
NotificationsIOS.registerPushKit();
expect(nativeModule.registerPushKit).toHaveBeenCalledTimes(1);
});
});
describe('Abandon push notifications permissions', () => {
it('should call native abandon permissions method', () => {
NotificationsIOS.abandonPermissions();
expect(nativeModule.abandonPermissions).toHaveBeenCalledTimes(1);
});
});
describe('Get background remaining time', () => {
it('should call native background remaining time method', () => {
let someCallback = () => {};
NotificationsIOS.backgroundTimeRemaining(someCallback);
expect(nativeModule.backgroundTimeRemaining).toHaveBeenCalledWith(someCallback);
});
});
describe('Dispatch local notification', () => {
it('should return generated notification guid', () => {
expect(NotificationsIOS.localNotification({})).toEqual(constantGuid);
});
it('should call native local notification method with generated notification guid and notification object', () => {
let someLocalNotification = {
body: 'some body',
title: 'some title',
alertAction: 'some action',
sound: 'sound',
category: 'SOME_CATEGORY',
userInfo: {
'key': 'value'
}
};
NotificationsIOS.localNotification(someLocalNotification);
expect(nativeModule.localNotification).toHaveBeenCalledWith(someLocalNotification, constantGuid);
});
});
describe('Cancel local notification', () => {
it('should call native cancel local notification method', () => {
NotificationsIOS.cancelLocalNotification(constantGuid);
expect(nativeModule.cancelLocalNotification).toHaveBeenCalledWith(constantGuid);
});
});
describe('Cancel all local notifications', () => {
it('should call native cancel all local notifications method', () => {
NotificationsIOS.cancelAllLocalNotifications();
expect(nativeModule.cancelAllLocalNotifications).toHaveBeenCalledWith();
});
});
describe('Is registered for remote notifications ', () => {
it('should call native is registered for remote notifications', () => {
NotificationsIOS.isRegisteredForRemoteNotifications();
expect(nativeModule.isRegisteredForRemoteNotifications).toHaveBeenCalledWith();
});
});
describe('Check permissions ', () => {
it('should call native check permissions', () => {
NotificationsIOS.checkPermissions();
expect(nativeModule.checkPermissions).toHaveBeenCalledWith();
});
});
describe('Remove all delivered notifications', () => {
it('should call native remove all delivered notifications method', () => {
NotificationsIOS.removeAllDeliveredNotifications();
expect(nativeModule.removeAllDeliveredNotifications).toHaveBeenCalledWith();
});
});
describe('Remove delivered notifications', () => {
it('should call native remove delivered notifications method', () => {
NotificationsIOS.removeDeliveredNotifications(identifiers);
expect(nativeModule.removeDeliveredNotifications).toHaveBeenCalledWith(identifiers);
});
});
describe('Get delivered notifications', () => {
it('should call native get delivered notifications method', () => {
const callback = (notifications) => console.log(notifications);
NotificationsIOS.getDeliveredNotifications(callback);
expect(nativeModule.getDeliveredNotifications).toHaveBeenCalledWith(callback);
});
});
});
import IOSNotification from '../lib/src/notification.ios';
describe('iOS Notification Object', () => {
let notification;
let someBadgeCount = 123, someSound = 'someSound', someCategory = 'some_notification_category', someThread = 'thread-1';
describe('for a regular iOS push notification', () => {
let regularNativeNotifications = [
// basic example, without content-available = 1 (aka silent notification)
{
aps: {
alert: {
title: 'some title',
body: 'some body'
},
badge: someBadgeCount,
sound: someSound,
category: someCategory,
thread: someThread
},
key1: 'value1',
key2: 'value2'
},
// another example, with content-available but also with alert object (should not be a silent notification)
{
aps: {
'content-available': 1,
alert: {
title: 'some title',
body: 'some body'
},
badge: someBadgeCount,
sound: someSound,
category: someCategory,
thread: someThread
},
key1: 'value1',
key2: 'value2'
}
];
regularNativeNotifications.forEach(nativeNotification => {
beforeEach(() => {
notification = new IOSNotification(nativeNotification);
});
it('should return regular type', function () {
expect(notification.getType()).toEqual('regular');
});
it('should return the alert object', () => {
expect(notification.getMessage()).toEqual(nativeNotification.aps.alert);
});
it('should return the sound', () => {
expect(notification.getSound()).toEqual(someSound);
});
it('should return the badge count', () => {
expect(notification.getBadgeCount()).toEqual(someBadgeCount);
});
it('should return the category', () => {
expect(notification.getCategory()).toEqual(someCategory);
});
it('should return the thread', () => {
expect(notification.getThread()).toEqual('thread-1');
});
it('should return the custom data', () => {
expect(notification.getData()).toEqual({ key1: 'value1', key2: 'value2' });
});
});
});
describe('for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)', () => {
let managedNativeNotification = {
aps: {
'content-available': 1,
badge: someBadgeCount
},
managedAps: {
action: 'CREATE',
notificationId: '1',
alert: {
title: 'some title',
body: 'some body'
},
sound: someSound,
category: someCategory
},
key1: 'value1',
key2: 'value2'
};
beforeEach(() => {
notification = new IOSNotification(managedNativeNotification);
});
it('should return managed type', function () {
expect(notification.getType()).toEqual('managed');
});
it('should return the alert object', () => {
expect(notification.getMessage()).toEqual(managedNativeNotification.managedAps.alert);
});
it('should return the sound', () => {
expect(notification.getSound()).toEqual(someSound);
});
it('should return the badge count', () => {
expect(notification.getBadgeCount()).toEqual(someBadgeCount);
});
it('should return the category', () => {
expect(notification.getCategory()).toEqual(someCategory);
});
it('should return the custom data', () => {
expect(notification.getData()).toEqual({ managedAps: managedNativeNotification.managedAps, key1: 'value1', key2: 'value2' });
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment