mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 02:18:31 -07:00
1c3ad9da72
* add getZigbeeHerdsmanVersion Function Allow current zigbee-herdsman version to be exposed to controller for logging and to startup output. * Update utils.test.js Add tests for getZigbeeHerdsmanVersion() function * Update utils.js Added getZigbeeHerdsman to module exports * Update utils.js Fixed path because I'm dumb. * Update utils.test.js Apparently version numbers are important when they're different. * Update zigbee.js Added actual display of herdsman version output. * Update utils.js Remove git checking in getZigbeeHerdsmanVersion() * Update utils.test.js Remove commitHash from getZigbeeHerdsmanVersion test * Update utils.js Remove commitHash from getZigbeeHerdsmanVersion * Update utils.js * Update utils.test.js * Update utils.js Try removing less code this time. * Update utils.test.js * Update zigbee.js * Update utils.js * Update utils.js * Update utils.test.js * Update utils.js * Update utils.test.js * Update utils.js * Update utils.js * Update zigbee.js * Update utils.js Generalize getZigbeeHerdsmanVersion() to getDependVersion(), so any node_module dependency can be checked * Update zigbee.js * Update utils.test.js * Update utils.js * Update zigbee.js * Update utils.test.js * Update zigbee.js * Update zigbee.js * Update zigbee.js * Update zigbee.js * Update zigbee.js * Update utils.js * Update zigbee.js * Update utils.test.js * Update zigbee.js Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
65 lines
2.8 KiB
JavaScript
65 lines
2.8 KiB
JavaScript
const utils = require('../lib/util/utils.js');
|
|
const version = require('../package.json').version;
|
|
const versionHerdsman = require('../node_modules/zigbee-herdsman/package.json').version;
|
|
|
|
describe('Utils', () => {
|
|
describe('Is xiaomi device', () => {
|
|
it('Identify xiaomi device', () => {
|
|
const device = {type: 'Router', manufacturerID: 4151, manufacturerName: 'Xiaomi'};
|
|
expect(true).toBe(utils.isXiaomiDevice(device));
|
|
});
|
|
|
|
it('Identify xiaomi device without manufacturerName', () => {
|
|
const device = {type: 'Router', manufacturerID: 4447};
|
|
expect(true).toBe(utils.isXiaomiDevice(device));
|
|
});
|
|
|
|
it('Identify xiaomi device with different manufacturerName', () => {
|
|
const device = {type: 'Router', manufacturerID: 4151, manufacturerName: 'Trust International B.V.\u0000'};
|
|
expect(false).toBe(utils.isXiaomiDevice(device));
|
|
});
|
|
});
|
|
|
|
it('Convert milliseconds to seconds', () => {
|
|
expect(utils.millisecondsToSeconds(2000)).toBe(2);
|
|
})
|
|
|
|
it('Object has properties', () => {
|
|
expect(utils.objectHasProperties({a: 1, b: 2, c: 3}, ['a', 'b'])).toBeTruthy();
|
|
expect(utils.objectHasProperties({a: 1, b: 2, c: 3}, ['a', 'b', 'd'])).toBeFalsy();
|
|
})
|
|
|
|
it('git last commit', async () => {
|
|
let mockReturnValue = [];
|
|
jest.mock('git-last-commit', () => ({
|
|
getLastCommit: (cb) => cb(mockReturnValue[0], mockReturnValue[1])
|
|
}));
|
|
|
|
mockReturnValue = [false, {shortHash: '123'}]
|
|
expect(await utils.getZigbee2mqttVersion()).toStrictEqual({"commitHash": "123", "version": version});
|
|
|
|
mockReturnValue = [true, null]
|
|
expect(await utils.getZigbee2mqttVersion()).toStrictEqual({"commitHash": "unknown", "version": version});
|
|
})
|
|
|
|
it('Check dependency version', async () => {
|
|
var dependency = 'zigbee-herdsman';
|
|
expect(await utils.getDependencyVersion(dependency)).toStrictEqual({"version": versionHerdsman});
|
|
})
|
|
|
|
it('To local iso string', async () => {
|
|
var date = new Date('August 19, 1975 23:15:30 UTC+00:00');
|
|
var getTimezoneOffset = Date.prototype.getTimezoneOffset;
|
|
Date.prototype.getTimezoneOffset = () => 60;
|
|
expect(utils.formatDate(date, 'ISO_8601_local').endsWith('-01:00')).toBeTruthy();
|
|
Date.prototype.getTimezoneOffset = () => -60;
|
|
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'")
|
|
})
|
|
});
|