Skip to content

Commit

Permalink
Merge pull request ionic-team#695 from ArnaudSpanneut/fix-push-plugin
Browse files Browse the repository at this point in the history
Added push mocks factory
  • Loading branch information
pbernasconi committed Apr 1, 2015
2 parents 8239ac3 + 56b7076 commit 1d387af
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 1 deletion.
76 changes: 76 additions & 0 deletions dist/ng-cordova-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,82 @@ ngCordovaMocks.factory('$cordovaNetwork', function () {
}
};
});
'use strict';

/**
* @ngdoc service
* @name ngCordovaMocks.cordovaPush
*
* @description
* A service for testing push notifications features
* in an app build with ngCordova.
*/
ngCordovaMocks.factory('$cordovaPush', ['$q', '$timeout', '$rootScope', function($q, $timeout, $rootScope) {
var throwsError = false;

var deviceToken = '';

return {
/**
* @ngdoc property
* @name throwsError
* @propertyOf ngCordovaMocks.cordovaPush
*
* @description
* A flag that signals whether a promise should be rejected or not.
* This property should only be used in automated tests.
**/
throwsError: throwsError,

/**
* @ngdoc property
* @name deviceToken
* @propertyOf ngCordovaMocks.cordovaPush
*
* @description
* Token send when service register device
* This property should only be used in automated tests.
**/
deviceToken: deviceToken,

onNotification: function (notification) {
$timeout(function () {
$rootScope.$broadcast('$cordovaPush:notificationReceived', notification);
});
},

register: function (config) {
var _self = this;
var defer = $q.defer();
if (config !== undefined && config.ecb === undefined) {
config.ecb = this.onNotification;
}

if (this.throwsError) {
defer.reject('There was a register error.');
} else {
defer.resolve(this.deviceToken);
if (config && config.ecb) {
config.ecb({
event: 'registered',
regid: _self.deviceToken
});
}
}
return defer.promise;
},

unregister: function (options) {
var defer = $q.defer();
if (this.throwsError) {
defer.reject('There was a register error.');
} else {
defer.resolve();
}
return defer.promise;
},
};
}]);
/**
* @ngdoc service
* @name ngCordovaMocks.cordovaSocialSharing
Expand Down
Loading

0 comments on commit 1d387af

Please sign in to comment.