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

describe("iOS Notification Object", () => {
  let notification;
7
  let someBadgeCount = 123, someSound = "someSound", someCategory = "some_notification_category", someThread = "thread-1";
8 9 10 11 12 13 14 15 16 17 18 19

  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,
20 21
          category: someCategory,
          "thread-id": someThread
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        },
        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,
37 38
          category: someCategory,
          "thread-id": someThread
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        },
        key1: "value1",
        key2: "value2"
      }
    ];

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

      it("should return 'regular' type", function () {
        expect(notification.getType()).to.equal("regular");
      });

      it("should return the alert object", () => {
        expect(notification.getMessage()).to.deep.equal(nativeNotification.aps.alert);
      });

      it("should return the sound", () => {
        expect(notification.getSound()).to.equal(someSound);
      });

      it("should return the badge count", () => {
        expect(notification.getBadgeCount()).to.equal(someBadgeCount);
      });

      it("should return the category", () => {
        expect(notification.getCategory()).to.equal(someCategory);
      });

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

74 75 76 77 78 79 80 81 82
      it("should return the custom data", () => {
        expect(notification.getData()).to.deep.equal({ key1: "value1", key2: "value2" });
      });
    });
  });

  describe("for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)", () => {
    let managedNativeNotification = {
      aps: {
83 84
        "content-available": 1,
        badge: someBadgeCount
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
      },
      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()).to.equal("managed");
    });

    it("should return the alert object", () => {
      expect(notification.getMessage()).to.equal(managedNativeNotification.managedAps.alert);
    });

    it("should return the sound", () => {
      expect(notification.getSound()).to.equal(someSound);
    });

    it("should return the badge count", () => {
      expect(notification.getBadgeCount()).to.equal(someBadgeCount);
    });

    it("should return the category", () => {
      expect(notification.getCategory()).to.equal(someCategory);
    });

    it("should return the custom data", () => {
      expect(notification.getData()).to.deep.equal({ managedAps: managedNativeNotification.managedAps, key1: "value1", key2: "value2" });
    });
  });
});