notification.ios.spec.js 3.5 KB
Newer Older
Lidan Hifi's avatar
Lidan Hifi committed
1
"use strict";
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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
import { expect } from "chai";
import IOSNotification from "../notification.ios";

describe("iOS Notification Object", () => {
  let notification;
  let someBadgeCount = 123, someSound = "someSound", someCategory = "some_notification_category";

  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
        },
        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
        },
        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);
      });

      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: {
        "content-available": 1
      },
      managedAps: {
        action: "CREATE",
        notificationId: "1",
        alert: {
          title: "some title",
          body: "some body"
        },
        badge: someBadgeCount,
        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" });
    });
  });
});