mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-28 05:24:29 +00:00
Fix tests.
This commit is contained in:
@@ -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
@@ -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,
|
||||
};
|
||||
|
||||
@@ -52,7 +52,6 @@ function writeDefaultConfiguration() {
|
||||
friendly_name: "button_double_key_interviewing"
|
||||
},
|
||||
"0x0017880104e45540": {
|
||||
retain: false,
|
||||
friendly_name: "ikea_onoff"
|
||||
},
|
||||
'0x000b57fffec6a5b7': {
|
||||
|
||||
@@ -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'")
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user