'use strict';

var expect = require('chai').expect;
var OneSignal = require('../lib');
var NotificationMock = require('./mocks/notification');
var Constants = require('../lib/constants');

describe('Notification Tests', function () {
  describe('Create Notification', function () {
    it('Expect to throw an error with non object data when creating a notification', function () {
      var notification = NotificationMock.emptyNotification;
      try {
        var response = new OneSignal.Notification(notification);
        expect(response).to.equal(undefined);
      } catch (err) {
        expect(err).to.be.an('string');
        expect(err).to.equal('Body must be a JSON object');
      }
    })

    it('Expect to throw an error with object without one of required fields on notification', function () {
      var notification = NotificationMock.invalidNotification;
      try {
        var response = new OneSignal.Notification(notification);
        expect(response).to.equal(undefined);
      } catch (err) {
        expect(err).to.be.an('string');
        expect(err).to.equal(
          'Body must include one of the following fields: contents, content_available, template_id');
      }
    })

    it('Expect to valid notification with contents', function () {
      var notification = NotificationMock.validWithContents;
      var response = new OneSignal.Notification(notification);
      expect(response).to.be.an('object');
      expect(response.postBody).to.be.an('object');
      expect(response.postBody.contents).to.be.an('object');
      expect(response.postBody.contents).to.have.property('en');
      expect(response.postBody.contents).to.have.property('pt');
    })

    it('Expect to valid notification with content available', function () {
      var notification = NotificationMock.validWithContentAvailable;
      var response = new OneSignal.Notification(notification);
      expect(response).to.be.an('object');
      expect(response.postBody).to.be.an('object');
      expect(response.postBody.content_available).to.be.an('boolean');
      expect(response.postBody.content_available)
        .to.equal(notification.content_available);
    })

    it('Expect to valid notification with template ID', function () {
      var notification = NotificationMock.validWithTemplateId;
      var response = new OneSignal.Notification(notification);
      expect(response).to.be.an('object');
      expect(response.postBody).to.be.an('object');
      expect(response.postBody.template_id).to.be.an('string');
      expect(response.postBody.template_id).to.equal(notification.template_id);
    })
  })

  describe('Setting OneSignal Properties', function () {
    it('Expect to throw an error when setting invalid parameter', function () {
      var notification = NotificationMock.validWithContents;
      var notificationObject = new OneSignal.Notification(notification);
      try {
        var parameter = NotificationMock.invalidParameter;
        notificationObject.setParameter(parameter.name, parameter.value);
        expect(response).to.equal(undefined);
      } catch (err) {
        expect(err).to.be.an('string');
        expect(err).to.equal(
          '"other" is not present in documentation. You should add a exclamation'
          .concat(' mark to the begging of the name, if you want to set it : !other'));
      }
    })

    it('Expect to valid data when setting parameter', function () {
      var notification = NotificationMock.validWithContents;
      var notificationObject = new OneSignal.Notification(notification);
      var parameter = NotificationMock.validParameter;
      notificationObject.setParameter(parameter.name, parameter.value);
      var response = notificationObject;
      expect(response).to.be.an('object');
      expect(response.postBody).to.be.an('object');
      expect(response.postBody.filters).to.be.an('string');
      expect(response.postBody.filters).to.equal(parameter.value);
    })
  })
})

@@ -2677,691 +2677,8 @@
 ) %7B%0A
-    it('Expect to throw an error when setting invalid parameter', function () %7B%0A      var notification = NotificationMock.validWithContents;%0A      var notificationObject = new OneSignal.Notification(notification);%0A      try %7B%0A        var parameter = NotificationMock.invalidParameter;%0A        notificationObject.setParameter(parameter.name, parameter.value);%0A        expect(response).to.equal(undefined);%0A      %7D catch (err) %7B%0A        expect(err).to.be.an('string');%0A        expect(err).to.equal(%0A          '%22other%22 is not present in documentation. You should add a exclamation'%0A          .concat(' mark to the begging of the name, if you want to set it : !other'));%0A      %7D%0A    %7D)%0A%0A
     

Remove old tests