From 97b0acf7785aeea99477c148a00c55ca8e388083 Mon Sep 17 00:00:00 2001 From: ocReaper Date: Thu, 5 Oct 2017 08:45:18 +0200 Subject: [PATCH] implement getSerial function for device plugin (#1443) --- src/mocks/device.js | 16 ++++++++++++++++ src/plugins/device.js | 8 ++++++++ test/mocks/device.spec.js | 10 +++++++++- test/plugins/devices.spec.js | 7 ++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/mocks/device.js b/src/mocks/device.js index 4cf5f372..60d7999b 100644 --- a/src/mocks/device.js +++ b/src/mocks/device.js @@ -13,6 +13,7 @@ ngCordovaMocks.factory('$cordovaDevice', function () { var platform = ''; var uuid = ''; var version = ''; + var serial = ''; return { /** @@ -92,6 +93,17 @@ ngCordovaMocks.factory('$cordovaDevice', function () { */ version: version, + /** + @ngdoc property + @name serial + @propertyOf ngCordovaMocks.cordovaDevice + + @description + The serial of the device. + This property should only be used in automated tests. + */ + serial: serial, + getDevice: function () { return this.device; }, @@ -118,6 +130,10 @@ ngCordovaMocks.factory('$cordovaDevice', function () { getManufacturer: function () { return this.manufacturer; + }, + + getSerial: function () { + return this.serial; } }; }); diff --git a/src/plugins/device.js b/src/plugins/device.js index 14d3518c..3f1eba38 100644 --- a/src/plugins/device.js +++ b/src/plugins/device.js @@ -75,6 +75,14 @@ angular.module('ngCordova.plugins.device', []) */ getManufacturer: function () { return device.manufacturer; + }, + + /** + * Returns the device serial. + * @returns {String} + */ + getSerial: function () { + return device.serial; } }; }]); diff --git a/test/mocks/device.spec.js b/test/mocks/device.spec.js index 3b8b023b..11bb1d9f 100644 --- a/test/mocks/device.spec.js +++ b/test/mocks/device.spec.js @@ -65,5 +65,13 @@ describe('ngCordovaMocks', function() { var v = $cordovaDevice.getManufacturer(); expect(v).toEqual(manufacturer); }); + + it('should get the serial', function () { + var serial = 'FK1RK67XGRY1'; + $cordovaDevice.serial = serial; + + var v = $cordovaDevice.getSerial(); + expect(v).toEqual(serial); + }); }); -}) +}); diff --git a/test/plugins/devices.spec.js b/test/plugins/devices.spec.js index 966807ee..cee5fa80 100644 --- a/test/plugins/devices.spec.js +++ b/test/plugins/devices.spec.js @@ -15,7 +15,8 @@ describe('Service: $cordovaDevice', function() { platform: 'iOS', uuid: 89749382749823749823, version: 5, - manufacturer: 'apple' + manufacturer: 'apple', + serial: 'FK1RK67XGRY1' }; })); @@ -51,4 +52,8 @@ describe('Service: $cordovaDevice', function() { expect($cordovaDevice.getManufacturer()).toBe(window.device.manufacturer); }); + it('should return window.device.serial on getSerial', function() { + expect($cordovaDevice.getSerial()).toBe(window.device.serial); + }); + });