Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Add getSerial function for device plugin #1444

Open
wants to merge 1 commit into
base: dev-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/mocks/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ngCordovaMocks.factory('$cordovaDevice', function () {
var platform = '';
var uuid = '';
var version = '';
var serial = '';

return {
/**
Expand Down Expand Up @@ -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;
},
Expand All @@ -118,6 +130,10 @@ ngCordovaMocks.factory('$cordovaDevice', function () {

getManufacturer: function () {
return this.manufacturer;
},

getSerial: function () {
return this.serial;
}
};
});
8 changes: 8 additions & 0 deletions src/plugins/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}]);
10 changes: 9 additions & 1 deletion test/mocks/device.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
})
});
7 changes: 6 additions & 1 deletion test/plugins/devices.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('Service: $cordovaDevice', function() {
platform: 'iOS',
uuid: 89749382749823749823,
version: 5,
manufacturer: 'apple'
manufacturer: 'apple',
serial: 'FK1RK67XGRY1'
};
}));

Expand Down Expand Up @@ -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);
});

});