notification.ios.spec.js 3.65 KB
Newer Older
yogevbd's avatar
yogevbd committed
1
import IOSNotification from '../lib/src/notification.ios';
2

yogevbd's avatar
yogevbd committed
3
describe.only('iOS Notification Object', () => {
4
  let notification;
yogevbd's avatar
yogevbd committed
5
  let someBadgeCount = 123, someSound = 'someSound', someCategory = 'some_notification_category', someThread = 'thread-1';
6

yogevbd's avatar
yogevbd committed
7
  describe('for a regular iOS push notification', () => {
8 9 10 11 12
    let regularNativeNotifications = [
      // basic example, without content-available = 1 (aka silent notification)
      {
        aps: {
          alert: {
yogevbd's avatar
yogevbd committed
13 14
            title: 'some title',
            body: 'some body'
15 16 17
          },
          badge: someBadgeCount,
          sound: someSound,
18
          category: someCategory,
yogevbd's avatar
yogevbd committed
19
          'thread-id': someThread
20
        },
yogevbd's avatar
yogevbd committed
21 22
        key1: 'value1',
        key2: 'value2'
23 24 25 26 27
      },

      // another example, with content-available but also with alert object (should not be a silent notification)
      {
        aps: {
yogevbd's avatar
yogevbd committed
28
          'content-available': 1,
29
          alert: {
yogevbd's avatar
yogevbd committed
30 31
            title: 'some title',
            body: 'some body'
32 33 34
          },
          badge: someBadgeCount,
          sound: someSound,
35
          category: someCategory,
yogevbd's avatar
yogevbd committed
36
          'thread-id': someThread
37
        },
yogevbd's avatar
yogevbd committed
38 39
        key1: 'value1',
        key2: 'value2'
40 41 42 43 44 45 46 47
      }
    ];

    regularNativeNotifications.forEach(nativeNotification => {
      beforeEach(() => {
        notification = new IOSNotification(nativeNotification);
      });

yogevbd's avatar
yogevbd committed
48
      it('should return regular type', function () {
yogevbd's avatar
yogevbd committed
49
        expect(notification.getType()).toEqual('regular');
50 51
      });

yogevbd's avatar
yogevbd committed
52
      it('should return the alert object', () => {
yogevbd's avatar
yogevbd committed
53
        expect(notification.getMessage()).toEqual(nativeNotification.aps.alert);
54 55
      });

yogevbd's avatar
yogevbd committed
56
      it('should return the sound', () => {
yogevbd's avatar
yogevbd committed
57
        expect(notification.getSound()).toEqual(someSound);
58 59
      });

yogevbd's avatar
yogevbd committed
60
      it('should return the badge count', () => {
yogevbd's avatar
yogevbd committed
61
        expect(notification.getBadgeCount()).toEqual(someBadgeCount);
62 63
      });

yogevbd's avatar
yogevbd committed
64
      it('should return the category', () => {
yogevbd's avatar
yogevbd committed
65
        expect(notification.getCategory()).toEqual(someCategory);
66 67
      });

yogevbd's avatar
yogevbd committed
68
      it('should return the thread', () => {
yogevbd's avatar
yogevbd committed
69
        expect(notification.getThread()).toEqual('thread-1');
70 71
      });

yogevbd's avatar
yogevbd committed
72
      it('should return the custom data', () => {
yogevbd's avatar
yogevbd committed
73
        expect(notification.getData()).toEqual({ key1: 'value1', key2: 'value2' });
74 75 76 77
      });
    });
  });

yogevbd's avatar
yogevbd committed
78
  describe('for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)', () => {
79 80
    let managedNativeNotification = {
      aps: {
yogevbd's avatar
yogevbd committed
81
        'content-available': 1,
82
        badge: someBadgeCount
83 84
      },
      managedAps: {
yogevbd's avatar
yogevbd committed
85 86
        action: 'CREATE',
        notificationId: '1',
87
        alert: {
yogevbd's avatar
yogevbd committed
88 89
          title: 'some title',
          body: 'some body'
90 91 92 93
        },
        sound: someSound,
        category: someCategory
      },
yogevbd's avatar
yogevbd committed
94 95
      key1: 'value1',
      key2: 'value2'
96 97 98 99 100 101
    };

    beforeEach(() => {
      notification = new IOSNotification(managedNativeNotification);
    });

yogevbd's avatar
yogevbd committed
102
    it('should return managed type', function () {
yogevbd's avatar
yogevbd committed
103
      expect(notification.getType()).toEqual('managed');
104 105
    });

yogevbd's avatar
yogevbd committed
106
    it('should return the alert object', () => {
yogevbd's avatar
yogevbd committed
107
      expect(notification.getMessage()).toEqual(managedNativeNotification.managedAps.alert);
108 109
    });

yogevbd's avatar
yogevbd committed
110
    it('should return the sound', () => {
yogevbd's avatar
yogevbd committed
111
      expect(notification.getSound()).toEqual(someSound);
112 113
    });

yogevbd's avatar
yogevbd committed
114
    it('should return the badge count', () => {
yogevbd's avatar
yogevbd committed
115
      expect(notification.getBadgeCount()).toEqual(someBadgeCount);
116 117
    });

yogevbd's avatar
yogevbd committed
118
    it('should return the category', () => {
yogevbd's avatar
yogevbd committed
119
      expect(notification.getCategory()).toEqual(someCategory);
120 121
    });

yogevbd's avatar
yogevbd committed
122
    it('should return the custom data', () => {
yogevbd's avatar
yogevbd committed
123
      expect(notification.getData()).toEqual({ managedAps: managedNativeNotification.managedAps, key1: 'value1', key2: 'value2' });
124 125 126
    });
  });
});