mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 10:28:33 -07:00
d83085ea7f
* Update zigbee-herdsman and zigbee-shepherd-converters. * Force Aqara S2 Lock endvices (#1764) * Start on zigbee-herdsman controller refactor. * More updates. * Cleanup zapp. * updates. * Propagate adapter disconnected event. * Updates. * Initial refactor to zigbee-herdsman. * Refactor deviceReceive to zigbee-herdsman. * Rename * Refactor deviceConfigure. * Finish bridge config. * Refactor availability. * Active homeassistant extension and more refactors. * Refactor groups. * Enable soft reset. * Activate group membership * Start on tests. * Enable reporting. * Add more controller tests. * Add more tests * Fix linting error. * Data en deviceReceive tests. * Move to zigbee-herdsman-converters. * More device publish tests. * Cleanup dependencies. * Bring device publish coverage to 100. * Bring home assistant test coverage to 100. * Device configure tests. * Attempt to fix tests. * Another attempt. * Another one. * Another one. * Another. * Add wait. * Longer wait. * Debug. * Update dependencies. * Another. * Begin on availability tests. * Improve availability tests. * Complete deviceAvailability tests. * Device bind tests. * More tests. * Begin networkmap refactors. * start on networkmap tests. * Network map tests. * Add utils tests. * Logger tests. * Settings and logger tests. * Ignore some stuff for coverage and add todos. * Add remaining missing tests. * Enforce 100% test coverage. * Start on groups test and refactor entityPublish to resolveEntity * Remove joinPathStorage, not used anymore as group information is stored into zigbee-herdsman database. * Fix linting issues. * Improve tests. * Add groups. * fix group membership. * Group: log names. * Convert MQTT message to string by default. * Fix group name. * Updates. * Revert configuration.yaml. * Add new line. * Fixes. * Updates. * Fix tests. * Ignore soft reset extension.
54 lines
2.2 KiB
JavaScript
54 lines
2.2 KiB
JavaScript
const utils = require('../lib/util/utils.js');
|
|
const version = require('../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('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;
|
|
})
|
|
});
|