diff --git a/src/plugins/push_v5.js b/src/plugins/push_v5.js index 02706e9c..dcdb555f 100644 --- a/src/plugins/push_v5.js +++ b/src/plugins/push_v5.js @@ -14,6 +14,13 @@ angular.module('ngCordova.plugins.push_v5', []) q.resolve(push); return q.promise; }, + hasPermission : function () { + var q = $q.defer(); + PushNotification.hasPermission(function(response) { + q.resolve(response); + }); + return q.promise; + }, onNotification : function () { $timeout(function () { push.on('notification', function (notification) { diff --git a/test/plugins/push_V5.spec.js b/test/plugins/push_V5.spec.js new file mode 100644 index 00000000..6896e5bb --- /dev/null +++ b/test/plugins/push_V5.spec.js @@ -0,0 +1,53 @@ +describe('Service: $cordovaPushV5', function() { + + var $cordovaPushV5, $rootScope; + + beforeEach(module('ngCordova.plugins.push_v5')); + + beforeEach(inject(function (_$cordovaPushV5_, _$rootScope_) { + $cordovaPushV5 = _$cordovaPushV5_; + $rootScope = _$rootScope_; + + + window.PushNotification = { + init: angular.noop, + hasPermission: angular.noop, + }; + })); + + it('should call the PushNotification.init method', function() { + + var result; + var config = { someConfig: 1 }; + + spyOn(window.PushNotification, 'init').and.returnValue(true); + + $cordovaPushV5.initialize(config) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + expect(window.PushNotification.init.calls.argsFor(0)[0]).toBe(config); + expect(result).toBe(true); + }); + + it('should call the PushNotification.hasPermission method', function() { + + var result; + + spyOn(window.PushNotification, 'hasPermission') + .and.callFake(function (successCb) { + successCb({ isEnabled: true }); + }); + + $cordovaPushV5.hasPermission() + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + expect(window.PushNotification.hasPermission).toHaveBeenCalled; + expect(result.isEnabled).toBe(true); + }); +});