Fix tests.

This commit is contained in:
Koen Kanters
2019-11-06 20:51:31 +01:00
parent af770acd2d
commit 019b087af1
4 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ class NetworkMap extends BaseExtension {
let lastSeen = 'unknown';
const date = device.type === 'Coordinator' ? Date.now() : device.lastSeen;
if (date) {
lastSeen = utils.formatDate(date, 'ISO_8601_local', null);
lastSeen = utils.formatDate(date, 'ISO_8601_local');
}
labels.push(lastSeen);
+3 -4
View File
@@ -68,7 +68,7 @@ async function getZigbee2mqttVersion() {
});
}
function formatDate(date, type, _default) {
function formatDate(date, type) {
let result;
switch (type) {
@@ -82,8 +82,7 @@ function formatDate(date, type, _default) {
result = date;
break;
default:
result = _default;
break;
throw new Error(`Unsupported type '${type}'`);
}
return result;
@@ -122,6 +121,6 @@ module.exports = {
isIkeaTradfriDevice: (device) => ikeaTradfriManufacturerID.includes(device.manufacturerID),
isRouter: (device) => device.type === 'Router' && !forceEndDevice.includes(device.modelID),
isBatteryPowered: (device) => device.powerSource && device.powerSource === 'Battery',
formatDate: (date, type, _default=null) => formatDate(date, type, _default),
formatDate: (date, type) => formatDate(date, type),
equalsPartial,
};
-1
View File
@@ -52,7 +52,6 @@ function writeDefaultConfiguration() {
friendly_name: "button_double_key_interviewing"
},
"0x0017880104e45540": {
retain: false,
friendly_name: "ikea_onoff"
},
'0x000b57fffec6a5b7': {
+5
View File
@@ -50,4 +50,9 @@ describe('Utils', () => {
expect(utils.formatDate(date, 'ISO_8601_local').endsWith('+01:00')).toBeTruthy();
Date.prototype.getTimezoneOffset = getTimezoneOffset;
})
it('Throw exception when formating with invalid date', async () => {
var date = new Date('August 19, 1975 23:15:30 UTC+00:00');
expect(() => utils.formatDate(date, 'invalid', 1)).toThrowError("Unsupported type 'invalid'")
})
});