notification.ios.spec.js 3.71 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3
'use strict';
import { expect } from 'chai';
import IOSNotification from '../notification.ios';
4

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

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

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

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

yogevbd's avatar
yogevbd committed
50 51
      it('should return regular type', function () {
        expect(notification.getType()).to.equal('regular');
52 53
      });

yogevbd's avatar
yogevbd committed
54
      it('should return the alert object', () => {
55 56 57
        expect(notification.getMessage()).to.deep.equal(nativeNotification.aps.alert);
      });

yogevbd's avatar
yogevbd committed
58
      it('should return the sound', () => {
59 60 61
        expect(notification.getSound()).to.equal(someSound);
      });

yogevbd's avatar
yogevbd committed
62
      it('should return the badge count', () => {
63 64 65
        expect(notification.getBadgeCount()).to.equal(someBadgeCount);
      });

yogevbd's avatar
yogevbd committed
66
      it('should return the category', () => {
67 68 69
        expect(notification.getCategory()).to.equal(someCategory);
      });

yogevbd's avatar
yogevbd committed
70 71
      it('should return the thread', () => {
        expect(notification.getThread()).to.equal('thread-1');
72 73
      });

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

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

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

yogevbd's avatar
yogevbd committed
104 105
    it('should return managed type', function () {
      expect(notification.getType()).to.equal('managed');
106 107
    });

yogevbd's avatar
yogevbd committed
108
    it('should return the alert object', () => {
109 110 111
      expect(notification.getMessage()).to.equal(managedNativeNotification.managedAps.alert);
    });

yogevbd's avatar
yogevbd committed
112
    it('should return the sound', () => {
113 114 115
      expect(notification.getSound()).to.equal(someSound);
    });

yogevbd's avatar
yogevbd committed
116
    it('should return the badge count', () => {
117 118 119
      expect(notification.getBadgeCount()).to.equal(someBadgeCount);
    });

yogevbd's avatar
yogevbd committed
120
    it('should return the category', () => {
121 122 123
      expect(notification.getCategory()).to.equal(someCategory);
    });

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