Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lwmqn-util

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lwmqn-util - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

docs/API.md

340

index.js

@@ -1,257 +0,231 @@

'use strict';
var lwm2mid = require('lwm2m-id');
const lwm2mid = require('lwm2m-id')
lwm2mid.Cmd = new lwm2mid._Enum({
"read": 0,
"write": 1,
"discover": 2,
"writeAttrs": 3,
"execute": 4,
"observe": 5,
"notify": 6,
"ping": 7,
"identify": 8,
"unknown": 255
});
read: 0,
write: 1,
discover: 2,
writeAttrs: 3,
execute: 4,
observe: 5,
notify: 6,
ping: 7,
identify: 8,
unknown: 255
})
var ut = {
getCmd: null, // define below
getOid: null, // define below
getRid: null, // define below
getRspCode: null, // define below
getSpecificResrcChar: lwm2mid.getRdef
};
/*************************************************************************************************/
/*** Polyfill ***/
/*************************************************************************************************/
// polyfill for ES5
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
const ut = {
getCmd: null, // define below
getOid: null, // define below
getRid: null, // define below
getRspCode: null, // define below
getSpecificResrcChar: lwm2mid.getRdef
}
/*************************************************************************************************/
/*** Identifier Getters ***/
/*************************************************************************************************/
/** ********************************************************************************************** */
/** * Identifier Getters ** */
/** ********************************************************************************************** */
ut.getCmd = function (id) {
var cmdItem = lwm2mid.getCmd(id);
return cmdItem ? { key: cmdItem.key, value: cmdItem.value } : undefined;
};
const cmdItem = lwm2mid.getCmd(id)
return cmdItem ? { key: cmdItem.key, value: cmdItem.value } : undefined
}
ut.cmdNum = function (id) {
var cmdNum = ut.getCmd(id);
return cmdNum ? cmdNum.value : undefined;
};
const cmdNum = ut.getCmd(id)
return cmdNum ? cmdNum.value : undefined
}
ut.cmdKey = function (id) {
var cmdKey = ut.getCmd(id);
return cmdKey ? cmdKey.key : undefined;
};
const cmdKey = ut.getCmd(id)
return cmdKey ? cmdKey.key : undefined
}
ut.getOid = function (oid) {
var oidItem = lwm2mid.getOid(oid);
return oidItem ? { key: oidItem.key, value: oidItem.value } : undefined;
};
const oidItem = lwm2mid.getOid(oid)
return oidItem ? { key: oidItem.key, value: oidItem.value } : undefined
}
ut.oidKey = function (oid) {
var oidItem = lwm2mid.getOid(oid);
return oidItem ? oidItem.key : oid.toString(); // if undefined, return itself
};
const oidItem = lwm2mid.getOid(oid)
return oidItem ? oidItem.key : oid.toString() // if undefined, return itself
}
ut.oidNum = function (oid) {
var oidItem = lwm2mid.getOid(oid);
let oidItem = lwm2mid.getOid(oid)
oidItem = oidItem ? oidItem.value : parseInt(oid); // if undefined, return parseInt(itself)
return isNaN(oidItem) ? oid : oidItem;
};
if (oidItem) {
return oidItem.value
} else {
if (oid.toString().match(/^[0-9]+$/)) {
var oidNumber = parseInt(oid)
if (!isNaN(oidNumber)) oid = oidNumber
}
return oid
}
}
ut.getRid = function (oid, rid) {
var ridItem = lwm2mid.getRid(oid, rid);
return ridItem ? { key: ridItem.key, value: ridItem.value } : undefined;
};
const ridItem = lwm2mid.getRid(oid, rid)
return ridItem ? { key: ridItem.key, value: ridItem.value } : undefined
}
ut.ridKey = function (oid, rid) {
var ridItem;
let ridItem
if (typeof rid === 'undefined') {
rid = oid;
ridItem = lwm2mid.getRid(rid); // here, oid is rid
} else {
ridItem = lwm2mid.getRid(oid, rid);
}
if (typeof rid === 'undefined') {
rid = oid
ridItem = lwm2mid.getRid(rid) // here, oid is rid
} else {
ridItem = lwm2mid.getRid(oid, rid)
}
return ridItem ? ridItem.key : rid.toString(); // if undefined, return itself
};
return ridItem ? ridItem.key : rid.toString() // if undefined, return itself
}
ut.ridNum = function (oid, rid) {
var ridItem = lwm2mid.getRid(oid, rid);
let ridItem = lwm2mid.getRid(oid, rid)
if (typeof rid === 'undefined')
rid = oid;
if (typeof rid === 'undefined') rid = oid
ridItem = ridItem ? ridItem.value : parseInt(rid); // if undefined, return parseInt(itself)
return isNaN(ridItem) ? rid : ridItem;
};
if (ridItem) {
return ridItem.value
} else {
if (rid.toString().match(/^[0-9]+$/)) {
var ridNumber = parseInt(rid)
if (!isNaN(ridNumber)) rid = ridNumber
}
return rid
}
}
ut.getRspCode = function (code) {
var rspItem = lwm2mid.getRspCode(code);
return rspItem ? { key: rspItem.key, value: rspItem.value } : undefined;
};
const rspItem = lwm2mid.getRspCode(code)
return rspItem ? { key: rspItem.key, value: rspItem.value } : undefined
}
ut.rspCodeKey = function (code) {
var k = ut.getRspCode(code);
return k ? k.key : undefined;
};
const k = ut.getRspCode(code)
return k ? k.key : undefined
}
ut.rspCodeNum = function (code) {
var n = ut.getRspCode(code);
return n ? n.value : undefined;
};
const n = ut.getRspCode(code)
return n ? n.value : undefined
}
/*************************************************************************************************/
/*** Tackling Path ***/
/*************************************************************************************************/
/** ********************************************************************************************** */
/** * Tackling Path ** */
/** ********************************************************************************************** */
ut.createPath = function () {
if (arguments.length === 0)
throw new TypeError('Each argument should be a string or a number.');
if (arguments.length === 0) throw new TypeError('Each argument should be a string or a number.')
var args = Array.prototype.slice.call(arguments),
connector = args[0],
path = '';
const args = Array.prototype.slice.call(arguments)
const connector = args[0]
let path = ''
args.forEach(function (arg, i) {
if (!isValidArgType(arg))
throw new TypeError('Each argument should be a string or a number.');
args.forEach((arg, i) => {
if (!isValidArgType(arg)) throw new TypeError('Each argument should be a string or a number.')
if (i !== 0)
path = path + arg + connector;
});
if (i !== 0) path = path + arg + connector
})
return path.slice(0, path.length - 1);
};
return path.slice(0, path.length - 1)
}
ut.slashPath = function (path) {
if (typeof path !== 'string')
throw new TypeError('Input path should be a string.');
if (typeof path !== 'string') throw new TypeError('Input path should be a string.')
path = path.replace(/\./g, '/'); // tranform dot notation into slash notation
path = path.replace(/\./g, '/') // tranform dot notation into slash notation
if (path[0] === '/') // if the first char of topic is '/', take it off
path = path.slice(1);
// if the first char of topic is '/', take it off
if (path[0] === '/') path = path.slice(1)
if (path[path.length-1] === '/') // if the last char of topic is '/', take it off
path = path.slice(0, path.length - 1);
// if the last char of topic is '/', take it off
if (path[path.length - 1] === '/') path = path.slice(0, path.length - 1)
return path;
};
return path
}
ut.dotPath = function (path) {
if (typeof path !== 'string')
throw new TypeError('Input path should be a string.');
if (typeof path !== 'string') throw new TypeError('Input path should be a string.')
path = path.replace(/\//g, '.'); // tranform slash notation into dot notation
path = path.replace(/\//g, '.') // tranform slash notation into dot notation
if (path[0] === '.') // if the first char of topic is '.', take it off
path = path.slice(1);
// if the first char of topic is '.', take it off
if (path[0] === '.') path = path.slice(1)
if (path[path.length-1] === '.') // if the last char of topic is '.', take it off
path = path.slice(0, path.length - 1);
// if the last char of topic is '.', take it off
if (path[path.length - 1] === '.') path = path.slice(0, path.length - 1)
return path;
};
return path
}
ut.pathItems = function (path) {
return ut.slashPath(path).split('/');
};
return ut.slashPath(path).split('/')
}
ut.buildPathValuePairs = function (rootPath, obj) {
var result = {};
rootPath = ut.dotPath(rootPath);
let result = {}
rootPath = ut.dotPath(rootPath)
if (obj && typeof obj === 'object') {
if (rootPath !== undefined && rootPath !== '' && rootPath !== '.' && rootPath !== '/')
rootPath = rootPath + '.';
if (obj && typeof obj === 'object') {
if (rootPath !== undefined && rootPath !== '' && rootPath !== '.' && rootPath !== '/') rootPath = `${rootPath}.`
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var n = obj[key];
// Tricky: objList is an array, don't buid its full path, or updating new list will fail
if (n && typeof n === 'object' && key !== 'objList')
result = Object.assign(result, ut.buildPathValuePairs(rootPath + key, n));
else
result[rootPath + key] = n;
}
}
} else {
result[rootPath] = obj;
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const n = obj[key]
// Tricky: objList is an array, don't buid its full path, or updating new list will fail
if (n && typeof n === 'object' && key !== 'objList') result = Object.assign(result, ut.buildPathValuePairs(rootPath + key, n))
else result[rootPath + key] = n
}
}
return result;
};
} else {
result[rootPath] = obj
}
return result
}
ut.isGoodResponse = function (status) {
var statusCode = ut.getRspCode(status),
goodCodes = [ 200, 201, 202, 204, 205 ],
included = false;
const statusCode = ut.getRspCode(status)
const goodCodes = [200, 201, 202, 204, 205]
let included = false
if (typeof statusCode === 'undefined')
return false;
if (typeof statusCode === 'undefined') return false
goodCodes.forEach(function (v) {
if (v === statusCode.value)
included = true;
});
goodCodes.forEach((v) => {
if (v === statusCode.value) included = true
})
return included;
};
return included
}
ut.getAccessCtrl = function (oid, rid) {
var chr = lwm2mid.getRdef(oid, rid);
return chr ? chr.access : undefined;
}; // undefined / resrc characteristic
const chr = lwm2mid.getRdef(oid, rid)
return chr ? chr.access : undefined
} // undefined / resrc characteristic
ut.jsonify = function (str) {
var obj;
let obj
if (typeof str !== 'string') throw new TypeError('Input str should be a string.')
if (typeof str !== 'string')
throw new TypeError('Input str should be a string.');
try {
obj = JSON.parse(str)
} catch (e) {
return str
}
return obj
} // undefined/result
try {
obj = JSON.parse(str);
} catch (e) {
return str;
}
return obj;
}; // undefined/result
function isValidArgType (param) {
let isValid = true
function isValidArgType(param) {
var isValid = true;
if (typeof param !== 'number' && typeof param !== 'string') {
isValid = false
} else if (typeof param === 'number') {
isValid = !isNaN(param)
}
if (typeof param !== 'number' && typeof param !== 'string') {
isValid = false;
} else if (typeof param === 'number') {
isValid = !isNaN(param);
}
return isValid;
return isValid
}
module.exports = ut;
module.exports = ut
{
"name": "lwmqn-util",
"version": "0.5.1",
"version": "0.5.2",
"description": "Utility for LWMQN mqtt-shepherd server and mqtt-node client libraries",
"main": "index.js",
"scripts": {
"test": "mocha -u bdd --reporter spec"
"lint": "standard --env mocha | snazzy",
"lint-fix": "standard --env mocha --fix | snazzy",
"test": "standard --env mocha && nyc mocha -u bdd --reporter spec",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},

@@ -30,4 +33,8 @@ "repository": {

"chai": "^4.2.0",
"mocha": "^6.1.4"
"coveralls": "^3.0.3",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"snazzy": "^8.0.0",
"standard": "^12.0.1"
}
}

@@ -1,24 +0,53 @@

# lwmqn-util
Utility for LWMQN mqtt-shepherd server and mqtt-node client libraries.
![LWMQN Network](https://raw.githubusercontent.com/lwmqn/documents/master/media/lwmqn_net.png)
[![Travis branch](https://img.shields.io/travis/lwmqn/lwmqn-util/master.svg?maxAge=2592000)](https://travis-ci.org/lwmqn/lwmqn-util)
[![npm](https://img.shields.io/npm/v/lwmqn-util.svg?maxAge=2592000)](https://www.npmjs.com/package/lwmqn-util)
[![npm](https://img.shields.io/npm/l/lwmqn-util.svg?maxAge=2592000)](https://www.npmjs.com/package/lwmqn-util)
<div align="center">
<br />
**lwmqn-util** is an utility for LWMQN mqtt-shepherd server and mqtt-node client libraries.
[![Greenkeeper badge](https://badges.greenkeeper.io/lwmqn/lwmqn-util.svg?style=flat-square)](https://greenkeeper.io/)
[![NPM version](https://img.shields.io/npm/v/lwmqn-util.svg?style=flat-square)](https://www.npmjs.com/package/lwmqn-util)
[![NPM downloads](https://img.shields.io/npm/dm/lwmqn-util.svg?style=flat-square)](https://www.npmjs.com/package/lwmqn-util)
[![Travis branch](https://img.shields.io/travis/lwmqn/lwmqn-util/master.svg?maxAge=2592000&style=flat-square)](https://travis-ci.org/lwmqn/lwmqn-util)
[![Coverage Status](https://coveralls.io/repos/github/lwmqn/lwmqn-util/badge.svg?branch=master&style=flat-square)](https://coveralls.io/github/lwmqn/lwmqn-util?branch=master)
[![Gitter](https://img.shields.io/gitter/room/lwmqn/Lobby.svg?style=flat-square)](https://gitter.im/lwmqn/Lobby)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
![pr-welcoming-image](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
## Documentation
</div>
Please visit the [Wiki](https://github.com/lwmqn/lwmqn-util/wiki).
-------
## Overview
## What is LWMQN
**lwmqn-util** is a utility for Lightweight Mqtt Machine Network Server([mqtt-shepherd](https://github.com/lwmqn/mqtt-shepherd)) and Client([mqtt-node](https://github.com/lwmqn/mqtt-node)) modules. This utility provides some common methods of getting identifiers in string or in number, getting command ids, getting response codes, and tackling the path of resource alloaction.
Lightweight MQTT machine network ([**LWMQN**](http://lwmqn.github.io)) is an open source project that follows part of [**OMA LWM2M v1.0**](http://technical.openmobilealliance.org/Technical/technical-information/release-program/current-releases/oma-lightweightm2m-v1-0) specification to meet the minimum requirements of machine network management.
### Server-side and Client-side Libraries:
- LWMQN project provides you with this machine-side **mqtt-node** library and a server-side [**mqtt-shepherd**](https://github.com/lwmqn/mqtt-shepherd) library to build your machine network with JavaScript and node.js easily.
* Server-side library: [**mqtt-shepherd**](https://github.com/lwmqn/mqtt-shepherd)
* Client-side library: [**mqtt-node**](https://github.com/lwmqn/mqtt-node)
* [**A simple demo webapp**](https://github.com/lwmqn/lwmqn-demo)
**lwmqn-util** is a utility for Lightweight Mqtt Machine Network Server([mqtt-shepherd](https://github.com/lwmqn/mqtt-shepherd)) and Client([mqtt-node](https://github.com/lwmqn/mqtt-node)) modules. This utility provides some common methods of getting identifiers in string or in number, getting command ids, getting response codes, and tackling the path of resource alloaction.
-------
## Installation
> $ npm install lwmqn-util --save
Currently [Node.js 8.x LTS](https://nodejs.org/en/about/releases/) or higher is required.
```bash
$ npm install lwmqn-util
```
-------
## Documentation
Please visit the <a href="https://github.com/lwmqn/lwmqn-util/blob/master/docs/API.md"><code><b>API</b></code></a>.
-------
## License
Licensed under [MIT](https://github.com/lwmqn/lwmqn-util/blob/master/LICENSE).

@@ -1,596 +0,596 @@

var expect = require('chai').expect,
util = require('../index.js'); // lwm2m-util module
/* eslint-env mocha */
const { expect } = require('chai')
const util = require('../index.js') // lwm2m-util module
describe('APIs Arguments Type Check', function() {
describe('#.getOid', function() {
it('is a function', function () {
expect(util.getOid).to.be.a('function');
});
describe('APIs Arguments Type Check', () => {
describe('#.getOid', () => {
it('is a function', () => {
expect(util.getOid).to.be.a('function')
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.getOid(); }).to.throw(TypeError);
expect(function () { return util.getOid(undefined); }).to.throw(TypeError);
expect(function () { return util.getOid(null); }).to.throw(TypeError);
expect(function () { return util.getOid(NaN); }).to.throw(TypeError);
expect(function () { return util.getOid([]); }).to.throw(TypeError);
expect(function () { return util.getOid({}); }).to.throw(TypeError);
expect(function () { return util.getOid(true); }).to.throw(TypeError);
expect(function () { return util.getOid(new Date()); }).to.throw(TypeError);
expect(function () { return util.getOid(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.getOid()).to.throw(TypeError)
expect(() => util.getOid(undefined)).to.throw(TypeError)
expect(() => util.getOid(null)).to.throw(TypeError)
expect(() => util.getOid(NaN)).to.throw(TypeError)
expect(() => util.getOid([])).to.throw(TypeError)
expect(() => util.getOid({})).to.throw(TypeError)
expect(() => util.getOid(true)).to.throw(TypeError)
expect(() => util.getOid(new Date())).to.throw(TypeError)
expect(() => util.getOid(() => {})).to.throw(TypeError)
expect(function () { return util.getOid(3); }).not.to.throw(Error);
expect(function () { return util.getOid('3'); }).not.to.throw(Error);
expect(function () { return util.getOid('xx'); }).not.to.throw(Error);
});
});
expect(() => util.getOid(3)).not.to.throw(Error)
expect(() => util.getOid('3')).not.to.throw(Error)
expect(() => util.getOid('xx')).not.to.throw(Error)
})
})
describe('#.oidKey', function() {
it('is a function', function () {
expect(util.oidKey).to.be.a('function');
});
describe('#.oidKey', () => {
it('is a function', () => {
expect(util.oidKey).to.be.a('function')
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.oidKey(); }).to.throw(TypeError);
expect(function () { return util.oidKey(undefined); }).to.throw(TypeError);
expect(function () { return util.oidKey(null); }).to.throw(TypeError);
expect(function () { return util.oidKey(NaN); }).to.throw(TypeError);
expect(function () { return util.oidKey([]); }).to.throw(TypeError);
expect(function () { return util.oidKey({}); }).to.throw(TypeError);
expect(function () { return util.oidKey(true); }).to.throw(TypeError);
expect(function () { return util.oidKey(new Date()); }).to.throw(TypeError);
expect(function () { return util.oidKey(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.oidKey()).to.throw(TypeError)
expect(() => util.oidKey(undefined)).to.throw(TypeError)
expect(() => util.oidKey(null)).to.throw(TypeError)
expect(() => util.oidKey(NaN)).to.throw(TypeError)
expect(() => util.oidKey([])).to.throw(TypeError)
expect(() => util.oidKey({})).to.throw(TypeError)
expect(() => util.oidKey(true)).to.throw(TypeError)
expect(() => util.oidKey(new Date())).to.throw(TypeError)
expect(() => util.oidKey(() => {})).to.throw(TypeError)
expect(function () { return util.oidKey(3); }).not.to.throw(Error);
expect(function () { return util.oidKey('3'); }).not.to.throw(Error);
expect(function () { return util.oidKey('xx'); }).not.to.throw(Error);
});
});
expect(() => util.oidKey(3)).not.to.throw(Error)
expect(() => util.oidKey('3')).not.to.throw(Error)
expect(() => util.oidKey('xx')).not.to.throw(Error)
})
})
describe('#.oidNum', function() {
it('is a function', function () {
expect(util.oidNum).to.be.a('function');
});
describe('#.oidNum', () => {
it('is a function', () => {
expect(util.oidNum).to.be.a('function')
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.oidNum(); }).to.throw(TypeError);
expect(function () { return util.oidNum(undefined); }).to.throw(TypeError);
expect(function () { return util.oidNum(null); }).to.throw(TypeError);
expect(function () { return util.oidNum(NaN); }).to.throw(TypeError);
expect(function () { return util.oidNum([]); }).to.throw(TypeError);
expect(function () { return util.oidNum({}); }).to.throw(TypeError);
expect(function () { return util.oidNum(true); }).to.throw(TypeError);
expect(function () { return util.oidNum(new Date()); }).to.throw(TypeError);
expect(function () { return util.oidNum(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.oidNum()).to.throw(TypeError)
expect(() => util.oidNum(undefined)).to.throw(TypeError)
expect(() => util.oidNum(null)).to.throw(TypeError)
expect(() => util.oidNum(NaN)).to.throw(TypeError)
expect(() => util.oidNum([])).to.throw(TypeError)
expect(() => util.oidNum({})).to.throw(TypeError)
expect(() => util.oidNum(true)).to.throw(TypeError)
expect(() => util.oidNum(new Date())).to.throw(TypeError)
expect(() => util.oidNum(() => {})).to.throw(TypeError)
expect(function () { return util.oidNum(3); }).not.to.throw(Error);
expect(function () { return util.oidNum('3'); }).not.to.throw(Error);
expect(function () { return util.oidNum('xx'); }).not.to.throw(Error);
});
});
expect(() => util.oidNum(3)).not.to.throw(Error)
expect(() => util.oidNum('3')).not.to.throw(Error)
expect(() => util.oidNum('xx')).not.to.throw(Error)
})
})
describe('#.getRid', function() {
it('is a function', function () {
expect(util.getRid).to.be.a('function');
});
describe('#.getRid', () => {
it('is a function', () => {
expect(util.getRid).to.be.a('function')
})
it('should throw TypeError if input rid is not a number and not a string', function () {
expect(function () { return util.getRid(); }).to.throw(TypeError);
expect(function () { return util.getRid(undefined); }).to.throw(TypeError);
expect(function () { return util.getRid(null); }).to.throw(TypeError);
expect(function () { return util.getRid(NaN); }).to.throw(TypeError);
expect(function () { return util.getRid([]); }).to.throw(TypeError);
expect(function () { return util.getRid({}); }).to.throw(TypeError);
expect(function () { return util.getRid(true); }).to.throw(TypeError);
expect(function () { return util.getRid(new Date()); }).to.throw(TypeError);
expect(function () { return util.getRid(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input rid is not a number and not a string', () => {
expect(() => util.getRid()).to.throw(TypeError)
expect(() => util.getRid(undefined)).to.throw(TypeError)
expect(() => util.getRid(null)).to.throw(TypeError)
expect(() => util.getRid(NaN)).to.throw(TypeError)
expect(() => util.getRid([])).to.throw(TypeError)
expect(() => util.getRid({})).to.throw(TypeError)
expect(() => util.getRid(true)).to.throw(TypeError)
expect(() => util.getRid(new Date())).to.throw(TypeError)
expect(() => util.getRid(() => {})).to.throw(TypeError)
expect(function () { return util.getRid(3); }).not.to.throw(Error);
expect(function () { return util.getRid('3'); }).not.to.throw(Error);
expect(function () { return util.getRid('xx'); }).not.to.throw(Error);
});
expect(() => util.getRid(3)).not.to.throw(Error)
expect(() => util.getRid('3')).not.to.throw(Error)
expect(() => util.getRid('xx')).not.to.throw(Error)
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.getRid(undefined, 3); }).to.throw(TypeError);
expect(function () { return util.getRid(null, 3); }).to.throw(TypeError);
expect(function () { return util.getRid(NaN, 3); }).to.throw(TypeError);
expect(function () { return util.getRid([], 3); }).to.throw(TypeError);
expect(function () { return util.getRid({}, 3); }).to.throw(TypeError);
expect(function () { return util.getRid(true, 3); }).to.throw(TypeError);
expect(function () { return util.getRid(new Date(), 3); }).to.throw(TypeError);
expect(function () { return util.getRid(function () {}, 3); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.getRid(undefined, 3)).to.throw(TypeError)
expect(() => util.getRid(null, 3)).to.throw(TypeError)
expect(() => util.getRid(NaN, 3)).to.throw(TypeError)
expect(() => util.getRid([], 3)).to.throw(TypeError)
expect(() => util.getRid({}, 3)).to.throw(TypeError)
expect(() => util.getRid(true, 3)).to.throw(TypeError)
expect(() => util.getRid(new Date(), 3)).to.throw(TypeError)
expect(() => util.getRid(() => {}, 3)).to.throw(TypeError)
expect(function () { return util.getRid(3, 3); }).not.to.throw(Error);
expect(function () { return util.getRid('3', 3); }).not.to.throw(Error);
expect(function () { return util.getRid('xx', 3); }).not.to.throw(Error);
});
expect(() => util.getRid(3, 3)).not.to.throw(Error)
expect(() => util.getRid('3', 3)).not.to.throw(Error)
expect(() => util.getRid('xx', 3)).not.to.throw(Error)
})
it('should throw TypeError if input oid is valid but rid is not a number and not a string', function () {
expect(function () { return util.getRid(3, null); }).to.throw(TypeError);
expect(function () { return util.getRid(3, NaN); }).to.throw(TypeError);
expect(function () { return util.getRid(3, []); }).to.throw(TypeError);
expect(function () { return util.getRid(3, {}); }).to.throw(TypeError);
expect(function () { return util.getRid(3, true); }).to.throw(TypeError);
expect(function () { return util.getRid(3, new Date()); }).to.throw(TypeError);
expect(function () { return util.getRid(3, function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is valid but rid is not a number and not a string', () => {
expect(() => util.getRid(3, null)).to.throw(TypeError)
expect(() => util.getRid(3, NaN)).to.throw(TypeError)
expect(() => util.getRid(3, [])).to.throw(TypeError)
expect(() => util.getRid(3, {})).to.throw(TypeError)
expect(() => util.getRid(3, true)).to.throw(TypeError)
expect(() => util.getRid(3, new Date())).to.throw(TypeError)
expect(() => util.getRid(3, () => {})).to.throw(TypeError)
expect(function () { return util.getRid(3, 3); }).not.to.throw(Error);
expect(function () { return util.getRid(3, '3'); }).not.to.throw(Error);
expect(function () { return util.getRid(3, 'xx'); }).not.to.throw(Error);
});
});
expect(() => util.getRid(3, 3)).not.to.throw(Error)
expect(() => util.getRid(3, '3')).not.to.throw(Error)
expect(() => util.getRid(3, 'xx')).not.to.throw(Error)
})
})
describe('#.ridKey', function() {
it('is a function', function () {
expect(util.ridKey).to.be.a('function');
});
describe('#.ridKey', () => {
it('is a function', () => {
expect(util.ridKey).to.be.a('function')
})
it('should throw TypeError if input rid is not a number and not a string', function () {
expect(function () { return util.ridKey(); }).to.throw(TypeError);
expect(function () { return util.ridKey(undefined); }).to.throw(TypeError);
expect(function () { return util.ridKey(null); }).to.throw(TypeError);
expect(function () { return util.ridKey(NaN); }).to.throw(TypeError);
expect(function () { return util.ridKey([]); }).to.throw(TypeError);
expect(function () { return util.ridKey({}); }).to.throw(TypeError);
expect(function () { return util.ridKey(true); }).to.throw(TypeError);
expect(function () { return util.ridKey(new Date()); }).to.throw(TypeError);
expect(function () { return util.ridKey(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input rid is not a number and not a string', () => {
expect(() => util.ridKey()).to.throw(TypeError)
expect(() => util.ridKey(undefined)).to.throw(TypeError)
expect(() => util.ridKey(null)).to.throw(TypeError)
expect(() => util.ridKey(NaN)).to.throw(TypeError)
expect(() => util.ridKey([])).to.throw(TypeError)
expect(() => util.ridKey({})).to.throw(TypeError)
expect(() => util.ridKey(true)).to.throw(TypeError)
expect(() => util.ridKey(new Date())).to.throw(TypeError)
expect(() => util.ridKey(() => {})).to.throw(TypeError)
expect(function () { return util.ridKey(3); }).not.to.throw(Error);
expect(function () { return util.ridKey('3'); }).not.to.throw(Error);
expect(function () { return util.ridKey('xx'); }).not.to.throw(Error);
});
expect(() => util.ridKey(3)).not.to.throw(Error)
expect(() => util.ridKey('3')).not.to.throw(Error)
expect(() => util.ridKey('xx')).not.to.throw(Error)
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.ridKey(undefined, 3); }).to.throw(TypeError);
expect(function () { return util.ridKey(null, 3); }).to.throw(TypeError);
expect(function () { return util.ridKey(NaN, 3); }).to.throw(TypeError);
expect(function () { return util.ridKey([], 3); }).to.throw(TypeError);
expect(function () { return util.ridKey({}, 3); }).to.throw(TypeError);
expect(function () { return util.ridKey(true, 3); }).to.throw(TypeError);
expect(function () { return util.ridKey(new Date(), 3); }).to.throw(TypeError);
expect(function () { return util.ridKey(function () {}, 3); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.ridKey(undefined, 3)).to.throw(TypeError)
expect(() => util.ridKey(null, 3)).to.throw(TypeError)
expect(() => util.ridKey(NaN, 3)).to.throw(TypeError)
expect(() => util.ridKey([], 3)).to.throw(TypeError)
expect(() => util.ridKey({}, 3)).to.throw(TypeError)
expect(() => util.ridKey(true, 3)).to.throw(TypeError)
expect(() => util.ridKey(new Date(), 3)).to.throw(TypeError)
expect(() => util.ridKey(() => {}, 3)).to.throw(TypeError)
expect(function () { return util.ridKey(3, 3); }).not.to.throw(Error);
expect(function () { return util.ridKey('3', 3); }).not.to.throw(Error);
expect(function () { return util.ridKey('xx', 3); }).not.to.throw(Error);
});
expect(() => util.ridKey(3, 3)).not.to.throw(Error)
expect(() => util.ridKey('3', 3)).not.to.throw(Error)
expect(() => util.ridKey('xx', 3)).not.to.throw(Error)
})
it('should throw TypeError if input oid is valid but rid is not a number and not a string', function () {
expect(function () { return util.ridKey(3, null); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, NaN); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, []); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, {}); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, true); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, new Date()); }).to.throw(TypeError);
expect(function () { return util.ridKey(3, function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is valid but rid is not a number and not a string', () => {
expect(() => util.ridKey(3, null)).to.throw(TypeError)
expect(() => util.ridKey(3, NaN)).to.throw(TypeError)
expect(() => util.ridKey(3, [])).to.throw(TypeError)
expect(() => util.ridKey(3, {})).to.throw(TypeError)
expect(() => util.ridKey(3, true)).to.throw(TypeError)
expect(() => util.ridKey(3, new Date())).to.throw(TypeError)
expect(() => util.ridKey(3, () => {})).to.throw(TypeError)
expect(function () { return util.ridKey(3, 3); }).not.to.throw(Error);
expect(function () { return util.ridKey(3, '3'); }).not.to.throw(Error);
expect(function () { return util.ridKey(3, 'xx'); }).not.to.throw(Error);
});
});
expect(() => util.ridKey(3, 3)).not.to.throw(Error)
expect(() => util.ridKey(3, '3')).not.to.throw(Error)
expect(() => util.ridKey(3, 'xx')).not.to.throw(Error)
})
})
describe('#.ridNum', function() {
it('is a function', function () {
expect(util.ridNum).to.be.a('function');
});
describe('#.ridNum', () => {
it('is a function', () => {
expect(util.ridNum).to.be.a('function')
})
it('should throw TypeError if input rid is not a number and not a string', function () {
expect(function () { return util.ridNum(); }).to.throw(TypeError);
expect(function () { return util.ridNum(undefined); }).to.throw(TypeError);
expect(function () { return util.ridNum(null); }).to.throw(TypeError);
expect(function () { return util.ridNum(NaN); }).to.throw(TypeError);
expect(function () { return util.ridNum([]); }).to.throw(TypeError);
expect(function () { return util.ridNum({}); }).to.throw(TypeError);
expect(function () { return util.ridNum(true); }).to.throw(TypeError);
expect(function () { return util.ridNum(new Date()); }).to.throw(TypeError);
expect(function () { return util.ridNum(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input rid is not a number and not a string', () => {
expect(() => util.ridNum()).to.throw(TypeError)
expect(() => util.ridNum(undefined)).to.throw(TypeError)
expect(() => util.ridNum(null)).to.throw(TypeError)
expect(() => util.ridNum(NaN)).to.throw(TypeError)
expect(() => util.ridNum([])).to.throw(TypeError)
expect(() => util.ridNum({})).to.throw(TypeError)
expect(() => util.ridNum(true)).to.throw(TypeError)
expect(() => util.ridNum(new Date())).to.throw(TypeError)
expect(() => util.ridNum(() => {})).to.throw(TypeError)
expect(function () { return util.ridNum(3); }).not.to.throw(Error);
expect(function () { return util.ridNum('3'); }).not.to.throw(Error);
expect(function () { return util.ridNum('xx'); }).not.to.throw(Error);
});
expect(() => util.ridNum(3)).not.to.throw(Error)
expect(() => util.ridNum('3')).not.to.throw(Error)
expect(() => util.ridNum('xx')).not.to.throw(Error)
})
it('should throw TypeError if input oid is not a number and not a string', function () {
expect(function () { return util.ridNum(undefined, 3); }).to.throw(TypeError);
expect(function () { return util.ridNum(null, 3); }).to.throw(TypeError);
expect(function () { return util.ridNum(NaN, 3); }).to.throw(TypeError);
expect(function () { return util.ridNum([], 3); }).to.throw(TypeError);
expect(function () { return util.ridNum({}, 3); }).to.throw(TypeError);
expect(function () { return util.ridNum(true, 3); }).to.throw(TypeError);
expect(function () { return util.ridNum(new Date(), 3); }).to.throw(TypeError);
expect(function () { return util.ridNum(function () {}, 3); }).to.throw(TypeError);
it('should throw TypeError if input oid is not a number and not a string', () => {
expect(() => util.ridNum(undefined, 3)).to.throw(TypeError)
expect(() => util.ridNum(null, 3)).to.throw(TypeError)
expect(() => util.ridNum(NaN, 3)).to.throw(TypeError)
expect(() => util.ridNum([], 3)).to.throw(TypeError)
expect(() => util.ridNum({}, 3)).to.throw(TypeError)
expect(() => util.ridNum(true, 3)).to.throw(TypeError)
expect(() => util.ridNum(new Date(), 3)).to.throw(TypeError)
expect(() => util.ridNum(() => {}, 3)).to.throw(TypeError)
expect(function () { return util.ridNum(3, 3); }).not.to.throw(Error);
expect(function () { return util.ridNum('3', 3); }).not.to.throw(Error);
expect(function () { return util.ridNum('xx', 3); }).not.to.throw(Error);
});
expect(() => util.ridNum(3, 3)).not.to.throw(Error)
expect(() => util.ridNum('3', 3)).not.to.throw(Error)
expect(() => util.ridNum('xx', 3)).not.to.throw(Error)
})
it('should throw TypeError if input oid is valid but rid is not a number and not a string', function () {
expect(function () { return util.ridNum(3, null); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, NaN); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, []); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, {}); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, true); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, new Date()); }).to.throw(TypeError);
expect(function () { return util.ridNum(3, function () {}); }).to.throw(TypeError);
it('should throw TypeError if input oid is valid but rid is not a number and not a string', () => {
expect(() => util.ridNum(3, null)).to.throw(TypeError)
expect(() => util.ridNum(3, NaN)).to.throw(TypeError)
expect(() => util.ridNum(3, [])).to.throw(TypeError)
expect(() => util.ridNum(3, {})).to.throw(TypeError)
expect(() => util.ridNum(3, true)).to.throw(TypeError)
expect(() => util.ridNum(3, new Date())).to.throw(TypeError)
expect(() => util.ridNum(3, () => {})).to.throw(TypeError)
expect(function () { return util.ridNum(3, 3); }).not.to.throw(Error);
expect(function () { return util.ridNum(3, '3'); }).not.to.throw(Error);
expect(function () { return util.ridNum(3, 'xx'); }).not.to.throw(Error);
});
});
expect(() => util.ridNum(3, 3)).not.to.throw(Error)
expect(() => util.ridNum(3, '3')).not.to.throw(Error)
expect(() => util.ridNum(3, 'xx')).not.to.throw(Error)
})
})
describe('#.getRspCode', function() {
it('is a function', function () {
expect(util.getRspCode).to.be.a('function');
});
describe('#.getRspCode', () => {
it('is a function', () => {
expect(util.getRspCode).to.be.a('function')
})
it('should throw TypeError if input code is not a number and not a string', function () {
expect(function () { return util.getRspCode(); }).to.throw(TypeError);
expect(function () { return util.getRspCode(undefined); }).to.throw(TypeError);
expect(function () { return util.getRspCode(null); }).to.throw(TypeError);
expect(function () { return util.getRspCode(NaN); }).to.throw(TypeError);
expect(function () { return util.getRspCode([]); }).to.throw(TypeError);
expect(function () { return util.getRspCode({}); }).to.throw(TypeError);
expect(function () { return util.getRspCode(true); }).to.throw(TypeError);
expect(function () { return util.getRspCode(new Date()); }).to.throw(TypeError);
expect(function () { return util.getRspCode(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input code is not a number and not a string', () => {
expect(() => util.getRspCode()).to.throw(TypeError)
expect(() => util.getRspCode(undefined)).to.throw(TypeError)
expect(() => util.getRspCode(null)).to.throw(TypeError)
expect(() => util.getRspCode(NaN)).to.throw(TypeError)
expect(() => util.getRspCode([])).to.throw(TypeError)
expect(() => util.getRspCode({})).to.throw(TypeError)
expect(() => util.getRspCode(true)).to.throw(TypeError)
expect(() => util.getRspCode(new Date())).to.throw(TypeError)
expect(() => util.getRspCode(() => {})).to.throw(TypeError)
expect(function () { return util.getRspCode(3); }).not.to.throw(Error);
expect(function () { return util.getRspCode('3'); }).not.to.throw(Error);
expect(function () { return util.getRspCode('xx'); }).not.to.throw(Error);
});
});
expect(() => util.getRspCode(3)).not.to.throw(Error)
expect(() => util.getRspCode('3')).not.to.throw(Error)
expect(() => util.getRspCode('xx')).not.to.throw(Error)
})
})
describe('#.rspCodeKey', function() {
it('is a function', function () {
expect(util.rspCodeKey).to.be.a('function');
});
describe('#.rspCodeKey', () => {
it('is a function', () => {
expect(util.rspCodeKey).to.be.a('function')
})
it('should throw TypeError if input code is not a number and not a string', function () {
expect(function () { return util.rspCodeKey(); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(undefined); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(null); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(NaN); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey([]); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey({}); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(true); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(new Date()); }).to.throw(TypeError);
expect(function () { return util.rspCodeKey(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input code is not a number and not a string', () => {
expect(() => util.rspCodeKey()).to.throw(TypeError)
expect(() => util.rspCodeKey(undefined)).to.throw(TypeError)
expect(() => util.rspCodeKey(null)).to.throw(TypeError)
expect(() => util.rspCodeKey(NaN)).to.throw(TypeError)
expect(() => util.rspCodeKey([])).to.throw(TypeError)
expect(() => util.rspCodeKey({})).to.throw(TypeError)
expect(() => util.rspCodeKey(true)).to.throw(TypeError)
expect(() => util.rspCodeKey(new Date())).to.throw(TypeError)
expect(() => util.rspCodeKey(() => {})).to.throw(TypeError)
expect(function () { return util.rspCodeKey(3); }).not.to.throw(Error);
expect(function () { return util.rspCodeKey('3'); }).not.to.throw(Error);
expect(function () { return util.rspCodeKey('xx'); }).not.to.throw(Error);
});
});
expect(() => util.rspCodeKey(3)).not.to.throw(Error)
expect(() => util.rspCodeKey('3')).not.to.throw(Error)
expect(() => util.rspCodeKey('xx')).not.to.throw(Error)
})
})
describe('#.rspCodeNum', function() {
it('is a function', function () {
expect(util.rspCodeNum).to.be.a('function');
});
describe('#.rspCodeNum', () => {
it('is a function', () => {
expect(util.rspCodeNum).to.be.a('function')
})
it('should throw TypeError if input code is not a number and not a string', function () {
expect(function () { return util.rspCodeNum(); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(undefined); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(null); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(NaN); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum([]); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum({}); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(true); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(new Date()); }).to.throw(TypeError);
expect(function () { return util.rspCodeNum(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input code is not a number and not a string', () => {
expect(() => util.rspCodeNum()).to.throw(TypeError)
expect(() => util.rspCodeNum(undefined)).to.throw(TypeError)
expect(() => util.rspCodeNum(null)).to.throw(TypeError)
expect(() => util.rspCodeNum(NaN)).to.throw(TypeError)
expect(() => util.rspCodeNum([])).to.throw(TypeError)
expect(() => util.rspCodeNum({})).to.throw(TypeError)
expect(() => util.rspCodeNum(true)).to.throw(TypeError)
expect(() => util.rspCodeNum(new Date())).to.throw(TypeError)
expect(() => util.rspCodeNum(() => {})).to.throw(TypeError)
expect(function () { return util.rspCodeNum(3); }).not.to.throw(Error);
expect(function () { return util.rspCodeNum('3'); }).not.to.throw(Error);
expect(function () { return util.rspCodeNum('xx'); }).not.to.throw(Error);
});
});
expect(() => util.rspCodeNum(3)).not.to.throw(Error)
expect(() => util.rspCodeNum('3')).not.to.throw(Error)
expect(() => util.rspCodeNum('xx')).not.to.throw(Error)
})
})
describe('#.getCmd', function() {
it('is a function', function () {
expect(util.getCmd).to.be.a('function');
});
describe('#.getCmd', () => {
it('is a function', () => {
expect(util.getCmd).to.be.a('function')
})
it('should throw TypeError if input cmd is not a number and not a string', function () {
expect(function () { return util.getCmd(); }).to.throw(TypeError);
expect(function () { return util.getCmd(undefined); }).to.throw(TypeError);
expect(function () { return util.getCmd(null); }).to.throw(TypeError);
expect(function () { return util.getCmd(NaN); }).to.throw(TypeError);
expect(function () { return util.getCmd([]); }).to.throw(TypeError);
expect(function () { return util.getCmd({}); }).to.throw(TypeError);
expect(function () { return util.getCmd(true); }).to.throw(TypeError);
expect(function () { return util.getCmd(new Date()); }).to.throw(TypeError);
expect(function () { return util.getCmd(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input cmd is not a number and not a string', () => {
expect(() => util.getCmd()).to.throw(TypeError)
expect(() => util.getCmd(undefined)).to.throw(TypeError)
expect(() => util.getCmd(null)).to.throw(TypeError)
expect(() => util.getCmd(NaN)).to.throw(TypeError)
expect(() => util.getCmd([])).to.throw(TypeError)
expect(() => util.getCmd({})).to.throw(TypeError)
expect(() => util.getCmd(true)).to.throw(TypeError)
expect(() => util.getCmd(new Date())).to.throw(TypeError)
expect(() => util.getCmd(() => {})).to.throw(TypeError)
expect(function () { return util.getCmd(3); }).not.to.throw(Error);
expect(function () { return util.getCmd('3'); }).not.to.throw(Error);
expect(function () { return util.getCmd('xx'); }).not.to.throw(Error);
});
});
expect(() => util.getCmd(3)).not.to.throw(Error)
expect(() => util.getCmd('3')).not.to.throw(Error)
expect(() => util.getCmd('xx')).not.to.throw(Error)
})
})
describe('#.cmdKey', function() {
it('is a function', function () {
expect(util.cmdKey).to.be.a('function');
});
describe('#.cmdKey', () => {
it('is a function', () => {
expect(util.cmdKey).to.be.a('function')
})
it('should throw TypeError if input cmd is not a number and not a string', function () {
expect(function () { return util.cmdKey(); }).to.throw(TypeError);
expect(function () { return util.cmdKey(undefined); }).to.throw(TypeError);
expect(function () { return util.cmdKey(null); }).to.throw(TypeError);
expect(function () { return util.cmdKey(NaN); }).to.throw(TypeError);
expect(function () { return util.cmdKey([]); }).to.throw(TypeError);
expect(function () { return util.cmdKey({}); }).to.throw(TypeError);
expect(function () { return util.cmdKey(true); }).to.throw(TypeError);
expect(function () { return util.cmdKey(new Date()); }).to.throw(TypeError);
expect(function () { return util.cmdKey(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input cmd is not a number and not a string', () => {
expect(() => util.cmdKey()).to.throw(TypeError)
expect(() => util.cmdKey(undefined)).to.throw(TypeError)
expect(() => util.cmdKey(null)).to.throw(TypeError)
expect(() => util.cmdKey(NaN)).to.throw(TypeError)
expect(() => util.cmdKey([])).to.throw(TypeError)
expect(() => util.cmdKey({})).to.throw(TypeError)
expect(() => util.cmdKey(true)).to.throw(TypeError)
expect(() => util.cmdKey(new Date())).to.throw(TypeError)
expect(() => util.cmdKey(() => {})).to.throw(TypeError)
expect(function () { return util.cmdKey(3); }).not.to.throw(Error);
expect(function () { return util.cmdKey('3'); }).not.to.throw(Error);
expect(function () { return util.cmdKey('xx'); }).not.to.throw(Error);
});
});
expect(() => util.cmdKey(3)).not.to.throw(Error)
expect(() => util.cmdKey('3')).not.to.throw(Error)
expect(() => util.cmdKey('xx')).not.to.throw(Error)
})
})
describe('#.cmdNum', function() {
it('is a function', function () {
expect(util.cmdNum).to.be.a('function');
});
describe('#.cmdNum', () => {
it('is a function', () => {
expect(util.cmdNum).to.be.a('function')
})
it('should throw TypeError if input cmd is not a number and not a string', function () {
expect(function () { return util.cmdNum(); }).to.throw(TypeError);
expect(function () { return util.cmdNum(undefined); }).to.throw(TypeError);
expect(function () { return util.cmdNum(null); }).to.throw(TypeError);
expect(function () { return util.cmdNum(NaN); }).to.throw(TypeError);
expect(function () { return util.cmdNum([]); }).to.throw(TypeError);
expect(function () { return util.cmdNum({}); }).to.throw(TypeError);
expect(function () { return util.cmdNum(true); }).to.throw(TypeError);
expect(function () { return util.cmdNum(new Date()); }).to.throw(TypeError);
expect(function () { return util.cmdNum(function () {}); }).to.throw(TypeError);
it('should throw TypeError if input cmd is not a number and not a string', () => {
expect(() => util.cmdNum()).to.throw(TypeError)
expect(() => util.cmdNum(undefined)).to.throw(TypeError)
expect(() => util.cmdNum(null)).to.throw(TypeError)
expect(() => util.cmdNum(NaN)).to.throw(TypeError)
expect(() => util.cmdNum([])).to.throw(TypeError)
expect(() => util.cmdNum({})).to.throw(TypeError)
expect(() => util.cmdNum(true)).to.throw(TypeError)
expect(() => util.cmdNum(new Date())).to.throw(TypeError)
expect(() => util.cmdNum(() => {})).to.throw(TypeError)
expect(function () { return util.cmdNum(3); }).not.to.throw(Error);
expect(function () { return util.cmdNum('3'); }).not.to.throw(Error);
expect(function () { return util.cmdNum('xx'); }).not.to.throw(Error);
});
});
expect(() => util.cmdNum(3)).not.to.throw(Error)
expect(() => util.cmdNum('3')).not.to.throw(Error)
expect(() => util.cmdNum('xx')).not.to.throw(Error)
})
})
describe('#.createPath', function() {
it('is a function', function () {
expect(util.createPath).to.be.a('function');
});
describe('#.createPath', () => {
it('is a function', () => {
expect(util.createPath).to.be.a('function')
})
it('should throw TypeError if any of the input is not a number and not a string', function () {
expect(function () { return util.createPath(); }).to.throw(TypeError);
expect(function () { return util.createPath(undefined); }).to.throw(TypeError);
expect(function () { return util.createPath(null); }).to.throw(TypeError);
expect(function () { return util.createPath(NaN); }).to.throw(TypeError);
expect(function () { return util.createPath([]); }).to.throw(TypeError);
expect(function () { return util.createPath({}); }).to.throw(TypeError);
expect(function () { return util.createPath(true); }).to.throw(TypeError);
expect(function () { return util.createPath(new Date()); }).to.throw(TypeError);
expect(function () { return util.createPath(function () {}); }).to.throw(TypeError);
it('should throw TypeError if any of the input is not a number and not a string', () => {
expect(() => util.createPath()).to.throw(TypeError)
expect(() => util.createPath(undefined)).to.throw(TypeError)
expect(() => util.createPath(null)).to.throw(TypeError)
expect(() => util.createPath(NaN)).to.throw(TypeError)
expect(() => util.createPath([])).to.throw(TypeError)
expect(() => util.createPath({})).to.throw(TypeError)
expect(() => util.createPath(true)).to.throw(TypeError)
expect(() => util.createPath(new Date())).to.throw(TypeError)
expect(() => util.createPath(() => {})).to.throw(TypeError)
expect(function () { return util.createPath(2, undefined); }).to.throw(TypeError);
expect(function () { return util.createPath(2, null); }).to.throw(TypeError);
expect(function () { return util.createPath(2, NaN); }).to.throw(TypeError);
expect(function () { return util.createPath(2, []); }).to.throw(TypeError);
expect(function () { return util.createPath(2, {}); }).to.throw(TypeError);
expect(function () { return util.createPath(2, true); }).to.throw(TypeError);
expect(function () { return util.createPath(2, new Date()); }).to.throw(TypeError);
expect(function () { return util.createPath(2, function () {}); }).to.throw(TypeError);
expect(() => util.createPath(2, undefined)).to.throw(TypeError)
expect(() => util.createPath(2, null)).to.throw(TypeError)
expect(() => util.createPath(2, NaN)).to.throw(TypeError)
expect(() => util.createPath(2, [])).to.throw(TypeError)
expect(() => util.createPath(2, {})).to.throw(TypeError)
expect(() => util.createPath(2, true)).to.throw(TypeError)
expect(() => util.createPath(2, new Date())).to.throw(TypeError)
expect(() => util.createPath(2, () => {})).to.throw(TypeError)
expect(function () { return util.createPath('2', undefined); }).to.throw(TypeError);
expect(function () { return util.createPath('2', null); }).to.throw(TypeError);
expect(function () { return util.createPath('2', NaN); }).to.throw(TypeError);
expect(function () { return util.createPath('2', []); }).to.throw(TypeError);
expect(function () { return util.createPath('2', {}); }).to.throw(TypeError);
expect(function () { return util.createPath('2', true); }).to.throw(TypeError);
expect(function () { return util.createPath('2', new Date()); }).to.throw(TypeError);
expect(function () { return util.createPath('2', function () {}); }).to.throw(TypeError);
expect(() => util.createPath('2', undefined)).to.throw(TypeError)
expect(() => util.createPath('2', null)).to.throw(TypeError)
expect(() => util.createPath('2', NaN)).to.throw(TypeError)
expect(() => util.createPath('2', [])).to.throw(TypeError)
expect(() => util.createPath('2', {})).to.throw(TypeError)
expect(() => util.createPath('2', true)).to.throw(TypeError)
expect(() => util.createPath('2', new Date())).to.throw(TypeError)
expect(() => util.createPath('2', () => {})).to.throw(TypeError)
expect(function () { return util.createPath('.', 2, undefined); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, null); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, NaN); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, []); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, {}); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, true); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, new Date()); }).to.throw(TypeError);
expect(function () { return util.createPath('.', 2, function () {}); }).to.throw(TypeError);
expect(() => util.createPath('.', 2, undefined)).to.throw(TypeError)
expect(() => util.createPath('.', 2, null)).to.throw(TypeError)
expect(() => util.createPath('.', 2, NaN)).to.throw(TypeError)
expect(() => util.createPath('.', 2, [])).to.throw(TypeError)
expect(() => util.createPath('.', 2, {})).to.throw(TypeError)
expect(() => util.createPath('.', 2, true)).to.throw(TypeError)
expect(() => util.createPath('.', 2, new Date())).to.throw(TypeError)
expect(() => util.createPath('.', 2, () => {})).to.throw(TypeError)
expect(function () { return util.createPath(3, 3, 3); }).not.to.throw(Error);
expect(function () { return util.createPath('3', '3', 1); }).not.to.throw(Error);
expect(function () { return util.createPath('.', 'xx', 1, 100, 'hello'); }).not.to.throw(Error);
});
expect(() => util.createPath(3, 3, 3)).not.to.throw(Error)
expect(() => util.createPath('3', '3', 1)).not.to.throw(Error)
expect(() => util.createPath('.', 'xx', 1, 100, 'hello')).not.to.throw(Error)
})
})
});
describe('#.slashPath', () => {
it('is a function', () => {
expect(util.slashPath).to.be.a('function')
})
describe('#.slashPath', function() {
it('is a function', function () {
expect(util.slashPath).to.be.a('function');
});
it('should throw TypeError if input path is not a string', () => {
expect(() => util.slashPath()).to.throw(TypeError)
expect(() => util.slashPath(undefined)).to.throw(TypeError)
expect(() => util.slashPath(null)).to.throw(TypeError)
expect(() => util.slashPath(NaN)).to.throw(TypeError)
expect(() => util.slashPath([])).to.throw(TypeError)
expect(() => util.slashPath({})).to.throw(TypeError)
expect(() => util.slashPath(true)).to.throw(TypeError)
expect(() => util.slashPath(new Date())).to.throw(TypeError)
expect(() => util.slashPath(() => {})).to.throw(TypeError)
expect(() => util.slashPath(3)).to.throw(Error)
it('should throw TypeError if input path is not a string', function () {
expect(function () { return util.slashPath(); }).to.throw(TypeError);
expect(function () { return util.slashPath(undefined); }).to.throw(TypeError);
expect(function () { return util.slashPath(null); }).to.throw(TypeError);
expect(function () { return util.slashPath(NaN); }).to.throw(TypeError);
expect(function () { return util.slashPath([]); }).to.throw(TypeError);
expect(function () { return util.slashPath({}); }).to.throw(TypeError);
expect(function () { return util.slashPath(true); }).to.throw(TypeError);
expect(function () { return util.slashPath(new Date()); }).to.throw(TypeError);
expect(function () { return util.slashPath(function () {}); }).to.throw(TypeError);
expect(function () { return util.slashPath(3); }).to.throw(Error);
expect(() => util.slashPath('3')).not.to.throw(Error)
expect(() => util.slashPath('xx')).not.to.throw(Error)
expect(() => util.slashPath('xx.y.z.g.h.j')).not.to.throw(Error)
})
})
expect(function () { return util.slashPath('3'); }).not.to.throw(Error);
expect(function () { return util.slashPath('xx'); }).not.to.throw(Error);
expect(function () { return util.slashPath('xx.y.z.g.h.j'); }).not.to.throw(Error);
});
});
describe('#.dotPath', () => {
it('is a function', () => {
expect(util.dotPath).to.be.a('function')
})
describe('#.dotPath', function() {
it('is a function', function () {
expect(util.dotPath).to.be.a('function');
});
it('should throw TypeError if input path is not a string', () => {
expect(() => util.dotPath()).to.throw(TypeError)
expect(() => util.dotPath(undefined)).to.throw(TypeError)
expect(() => util.dotPath(null)).to.throw(TypeError)
expect(() => util.dotPath(NaN)).to.throw(TypeError)
expect(() => util.dotPath([])).to.throw(TypeError)
expect(() => util.dotPath({})).to.throw(TypeError)
expect(() => util.dotPath(true)).to.throw(TypeError)
expect(() => util.dotPath(new Date())).to.throw(TypeError)
expect(() => util.dotPath(() => {})).to.throw(TypeError)
expect(() => util.dotPath(3)).to.throw(Error)
it('should throw TypeError if input path is not a string', function () {
expect(function () { return util.dotPath(); }).to.throw(TypeError);
expect(function () { return util.dotPath(undefined); }).to.throw(TypeError);
expect(function () { return util.dotPath(null); }).to.throw(TypeError);
expect(function () { return util.dotPath(NaN); }).to.throw(TypeError);
expect(function () { return util.dotPath([]); }).to.throw(TypeError);
expect(function () { return util.dotPath({}); }).to.throw(TypeError);
expect(function () { return util.dotPath(true); }).to.throw(TypeError);
expect(function () { return util.dotPath(new Date()); }).to.throw(TypeError);
expect(function () { return util.dotPath(function () {}); }).to.throw(TypeError);
expect(function () { return util.dotPath(3); }).to.throw(Error);
expect(() => util.dotPath('3')).not.to.throw(Error)
expect(() => util.dotPath('xx')).not.to.throw(Error)
expect(() => util.dotPath('xx.y.z.g.h.j')).not.to.throw(Error)
expect(() => util.dotPath('xx/y/z/g/h/j')).not.to.throw(Error)
})
})
expect(function () { return util.dotPath('3'); }).not.to.throw(Error);
expect(function () { return util.dotPath('xx'); }).not.to.throw(Error);
expect(function () { return util.dotPath('xx.y.z.g.h.j'); }).not.to.throw(Error);
expect(function () { return util.dotPath('xx/y/z/g/h/j'); }).not.to.throw(Error);
});
});
describe('#.pathItems', () => {
it('is a function', () => {
expect(util.pathItems).to.be.a('function')
})
describe('#.pathItems', function() {
it('is a function', function () {
expect(util.pathItems).to.be.a('function');
});
it('should throw TypeError if input path is not a string', () => {
expect(() => util.pathItems()).to.throw(TypeError)
expect(() => util.pathItems(undefined)).to.throw(TypeError)
expect(() => util.pathItems(null)).to.throw(TypeError)
expect(() => util.pathItems(NaN)).to.throw(TypeError)
expect(() => util.pathItems([])).to.throw(TypeError)
expect(() => util.pathItems({})).to.throw(TypeError)
expect(() => util.pathItems(true)).to.throw(TypeError)
expect(() => util.pathItems(new Date())).to.throw(TypeError)
expect(() => util.pathItems(() => {})).to.throw(TypeError)
expect(() => util.pathItems(3)).to.throw(Error)
it('should throw TypeError if input path is not a string', function () {
expect(function () { return util.pathItems(); }).to.throw(TypeError);
expect(function () { return util.pathItems(undefined); }).to.throw(TypeError);
expect(function () { return util.pathItems(null); }).to.throw(TypeError);
expect(function () { return util.pathItems(NaN); }).to.throw(TypeError);
expect(function () { return util.pathItems([]); }).to.throw(TypeError);
expect(function () { return util.pathItems({}); }).to.throw(TypeError);
expect(function () { return util.pathItems(true); }).to.throw(TypeError);
expect(function () { return util.pathItems(new Date()); }).to.throw(TypeError);
expect(function () { return util.pathItems(function () {}); }).to.throw(TypeError);
expect(function () { return util.pathItems(3); }).to.throw(Error);
expect(() => util.pathItems('3')).not.to.throw(Error)
expect(() => util.pathItems('xx')).not.to.throw(Error)
expect(() => util.pathItems('xx.y.z.g.h.j')).not.to.throw(Error)
expect(() => util.pathItems('xx/y/z/g/h/j')).not.to.throw(Error)
})
})
expect(function () { return util.pathItems('3'); }).not.to.throw(Error);
expect(function () { return util.pathItems('xx'); }).not.to.throw(Error);
expect(function () { return util.pathItems('xx.y.z.g.h.j'); }).not.to.throw(Error);
expect(function () { return util.pathItems('xx/y/z/g/h/j'); }).not.to.throw(Error);
});
});
describe('#.buildPathValuePairs', () => {
it('is a function', () => {
expect(util.buildPathValuePairs).to.be.a('function')
})
describe('#.buildPathValuePairs', function() {
it('is a function', function () {
expect(util.buildPathValuePairs).to.be.a('function');
});
it('should throw TypeError if input rootPath is not a string', () => {
expect(() => util.buildPathValuePairs()).to.throw(TypeError)
expect(() => util.buildPathValuePairs(undefined)).to.throw(TypeError)
expect(() => util.buildPathValuePairs(null)).to.throw(TypeError)
expect(() => util.buildPathValuePairs(NaN)).to.throw(TypeError)
expect(() => util.buildPathValuePairs([])).to.throw(TypeError)
expect(() => util.buildPathValuePairs({})).to.throw(TypeError)
expect(() => util.buildPathValuePairs(true)).to.throw(TypeError)
expect(() => util.buildPathValuePairs(new Date())).to.throw(TypeError)
expect(() => util.buildPathValuePairs(() => {})).to.throw(TypeError)
expect(() => util.buildPathValuePairs(3)).to.throw(Error)
it('should throw TypeError if input rootPath is not a string', function () {
expect(function () { return util.buildPathValuePairs(); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(undefined); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(null); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(NaN); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs([]); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs({}); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(true); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(new Date()); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(function () {}); }).to.throw(TypeError);
expect(function () { return util.buildPathValuePairs(3); }).to.throw(Error);
expect(() => util.buildPathValuePairs('3')).not.to.throw(Error)
expect(() => util.buildPathValuePairs('xx')).not.to.throw(Error)
expect(() => util.buildPathValuePairs('xx.y.z.g.h.j')).not.to.throw(Error)
expect(() => util.buildPathValuePairs('xx/y/z/g/h/j')).not.to.throw(Error)
})
})
expect(function () { return util.buildPathValuePairs('3'); }).not.to.throw(Error);
expect(function () { return util.buildPathValuePairs('xx'); }).not.to.throw(Error);
expect(function () { return util.buildPathValuePairs('xx.y.z.g.h.j'); }).not.to.throw(Error);
expect(function () { return util.buildPathValuePairs('xx/y/z/g/h/j'); }).not.to.throw(Error);
});
});
describe('#.isGoodResponse', () => {
it('is a function', () => {
expect(util.isGoodResponse).to.be.a('function')
})
describe('#.isGoodResponse', function() {
it('is a function', function () {
expect(util.isGoodResponse).to.be.a('function');
});
it('should throw TypeError if input status is not a number and not a string', () => {
expect(() => util.isGoodResponse()).to.throw(TypeError)
expect(() => util.isGoodResponse(undefined)).to.throw(TypeError)
expect(() => util.isGoodResponse(null)).to.throw(TypeError)
expect(() => util.isGoodResponse(NaN)).to.throw(TypeError)
expect(() => util.isGoodResponse([])).to.throw(TypeError)
expect(() => util.isGoodResponse({})).to.throw(TypeError)
expect(() => util.isGoodResponse(true)).to.throw(TypeError)
expect(() => util.isGoodResponse(new Date())).to.throw(TypeError)
expect(() => util.isGoodResponse(() => {})).to.throw(TypeError)
it('should throw TypeError if input status is not a number and not a string', function () {
expect(function () { return util.isGoodResponse(); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(undefined); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(null); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(NaN); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse([]); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse({}); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(true); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(new Date()); }).to.throw(TypeError);
expect(function () { return util.isGoodResponse(function () {}); }).to.throw(TypeError);
expect(() => util.isGoodResponse(3)).not.to.throw(Error)
expect(() => util.isGoodResponse('3')).not.to.throw(Error)
expect(() => util.isGoodResponse('xx')).not.to.throw(Error)
})
})
expect(function () { return util.isGoodResponse(3); }).not.to.throw(Error);
expect(function () { return util.isGoodResponse('3'); }).not.to.throw(Error);
expect(function () { return util.isGoodResponse('xx'); }).not.to.throw(Error);
});
});
describe('#.getAccessCtrl', () => {
it('is a function', () => {
expect(util.getAccessCtrl).to.be.a('function')
})
describe('#.getAccessCtrl', function() {
it('is a function', function () {
expect(util.getAccessCtrl).to.be.a('function');
});
it('should throw TypeError if input rid is not a number and not a string', () => {
expect(() => util.getAccessCtrl()).to.throw(TypeError)
expect(() => util.getAccessCtrl(undefined)).to.throw(TypeError)
expect(() => util.getAccessCtrl(null)).to.throw(TypeError)
expect(() => util.getAccessCtrl(NaN)).to.throw(TypeError)
expect(() => util.getAccessCtrl([])).to.throw(TypeError)
expect(() => util.getAccessCtrl({})).to.throw(TypeError)
expect(() => util.getAccessCtrl(true)).to.throw(TypeError)
expect(() => util.getAccessCtrl(new Date())).to.throw(TypeError)
expect(() => util.getAccessCtrl(() => {})).to.throw(TypeError)
it('should throw TypeError if input rid is not a number and not a string', function () {
expect(function () { return util.getAccessCtrl(); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(undefined); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(null); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(NaN); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl([]); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl({}); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(true); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(new Date()); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(function () {}); }).to.throw(TypeError);
expect(() => util.getAccessCtrl(3)).not.to.throw(Error)
expect(() => util.getAccessCtrl('3')).not.to.throw(Error)
expect(() => util.getAccessCtrl('xx')).not.to.throw(Error)
})
expect(function () { return util.getAccessCtrl(3); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl('3'); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl('xx'); }).not.to.throw(Error);
});
it('should throw TypeError if input rid is valid but oid is not a number and not a string', () => {
expect(() => util.getAccessCtrl(null, 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl(NaN, 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl([], 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl({}, 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl(true, 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl(new Date(), 3)).to.throw(TypeError)
expect(() => util.getAccessCtrl(() => {}, 3)).to.throw(TypeError)
it('should throw TypeError if input rid is valid but oid is not a number and not a string', function () {
expect(function () { return util.getAccessCtrl(null, 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(NaN, 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl([], 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl({}, 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(true, 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(new Date(), 3); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(function () {}, 3); }).to.throw(TypeError);
expect(() => util.getAccessCtrl(3, 3)).not.to.throw(Error)
expect(() => util.getAccessCtrl('3', 3)).not.to.throw(Error)
expect(() => util.getAccessCtrl('xx', 3)).not.to.throw(Error)
})
expect(function () { return util.getAccessCtrl(3, 3); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl('3', 3); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl('xx', 3); }).not.to.throw(Error);
});
it('should throw TypeError if input oid is valid but rid is not a number and not a string', () => {
expect(() => util.getAccessCtrl(3, null)).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, NaN)).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, [])).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, {})).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, true)).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, new Date())).to.throw(TypeError)
expect(() => util.getAccessCtrl(3, () => {})).to.throw(TypeError)
it('should throw TypeError if input oid is valid but rid is not a number and not a string', function () {
expect(function () { return util.getAccessCtrl(3, null); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, NaN); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, []); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, {}); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, true); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, new Date()); }).to.throw(TypeError);
expect(function () { return util.getAccessCtrl(3, function () {}); }).to.throw(TypeError);
expect(() => util.getAccessCtrl(3, 3)).not.to.throw(Error)
expect(() => util.getAccessCtrl(3, '3')).not.to.throw(Error)
expect(() => util.getAccessCtrl(3, 'xx')).not.to.throw(Error)
})
})
expect(function () { return util.getAccessCtrl(3, 3); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl(3, '3'); }).not.to.throw(Error);
expect(function () { return util.getAccessCtrl(3, 'xx'); }).not.to.throw(Error);
});
});
describe('#.jsonify', () => {
it('is a function', () => {
expect(util.jsonify).to.be.a('function')
})
describe('#.jsonify', function() {
it('is a function', function () {
expect(util.jsonify).to.be.a('function');
});
it('should throw TypeError if input str is not a string', () => {
expect(() => util.jsonify()).to.throw(TypeError)
expect(() => util.jsonify(undefined)).to.throw(TypeError)
expect(() => util.jsonify(null)).to.throw(TypeError)
expect(() => util.jsonify(NaN)).to.throw(TypeError)
expect(() => util.jsonify([])).to.throw(TypeError)
expect(() => util.jsonify({})).to.throw(TypeError)
expect(() => util.jsonify(true)).to.throw(TypeError)
expect(() => util.jsonify(new Date())).to.throw(TypeError)
expect(() => util.jsonify(() => {})).to.throw(TypeError)
expect(() => util.jsonify(3)).to.throw(Error)
it('should throw TypeError if input str is not a string', function () {
expect(function () { return util.jsonify(); }).to.throw(TypeError);
expect(function () { return util.jsonify(undefined); }).to.throw(TypeError);
expect(function () { return util.jsonify(null); }).to.throw(TypeError);
expect(function () { return util.jsonify(NaN); }).to.throw(TypeError);
expect(function () { return util.jsonify([]); }).to.throw(TypeError);
expect(function () { return util.jsonify({}); }).to.throw(TypeError);
expect(function () { return util.jsonify(true); }).to.throw(TypeError);
expect(function () { return util.jsonify(new Date()); }).to.throw(TypeError);
expect(function () { return util.jsonify(function () {}); }).to.throw(TypeError);
expect(function () { return util.jsonify(3); }).to.throw(Error);
expect(function () { return util.jsonify('3'); }).not.to.throw(Error);
expect(function () { return util.jsonify('xx'); }).not.to.throw(Error);
expect(function () { return util.jsonify('xx.y.z.g.h.j'); }).not.to.throw(Error);
expect(function () { return util.jsonify('xx/y/z/g/h/j'); }).not.to.throw(Error);
});
});
});
expect(() => util.jsonify('3')).not.to.throw(Error)
expect(() => util.jsonify('xx')).not.to.throw(Error)
expect(() => util.jsonify('xx.y.z.g.h.j')).not.to.throw(Error)
expect(() => util.jsonify('xx/y/z/g/h/j')).not.to.throw(Error)
})
})
})

@@ -1,510 +0,514 @@

var expect = require('chai').expect,
util = require('../index.js'); // lwm2m-util module
/* eslint-env mocha */
const { expect } = require('chai')
const util = require('../index.js') // lwm2m-util module
describe('APIs Functional Check', function() {
describe('#.getOid', function() {
it('returns a correct oid item', function () {
expect(util.getOid('temperature')).to.be.eql({ key: 'temperature', value: 3303 });
expect(util.getOid(3303)).to.be.eql({ key: 'temperature', value: 3303 });
expect(util.getOid('3303')).to.be.eql({ key: 'temperature', value: 3303 });
});
describe('APIs Functional Check', () => {
describe('#.getOid', () => {
it('returns a correct oid item', () => {
expect(util.getOid('temperature')).to.be.eql({ key: 'temperature', value: 3303 })
expect(util.getOid(3303)).to.be.eql({ key: 'temperature', value: 3303 })
expect(util.getOid('3303')).to.be.eql({ key: 'temperature', value: 3303 })
})
it('returns undefined if oid not found', function () {
expect(util.getOid('xxxx')).to.be.undefined;
expect(util.getOid('9999')).to.be.undefined;
expect(util.getOid(9999)).to.be.undefined;
});
});
it('returns undefined if oid not found', () => {
expect(util.getOid('xxxx')).to.equal(undefined)
expect(util.getOid('9999')).to.equal(undefined)
expect(util.getOid(9999)).to.equal(undefined)
})
})
describe('#.oidKey', function() {
it('returns a correct oid key', function () {
expect(util.oidKey('temperature')).to.be.eql('temperature');
expect(util.oidKey(3303)).to.be.eql('temperature');
expect(util.oidKey('3303')).to.be.eql('temperature');
});
describe('#.oidKey', () => {
it('returns a correct oid key', () => {
expect(util.oidKey('temperature')).to.be.eql('temperature')
expect(util.oidKey(3303)).to.be.eql('temperature')
expect(util.oidKey('3303')).to.be.eql('temperature')
})
it('returns itself if oid not found', function () {
expect(util.oidKey('xxxx')).to.be.eql('xxxx');
expect(util.oidKey('9999')).to.be.eql('9999');
expect(util.oidKey(9999)).to.be.eql('9999');
});
});
it('returns itself if oid not found', () => {
expect(util.oidKey('xxxx')).to.be.eql('xxxx')
expect(util.oidKey('9999')).to.be.eql('9999')
expect(util.oidKey(9999)).to.be.eql('9999')
})
})
describe('#.oidNum', function() {
it('returns a correct oid key', function () {
expect(util.oidNum('temperature')).to.be.eql(3303);
expect(util.oidNum(3303)).to.be.eql(3303);
expect(util.oidNum('3303')).to.be.eql(3303);
});
describe('#.oidNum', () => {
it('returns a correct oid key', () => {
expect(util.oidNum('temperature')).to.be.eql(3303)
expect(util.oidNum(3303)).to.be.eql(3303)
expect(util.oidNum('3303')).to.be.eql(3303)
})
it('returns itself if oid not found', function () {
expect(util.oidNum('xxxx')).to.be.eql('xxxx');
expect(util.oidNum('9999')).to.be.eql(9999);
expect(util.oidNum(9999)).to.be.eql(9999);
});
});
it('returns itself if oid not found', () => {
expect(util.oidNum('xxxx')).to.be.eql('xxxx')
expect(util.oidNum('9999')).to.be.eql(9999)
expect(util.oidNum(9999)).to.be.eql(9999)
})
})
describe('#.getRid(rid)', function() {
it('returns a correct rid item with input of rid alone', function () {
expect(util.getRid('appType')).to.be.eql({ key: 'appType', value: 5750 });
expect(util.getRid(5750)).to.be.eql({ key: 'appType', value: 5750 });
expect(util.getRid('5750')).to.be.eql({ key: 'appType', value: 5750 });
});
describe('#.getRid(rid)', () => {
it('returns a correct rid item with input of rid alone', () => {
expect(util.getRid('appType')).to.be.eql({ key: 'appType', value: 5750 })
expect(util.getRid(5750)).to.be.eql({ key: 'appType', value: 5750 })
expect(util.getRid('5750')).to.be.eql({ key: 'appType', value: 5750 })
})
it('returns undefined if rid not found with input of rid alone', function () {
expect(util.getRid('xxxx')).to.be.undefined;
expect(util.getRid('9999')).to.be.undefined;
expect(util.getRid(9999)).to.be.undefined;
});
});
it('returns undefined if rid not found with input of rid alone', () => {
expect(util.getRid('xxxx')).to.equal(undefined)
expect(util.getRid('9999')).to.equal(undefined)
expect(util.getRid(9999)).to.equal(undefined)
})
})
describe('#.getRid(oid, rid)', function() {
it('returns a correct rid item with input of oid plus rid', function () {
expect(util.getRid('location', 'lon')).to.be.eql({ key: 'lon', value: 1 });
expect(util.getRid(6, 1)).to.be.eql({ key: 'lon', value: 1 });
expect(util.getRid(6, 'lon')).to.be.eql({ key: 'lon', value: 1 });
expect(util.getRid('location', 1)).to.be.eql({ key: 'lon', value: 1 });
});
describe('#.getRid(oid, rid)', () => {
it('returns a correct rid item with input of oid plus rid', () => {
expect(util.getRid('location', 'lon')).to.be.eql({ key: 'lon', value: 1 })
expect(util.getRid(6, 1)).to.be.eql({ key: 'lon', value: 1 })
expect(util.getRid(6, 'lon')).to.be.eql({ key: 'lon', value: 1 })
expect(util.getRid('location', 1)).to.be.eql({ key: 'lon', value: 1 })
})
it('returns undefined if rid not found with input of oid plus rid', function () {
expect(util.getRid('locationx', 'lon')).to.be.undefined;
expect(util.getRid(61111, 1)).to.be.undefined;
expect(util.getRid(6, 'lonx')).to.be.undefined;
expect(util.getRid('location', 11111)).to.be.undefined;
});
});
it('returns undefined if rid not found with input of oid plus rid', () => {
expect(util.getRid('locationx', 'lon')).to.equal(undefined)
expect(util.getRid(61111, 1)).to.equal(undefined)
expect(util.getRid(6, 'lonx')).to.equal(undefined)
expect(util.getRid('location', 11111)).to.equal(undefined)
})
})
describe('#.ridKey(rid)', function() {
it('returns a correct rid item with input of rid alone', function () {
expect(util.ridKey('appType')).to.be.eql('appType');
expect(util.ridKey(5750)).to.be.eql('appType');
expect(util.ridKey('5750')).to.be.eql('appType');
});
describe('#.ridKey(rid)', () => {
it('returns a correct rid item with input of rid alone', () => {
expect(util.ridKey('appType')).to.be.eql('appType')
expect(util.ridKey(5750)).to.be.eql('appType')
expect(util.ridKey('5750')).to.be.eql('appType')
})
it('returns itself if rid not found with input of rid alone', function () {
expect(util.ridKey('xxxx')).to.be.eql('xxxx');
expect(util.ridKey('9999')).to.be.eql('9999');
expect(util.ridKey(9999)).to.be.eql('9999');
});
});
it('returns itself if rid not found with input of rid alone', () => {
expect(util.ridKey('xxxx')).to.be.eql('xxxx')
expect(util.ridKey('9999')).to.be.eql('9999')
expect(util.ridKey(9999)).to.be.eql('9999')
})
})
describe('#.ridKey(oid, rid)', function() {
it('returns a correct rid key with input of oid plus rid', function () {
expect(util.ridKey('location', 'lon')).to.be.eql('lon');
expect(util.ridKey(6, 1)).to.be.eql('lon');
expect(util.ridKey(6, 'lon')).to.be.eql('lon');
expect(util.ridKey('location', 1)).to.be.eql('lon');
});
describe('#.ridKey(oid, rid)', () => {
it('returns a correct rid key with input of oid plus rid', () => {
expect(util.ridKey('location', 'lon')).to.be.eql('lon')
expect(util.ridKey(6, 1)).to.be.eql('lon')
expect(util.ridKey(6, 'lon')).to.be.eql('lon')
expect(util.ridKey('location', 1)).to.be.eql('lon')
})
it('returns ridKey itself if rid not found with input of rid alone', function () {
expect(util.ridKey('lonx')).to.be.eql('lonx');
});
it('returns ridKey itself if rid not found with input of rid alone', () => {
expect(util.ridKey('lonx')).to.be.eql('lonx')
})
it('returns ridKey itself if oid not found with input of oid plus rid', function () {
expect(util.ridKey('locationx', 'lon')).to.be.eql('lon');
});
it('returns ridKey itself if oid not found with input of oid plus rid', () => {
expect(util.ridKey('locationx', 'lon')).to.be.eql('lon')
})
it('returns ridKey itself if oid or rid not found with input of oid plus rid', function () {
expect(util.ridKey(61111, 1)).to.be.eql('1');
expect(util.ridKey(6, 'lonx')).to.be.eql('lonx');
expect(util.ridKey('location', 11111)).to.be.eql('11111');
});
});
it('returns ridKey itself if oid or rid not found with input of oid plus rid', () => {
expect(util.ridKey(61111, 1)).to.be.eql('1')
expect(util.ridKey(6, 'lonx')).to.be.eql('lonx')
expect(util.ridKey('location', 11111)).to.be.eql('11111')
})
})
describe('#.ridNum(rid)', function() {
it('returns a correct rid number with input of rid alone', function () {
expect(util.ridNum('appType')).to.be.eql(5750);
expect(util.ridNum(5750)).to.be.eql(5750);
expect(util.ridNum('5750')).to.be.eql(5750);
});
describe('#.ridNum(rid)', () => {
it('returns a correct rid number with input of rid alone', () => {
expect(util.ridNum('appType')).to.be.eql(5750)
expect(util.ridNum(5750)).to.be.eql(5750)
expect(util.ridNum('5750')).to.be.eql(5750)
})
it('returns itself if rid not found with input of rid alone', function () {
expect(util.ridNum('xxxx')).to.be.eql('xxxx');
expect(util.ridNum('9999')).to.be.eql(9999);
expect(util.ridNum(9999)).to.be.eql(9999);
});
});
it('returns itself if rid not found with input of rid alone', () => {
expect(util.ridNum('xxxx')).to.be.eql('xxxx')
expect(util.ridNum('9999')).to.be.eql(9999)
expect(util.ridNum(9999)).to.be.eql(9999)
})
})
describe('#.ridNum(oid, rid)', function() {
it('returns a correct rid item with input of oid plus rid', function () {
expect(util.ridNum('location', 'lon')).to.be.eql(1);
expect(util.ridNum(6, 1)).to.be.eql(1);
expect(util.ridNum(6, 'lon')).to.be.eql(1);
expect(util.ridNum('location', 1)).to.be.eql(1);
});
describe('#.ridNum(oid, rid)', () => {
it('returns a correct rid item with input of oid plus rid', () => {
expect(util.ridNum('location', 'lon')).to.be.eql(1)
expect(util.ridNum(6, 1)).to.be.eql(1)
expect(util.ridNum(6, 'lon')).to.be.eql(1)
expect(util.ridNum('location', 1)).to.be.eql(1)
})
it('returns ridNum itself if rid not found with input of rid alone', function () {
expect(util.ridNum('lonx')).to.be.eql('lonx');
expect(util.ridNum(123456)).to.be.eql(123456);
expect(util.ridNum('123456')).to.be.eql(123456);
});
it('returns ridNum itself if rid not found with input of rid alone', () => {
expect(util.ridNum('lonx')).to.be.eql('lonx')
expect(util.ridNum(123456)).to.be.eql(123456)
expect(util.ridNum('123456')).to.be.eql(123456)
})
it('returns ridNum itself if oid not found with input of oid plus rid', function () {
expect(util.ridNum('locationx', 'lon')).to.be.eql('lon');
expect(util.ridNum('locationx', 123456)).to.be.eql(123456);
expect(util.ridNum('locationx', '123456')).to.be.eql(123456);
});
it('returns ridNum itself if oid not found with input of oid plus rid', () => {
expect(util.ridNum('locationx', 'lon')).to.be.eql('lon')
expect(util.ridNum('locationx', 123456)).to.be.eql(123456)
expect(util.ridNum('locationx', '123456')).to.be.eql(123456)
})
it('returns ridNum itself if oid or rid not found with input of oid plus rid', function () {
expect(util.ridNum(61111, 1)).to.be.eql(1);
expect(util.ridNum(61111, '1')).to.be.eql(1);
expect(util.ridNum(6, 'lonx')).to.be.eql('lonx');
expect(util.ridNum('location', 11111)).to.be.eql(11111);
});
});
it('returns ridNum itself if oid or rid not found with input of oid plus rid', () => {
expect(util.ridNum(61111, 1)).to.be.eql(1)
expect(util.ridNum(61111, '1')).to.be.eql(1)
expect(util.ridNum(6, 'lonx')).to.be.eql('lonx')
expect(util.ridNum('location', 11111)).to.be.eql(11111)
})
})
describe('#.getRspCode', function() {
it('returns a correct response code number item', function () {
expect(util.getRspCode(200)).to.be.eql({ key: 'OK', value: 200 });
expect(util.getRspCode(201)).to.be.eql({ key: 'Created', value: 201 });
expect(util.getRspCode(202)).to.be.eql({ key: 'Deleted', value: 202 });
expect(util.getRspCode(204)).to.be.eql({ key: 'Changed', value: 204 });
expect(util.getRspCode(205)).to.be.eql({ key: 'Content', value: 205 });
expect(util.getRspCode(400)).to.be.eql({ key: 'BadRequest', value: 400 });
expect(util.getRspCode(401)).to.be.eql({ key: 'Unauthorized', value: 401 });
expect(util.getRspCode(404)).to.be.eql({ key: 'NotFound', value: 404 });
expect(util.getRspCode(405)).to.be.eql({ key: 'MethodNotAllowed', value: 405 });
expect(util.getRspCode(408)).to.be.eql({ key: 'Timeout', value: 408 });
expect(util.getRspCode(409)).to.be.eql({ key: 'Conflict', value: 409 });
expect(util.getRspCode(500)).to.be.eql({ key: 'InternalServerError', value: 500 });
describe('#.getRspCode', () => {
it('returns a correct response code number item', () => {
expect(util.getRspCode(200)).to.be.eql({ key: 'OK', value: 200 })
expect(util.getRspCode(201)).to.be.eql({ key: 'Created', value: 201 })
expect(util.getRspCode(202)).to.be.eql({ key: 'Deleted', value: 202 })
expect(util.getRspCode(204)).to.be.eql({ key: 'Changed', value: 204 })
expect(util.getRspCode(205)).to.be.eql({ key: 'Content', value: 205 })
expect(util.getRspCode(400)).to.be.eql({ key: 'BadRequest', value: 400 })
expect(util.getRspCode(401)).to.be.eql({ key: 'Unauthorized', value: 401 })
expect(util.getRspCode(404)).to.be.eql({ key: 'NotFound', value: 404 })
expect(util.getRspCode(405)).to.be.eql({ key: 'MethodNotAllowed', value: 405 })
expect(util.getRspCode(408)).to.be.eql({ key: 'Timeout', value: 408 })
expect(util.getRspCode(409)).to.be.eql({ key: 'Conflict', value: 409 })
expect(util.getRspCode(500)).to.be.eql({ key: 'InternalServerError', value: 500 })
expect(util.getRspCode('OK')).to.be.eql({ key: 'OK', value: 200 });
expect(util.getRspCode('Created')).to.be.eql({ key: 'Created', value: 201 });
expect(util.getRspCode('Deleted')).to.be.eql({ key: 'Deleted', value: 202 });
expect(util.getRspCode('Changed')).to.be.eql({ key: 'Changed', value: 204 });
expect(util.getRspCode('Content')).to.be.eql({ key: 'Content', value: 205 });
expect(util.getRspCode('BadRequest')).to.be.eql({ key: 'BadRequest', value: 400 });
expect(util.getRspCode('Unauthorized')).to.be.eql({ key: 'Unauthorized', value: 401 });
expect(util.getRspCode('NotFound')).to.be.eql({ key: 'NotFound', value: 404 });
expect(util.getRspCode('MethodNotAllowed')).to.be.eql({ key: 'MethodNotAllowed', value: 405 });
expect(util.getRspCode('Timeout')).to.be.eql({ key: 'Timeout', value: 408 });
expect(util.getRspCode('Conflict')).to.be.eql({ key: 'Conflict', value: 409 });
expect(util.getRspCode('InternalServerError')).to.be.eql({ key: 'InternalServerError', value: 500 });
});
expect(util.getRspCode('OK')).to.be.eql({ key: 'OK', value: 200 })
expect(util.getRspCode('Created')).to.be.eql({ key: 'Created', value: 201 })
expect(util.getRspCode('Deleted')).to.be.eql({ key: 'Deleted', value: 202 })
expect(util.getRspCode('Changed')).to.be.eql({ key: 'Changed', value: 204 })
expect(util.getRspCode('Content')).to.be.eql({ key: 'Content', value: 205 })
expect(util.getRspCode('BadRequest')).to.be.eql({ key: 'BadRequest', value: 400 })
expect(util.getRspCode('Unauthorized')).to.be.eql({ key: 'Unauthorized', value: 401 })
expect(util.getRspCode('NotFound')).to.be.eql({ key: 'NotFound', value: 404 })
expect(util.getRspCode('MethodNotAllowed')).to.be.eql({ key: 'MethodNotAllowed', value: 405 })
expect(util.getRspCode('Timeout')).to.be.eql({ key: 'Timeout', value: 408 })
expect(util.getRspCode('Conflict')).to.be.eql({ key: 'Conflict', value: 409 })
expect(util.getRspCode('InternalServerError')).to.be.eql({ key: 'InternalServerError', value: 500 })
})
it('returns undefined if input is an invalid response code', function () {
expect(util.getRspCode('xxx')).to.be.undefined;
expect(util.getRspCode(123)).to.be.undefined;
});
});
it('returns undefined if input is an invalid response code', () => {
expect(util.getRspCode('xxx')).to.equal(undefined)
expect(util.getRspCode(123)).to.equal(undefined)
})
})
describe('#.rspCodeKey', function() {
it('returns a correct response code number item', function () {
expect(util.rspCodeKey(200)).to.be.eql('OK');
expect(util.rspCodeKey(201)).to.be.eql('Created');
expect(util.rspCodeKey(202)).to.be.eql('Deleted');
expect(util.rspCodeKey(204)).to.be.eql('Changed');
expect(util.rspCodeKey(205)).to.be.eql('Content');
expect(util.rspCodeKey(400)).to.be.eql('BadRequest');
expect(util.rspCodeKey(401)).to.be.eql('Unauthorized');
expect(util.rspCodeKey(404)).to.be.eql('NotFound');
expect(util.rspCodeKey(405)).to.be.eql('MethodNotAllowed');
expect(util.rspCodeKey(408)).to.be.eql('Timeout');
expect(util.rspCodeKey(409)).to.be.eql('Conflict');
expect(util.rspCodeKey(500)).to.be.eql('InternalServerError');
describe('#.rspCodeKey', () => {
it('returns a correct response code number item', () => {
expect(util.rspCodeKey(200)).to.be.eql('OK')
expect(util.rspCodeKey(201)).to.be.eql('Created')
expect(util.rspCodeKey(202)).to.be.eql('Deleted')
expect(util.rspCodeKey(204)).to.be.eql('Changed')
expect(util.rspCodeKey(205)).to.be.eql('Content')
expect(util.rspCodeKey(400)).to.be.eql('BadRequest')
expect(util.rspCodeKey(401)).to.be.eql('Unauthorized')
expect(util.rspCodeKey(404)).to.be.eql('NotFound')
expect(util.rspCodeKey(405)).to.be.eql('MethodNotAllowed')
expect(util.rspCodeKey(408)).to.be.eql('Timeout')
expect(util.rspCodeKey(409)).to.be.eql('Conflict')
expect(util.rspCodeKey(500)).to.be.eql('InternalServerError')
expect(util.rspCodeKey('OK')).to.be.eql('OK');
expect(util.rspCodeKey('Created')).to.be.eql('Created');
expect(util.rspCodeKey('Deleted')).to.be.eql('Deleted');
expect(util.rspCodeKey('Changed')).to.be.eql('Changed');
expect(util.rspCodeKey('Content')).to.be.eql('Content');
expect(util.rspCodeKey('BadRequest')).to.be.eql('BadRequest');
expect(util.rspCodeKey('Unauthorized')).to.be.eql('Unauthorized');
expect(util.rspCodeKey('NotFound')).to.be.eql('NotFound');
expect(util.rspCodeKey('MethodNotAllowed')).to.be.eql('MethodNotAllowed');
expect(util.rspCodeKey('Timeout')).to.be.eql('Timeout');
expect(util.rspCodeKey('Conflict')).to.be.eql('Conflict');
expect(util.rspCodeKey('InternalServerError')).to.be.eql('InternalServerError');
});
expect(util.rspCodeKey('OK')).to.be.eql('OK')
expect(util.rspCodeKey('Created')).to.be.eql('Created')
expect(util.rspCodeKey('Deleted')).to.be.eql('Deleted')
expect(util.rspCodeKey('Changed')).to.be.eql('Changed')
expect(util.rspCodeKey('Content')).to.be.eql('Content')
expect(util.rspCodeKey('BadRequest')).to.be.eql('BadRequest')
expect(util.rspCodeKey('Unauthorized')).to.be.eql('Unauthorized')
expect(util.rspCodeKey('NotFound')).to.be.eql('NotFound')
expect(util.rspCodeKey('MethodNotAllowed')).to.be.eql('MethodNotAllowed')
expect(util.rspCodeKey('Timeout')).to.be.eql('Timeout')
expect(util.rspCodeKey('Conflict')).to.be.eql('Conflict')
expect(util.rspCodeKey('InternalServerError')).to.be.eql('InternalServerError')
})
it('returns undefined if input is an invalid response code', function () {
expect(util.rspCodeKey('xxx')).to.be.undefined;
expect(util.rspCodeKey(123)).to.be.undefined;
});
});
it('returns undefined if input is an invalid response code', () => {
expect(util.rspCodeKey('xxx')).to.equal(undefined)
expect(util.rspCodeKey(123)).to.equal(undefined)
})
})
describe('#.rspCodeNum', function() {
it('returns a correct response code number item', function () {
expect(util.rspCodeNum(200)).to.be.eql(200);
expect(util.rspCodeNum(201)).to.be.eql(201);
expect(util.rspCodeNum(202)).to.be.eql(202);
expect(util.rspCodeNum(204)).to.be.eql(204);
expect(util.rspCodeNum(205)).to.be.eql(205);
describe('#.rspCodeNum', () => {
it('returns a correct response code number item', () => {
expect(util.rspCodeNum(200)).to.be.eql(200)
expect(util.rspCodeNum(201)).to.be.eql(201)
expect(util.rspCodeNum(202)).to.be.eql(202)
expect(util.rspCodeNum(204)).to.be.eql(204)
expect(util.rspCodeNum(205)).to.be.eql(205)
expect(util.rspCodeNum('OK')).to.be.eql(200);
expect(util.rspCodeNum('Created')).to.be.eql(201);
expect(util.rspCodeNum('Deleted')).to.be.eql(202);
expect(util.rspCodeNum('Changed')).to.be.eql(204);
expect(util.rspCodeNum('Content')).to.be.eql(205);
expect(util.rspCodeNum('OK')).to.be.eql(200)
expect(util.rspCodeNum('Created')).to.be.eql(201)
expect(util.rspCodeNum('Deleted')).to.be.eql(202)
expect(util.rspCodeNum('Changed')).to.be.eql(204)
expect(util.rspCodeNum('Content')).to.be.eql(205)
expect(util.rspCodeNum(400)).to.be.eql(400);
expect(util.rspCodeNum(401)).to.be.eql(401);
expect(util.rspCodeNum(404)).to.be.eql(404);
expect(util.rspCodeNum(405)).to.be.eql(405);
expect(util.rspCodeNum(408)).to.be.eql(408);
expect(util.rspCodeNum(409)).to.be.eql(409);
expect(util.rspCodeNum(500)).to.be.eql(500);
expect(util.rspCodeNum(400)).to.be.eql(400)
expect(util.rspCodeNum(401)).to.be.eql(401)
expect(util.rspCodeNum(404)).to.be.eql(404)
expect(util.rspCodeNum(405)).to.be.eql(405)
expect(util.rspCodeNum(408)).to.be.eql(408)
expect(util.rspCodeNum(409)).to.be.eql(409)
expect(util.rspCodeNum(500)).to.be.eql(500)
expect(util.rspCodeNum('BadRequest')).to.be.eql(400);
expect(util.rspCodeNum('Unauthorized')).to.be.eql(401);
expect(util.rspCodeNum('NotFound')).to.be.eql(404);
expect(util.rspCodeNum('MethodNotAllowed')).to.be.eql(405);
expect(util.rspCodeNum('Timeout')).to.be.eql(408);
expect(util.rspCodeNum('Conflict')).to.be.eql(409);
expect(util.rspCodeNum('InternalServerError')).to.be.eql(500);
});
expect(util.rspCodeNum('BadRequest')).to.be.eql(400)
expect(util.rspCodeNum('Unauthorized')).to.be.eql(401)
expect(util.rspCodeNum('NotFound')).to.be.eql(404)
expect(util.rspCodeNum('MethodNotAllowed')).to.be.eql(405)
expect(util.rspCodeNum('Timeout')).to.be.eql(408)
expect(util.rspCodeNum('Conflict')).to.be.eql(409)
expect(util.rspCodeNum('InternalServerError')).to.be.eql(500)
})
it('returns undefined if input is an invalid response code', function () {
expect(util.rspCodeNum('xxx')).to.be.undefined;
expect(util.rspCodeNum(123)).to.be.undefined;
});
});
it('returns undefined if input is an invalid response code', () => {
expect(util.rspCodeNum('xxx')).to.equal(undefined)
expect(util.rspCodeNum(123)).to.equal(undefined)
})
})
describe('#.getCmd', function() {
it('returns a correct command item', function () {
expect(util.getCmd('read')).to.be.eql({ key: 'read', value: 0 });
expect(util.getCmd('write')).to.be.eql({ key: 'write', value: 1 });
expect(util.getCmd('discover')).to.be.eql({ key: 'discover', value: 2 });
expect(util.getCmd('writeAttrs')).to.be.eql({ key: 'writeAttrs', value: 3 });
expect(util.getCmd('execute')).to.be.eql({ key: 'execute', value: 4 });
expect(util.getCmd('observe')).to.be.eql({ key: 'observe', value: 5 });
expect(util.getCmd('notify')).to.be.eql({ key: 'notify', value: 6 });
expect(util.getCmd('ping')).to.be.eql({ key: 'ping', value: 7 });
expect(util.getCmd('unknown')).to.be.eql({ key: 'unknown', value: 255 });
describe('#.getCmd', () => {
it('returns a correct command item', () => {
expect(util.getCmd('read')).to.be.eql({ key: 'read', value: 0 })
expect(util.getCmd('write')).to.be.eql({ key: 'write', value: 1 })
expect(util.getCmd('discover')).to.be.eql({ key: 'discover', value: 2 })
expect(util.getCmd('writeAttrs')).to.be.eql({ key: 'writeAttrs', value: 3 })
expect(util.getCmd('execute')).to.be.eql({ key: 'execute', value: 4 })
expect(util.getCmd('observe')).to.be.eql({ key: 'observe', value: 5 })
expect(util.getCmd('notify')).to.be.eql({ key: 'notify', value: 6 })
expect(util.getCmd('ping')).to.be.eql({ key: 'ping', value: 7 })
expect(util.getCmd('unknown')).to.be.eql({ key: 'unknown', value: 255 })
expect(util.getCmd(0)).to.be.eql({ key: 'read', value: 0 });
expect(util.getCmd(1)).to.be.eql({ key: 'write', value: 1 });
expect(util.getCmd(2)).to.be.eql({ key: 'discover', value: 2 });
expect(util.getCmd(3)).to.be.eql({ key: 'writeAttrs', value: 3 });
expect(util.getCmd(4)).to.be.eql({ key: 'execute', value: 4 });
expect(util.getCmd(5)).to.be.eql({ key: 'observe', value: 5 });
expect(util.getCmd(6)).to.be.eql({ key: 'notify', value: 6 });
expect(util.getCmd(7)).to.be.eql({ key: 'ping', value: 7 });
expect(util.getCmd(255)).to.be.eql({ key: 'unknown', value: 255 });
});
expect(util.getCmd(0)).to.be.eql({ key: 'read', value: 0 })
expect(util.getCmd(1)).to.be.eql({ key: 'write', value: 1 })
expect(util.getCmd(2)).to.be.eql({ key: 'discover', value: 2 })
expect(util.getCmd(3)).to.be.eql({ key: 'writeAttrs', value: 3 })
expect(util.getCmd(4)).to.be.eql({ key: 'execute', value: 4 })
expect(util.getCmd(5)).to.be.eql({ key: 'observe', value: 5 })
expect(util.getCmd(6)).to.be.eql({ key: 'notify', value: 6 })
expect(util.getCmd(7)).to.be.eql({ key: 'ping', value: 7 })
expect(util.getCmd(255)).to.be.eql({ key: 'unknown', value: 255 })
})
it('returns undefined if command number is invalid', function () {
expect(util.getCmd('readxx')).to.be.undefined;
expect(util.getCmd(123)).to.be.undefined;
});
});
it('returns undefined if command number is invalid', () => {
expect(util.getCmd('readxx')).to.equal(undefined)
expect(util.getCmd(123)).to.equal(undefined)
})
})
describe('#.cmdKey', function() {
it('returns a correct command number', function () {
expect(util.cmdKey('read')).to.be.eql('read');
expect(util.cmdKey('write')).to.be.eql('write');
expect(util.cmdKey('discover')).to.be.eql('discover');
expect(util.cmdKey('writeAttrs')).to.be.eql('writeAttrs');
expect(util.cmdKey('execute')).to.be.eql('execute');
expect(util.cmdKey('observe')).to.be.eql('observe');
expect(util.cmdKey('notify')).to.be.eql('notify');
expect(util.cmdKey('ping')).to.be.eql('ping');
expect(util.cmdKey('unknown')).to.be.eql('unknown');
describe('#.cmdKey', () => {
it('returns a correct command number', () => {
expect(util.cmdKey('read')).to.be.eql('read')
expect(util.cmdKey('write')).to.be.eql('write')
expect(util.cmdKey('discover')).to.be.eql('discover')
expect(util.cmdKey('writeAttrs')).to.be.eql('writeAttrs')
expect(util.cmdKey('execute')).to.be.eql('execute')
expect(util.cmdKey('observe')).to.be.eql('observe')
expect(util.cmdKey('notify')).to.be.eql('notify')
expect(util.cmdKey('ping')).to.be.eql('ping')
expect(util.cmdKey('unknown')).to.be.eql('unknown')
expect(util.cmdKey(0)).to.be.eql('read');
expect(util.cmdKey(1)).to.be.eql('write');
expect(util.cmdKey(2)).to.be.eql('discover');
expect(util.cmdKey(3)).to.be.eql('writeAttrs');
expect(util.cmdKey(4)).to.be.eql('execute');
expect(util.cmdKey(5)).to.be.eql('observe');
expect(util.cmdKey(6)).to.be.eql('notify');
expect(util.cmdKey(7)).to.be.eql('ping');
expect(util.cmdKey(255)).to.be.eql('unknown');
});
expect(util.cmdKey(0)).to.be.eql('read')
expect(util.cmdKey(1)).to.be.eql('write')
expect(util.cmdKey(2)).to.be.eql('discover')
expect(util.cmdKey(3)).to.be.eql('writeAttrs')
expect(util.cmdKey(4)).to.be.eql('execute')
expect(util.cmdKey(5)).to.be.eql('observe')
expect(util.cmdKey(6)).to.be.eql('notify')
expect(util.cmdKey(7)).to.be.eql('ping')
expect(util.cmdKey(255)).to.be.eql('unknown')
})
it('returns undefined if command number is invalid', function () {
expect(util.cmdKey('readxx')).to.be.undefined;
expect(util.cmdKey(123)).to.be.undefined;
});
});
it('returns undefined if command number is invalid', () => {
expect(util.cmdKey('readxx')).to.equal(undefined)
expect(util.cmdKey(123)).to.equal(undefined)
})
})
describe('#.cmdNum', function() {
it('returns a correct command number', function () {
expect(util.cmdNum('read')).to.be.eql(0);
expect(util.cmdNum('write')).to.be.eql(1);
expect(util.cmdNum('discover')).to.be.eql(2);
expect(util.cmdNum('writeAttrs')).to.be.eql(3);
expect(util.cmdNum('execute')).to.be.eql(4);
expect(util.cmdNum('observe')).to.be.eql(5);
expect(util.cmdNum('notify')).to.be.eql(6);
expect(util.cmdNum('ping')).to.be.eql(7);
expect(util.cmdNum('unknown')).to.be.eql(255);
describe('#.cmdNum', () => {
it('returns a correct command number', () => {
expect(util.cmdNum('read')).to.be.eql(0)
expect(util.cmdNum('write')).to.be.eql(1)
expect(util.cmdNum('discover')).to.be.eql(2)
expect(util.cmdNum('writeAttrs')).to.be.eql(3)
expect(util.cmdNum('execute')).to.be.eql(4)
expect(util.cmdNum('observe')).to.be.eql(5)
expect(util.cmdNum('notify')).to.be.eql(6)
expect(util.cmdNum('ping')).to.be.eql(7)
expect(util.cmdNum('unknown')).to.be.eql(255)
expect(util.cmdNum(0)).to.be.eql(0);
expect(util.cmdNum(1)).to.be.eql(1);
expect(util.cmdNum(2)).to.be.eql(2);
expect(util.cmdNum(3)).to.be.eql(3);
expect(util.cmdNum(4)).to.be.eql(4);
expect(util.cmdNum(5)).to.be.eql(5);
expect(util.cmdNum(6)).to.be.eql(6);
expect(util.cmdNum(7)).to.be.eql(7);
expect(util.cmdNum(255)).to.be.eql(255);
});
expect(util.cmdNum(0)).to.be.eql(0)
expect(util.cmdNum(1)).to.be.eql(1)
expect(util.cmdNum(2)).to.be.eql(2)
expect(util.cmdNum(3)).to.be.eql(3)
expect(util.cmdNum(4)).to.be.eql(4)
expect(util.cmdNum(5)).to.be.eql(5)
expect(util.cmdNum(6)).to.be.eql(6)
expect(util.cmdNum(7)).to.be.eql(7)
expect(util.cmdNum(255)).to.be.eql(255)
})
it('returns undefined if command number is invalid', function () {
expect(util.cmdNum('readxx')).to.be.undefined;
expect(util.cmdNum(123)).to.be.undefined;
});
});
it('returns undefined if command number is invalid', () => {
expect(util.cmdNum('readxx')).to.equal(undefined)
expect(util.cmdNum(123)).to.equal(undefined)
})
})
describe('#.createPath', function() {
it('returns a correct created path', function () {
var expectedString1 = 'dev/0/sensor/value',
expectedString2 = 'dev.0.sensor.value';
describe('#.createPath', () => {
it('returns a correct created path', () => {
const expectedString1 = 'dev/0/sensor/value'
// const expectedString2 = 'dev.0.sensor.value'
expect(util.createPath('/', 'dev', 0, 'sensor', 'value')).to.be.eql(expectedString1);
expect(util.createPath('/', 'dev', 0, 'sensor', 'value')).to.be.eql(expectedString1);
});
});
expect(util.createPath('/', 'dev', 0, 'sensor', 'value')).to.be.eql(expectedString1)
expect(util.createPath('/', 'dev', 0, 'sensor', 'value')).to.be.eql(expectedString1)
})
})
describe('#.slashPath', function() {
it('returns a correct slash path', function () {
var expectedString = 'dev/0/sensor/value';
describe('#.slashPath', () => {
it('returns a correct slash path', () => {
const expectedString = 'dev/0/sensor/value'
expect(util.slashPath('dev.0.sensor.value')).to.be.eql(expectedString);
expect(util.slashPath('.dev.0.sensor.value')).to.be.eql(expectedString);
expect(util.slashPath('.dev.0.sensor.value.')).to.be.eql(expectedString);
expect(util.slashPath('/dev.0.sensor/value/')).to.be.eql(expectedString);
expect(util.slashPath('/dev/0/sensor/value/')).to.be.eql(expectedString);
expect(util.slashPath('.dev/0/sensor/value.')).to.be.eql(expectedString);
});
});
expect(util.slashPath('dev.0.sensor.value')).to.be.eql(expectedString)
expect(util.slashPath('.dev.0.sensor.value')).to.be.eql(expectedString)
expect(util.slashPath('.dev.0.sensor.value.')).to.be.eql(expectedString)
expect(util.slashPath('/dev.0.sensor/value/')).to.be.eql(expectedString)
expect(util.slashPath('/dev/0/sensor/value/')).to.be.eql(expectedString)
expect(util.slashPath('.dev/0/sensor/value.')).to.be.eql(expectedString)
})
})
describe('#.dotPath', function() {
it('returns a correct dot path', function () {
var expectedString = 'dev.0.sensor.value';
describe('#.dotPath', () => {
it('returns a correct dot path', () => {
const expectedString = 'dev.0.sensor.value'
expect(util.dotPath('dev.0.sensor.value')).to.be.eql(expectedString);
expect(util.dotPath('.dev.0.sensor.value')).to.be.eql(expectedString);
expect(util.dotPath('.dev.0.sensor.value.')).to.be.eql(expectedString);
expect(util.dotPath('/dev.0.sensor/value/')).to.be.eql(expectedString);
expect(util.dotPath('/dev/0/sensor/value/')).to.be.eql(expectedString);
expect(util.dotPath('.dev/0/sensor/value.')).to.be.eql(expectedString);
});
});
expect(util.dotPath('dev.0.sensor.value')).to.be.eql(expectedString)
expect(util.dotPath('.dev.0.sensor.value')).to.be.eql(expectedString)
expect(util.dotPath('.dev.0.sensor.value.')).to.be.eql(expectedString)
expect(util.dotPath('/dev.0.sensor/value/')).to.be.eql(expectedString)
expect(util.dotPath('/dev/0/sensor/value/')).to.be.eql(expectedString)
expect(util.dotPath('.dev/0/sensor/value.')).to.be.eql(expectedString)
})
})
describe('#.pathItems', function() {
it('returns a correct array of a / path', function () {
var expectedArr = [ 'dev', '0', 'sensor', 'value' ];
describe('#.pathItems', () => {
it('returns a correct array of a / path', () => {
const expectedArr = ['dev', '0', 'sensor', 'value']
expect(util.pathItems('dev')).to.be.eql([ 'dev' ]);
expect(util.pathItems('dev.0.sensor.value')).to.be.eql(expectedArr);
expect(util.pathItems('.dev.0.sensor.value')).to.be.eql(expectedArr);
expect(util.pathItems('.dev.0.sensor.value.')).to.be.eql(expectedArr);
expect(util.pathItems('/dev.0.sensor/value/')).to.be.eql(expectedArr);
expect(util.pathItems('/dev/0/sensor/value/')).to.be.eql(expectedArr);
expect(util.pathItems('.dev/0/sensor/value.')).to.be.eql(expectedArr);
});
});
expect(util.pathItems('dev')).to.be.eql(['dev'])
expect(util.pathItems('dev.0.sensor.value')).to.be.eql(expectedArr)
expect(util.pathItems('.dev.0.sensor.value')).to.be.eql(expectedArr)
expect(util.pathItems('.dev.0.sensor.value.')).to.be.eql(expectedArr)
expect(util.pathItems('/dev.0.sensor/value/')).to.be.eql(expectedArr)
expect(util.pathItems('/dev/0/sensor/value/')).to.be.eql(expectedArr)
expect(util.pathItems('.dev/0/sensor/value.')).to.be.eql(expectedArr)
})
})
describe('#.buildPathValuePairs', function() {
var myObj = {
a: {
a1: {
a11: 1,
a12: 'hi',
},
a2: 'foo'
},
b: 'hello',
c: 3
};
describe('#.buildPathValuePairs', () => {
const myObj = {
a: {
a1: {
a11: 1,
a12: 'hi'
},
a2: 'foo'
},
b: 'hello',
c: 3
}
it('returns a correct path-value pairs of an object with root /', function () {
var expectedObj = {
'a.a1.a11': 1,
'a.a1.a12': 'hi',
'a.a2': 'foo',
'b': 'hello',
'c': 3
};
expect(util.buildPathValuePairs('/', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('.', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('', myObj)).to.be.eql(expectedObj);
});
it('returns a correct path-value pairs of an object with root /', () => {
const expectedObj = {
'a.a1.a11': 1,
'a.a1.a12': 'hi',
'a.a2': 'foo',
b: 'hello',
c: 3
}
expect(util.buildPathValuePairs('/', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('.', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('', myObj)).to.be.eql(expectedObj)
})
it('returns a correct path-value pairs of an object with root /dev/0', function () {
var expectedObj = {
'dev.0.a.a1.a11': 1,
'dev.0.a.a1.a12': 'hi',
'dev.0.a.a2': 'foo',
'dev.0.b': 'hello',
'dev.0.c': 3
};
expect(util.buildPathValuePairs('/dev/0/', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('/dev/0', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('dev/0/', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('dev/0', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('.dev.0.', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('.dev.0', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('dev.0.', myObj)).to.be.eql(expectedObj);
expect(util.buildPathValuePairs('dev.0', myObj)).to.be.eql(expectedObj);
});
});
it('returns a correct path-value pairs of an object with root /dev/0', () => {
const expectedObj = {
'dev.0.a.a1.a11': 1,
'dev.0.a.a1.a12': 'hi',
'dev.0.a.a2': 'foo',
'dev.0.b': 'hello',
'dev.0.c': 3
}
expect(util.buildPathValuePairs('/dev/0/', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('/dev/0', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('dev/0/', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('dev/0', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('.dev.0.', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('.dev.0', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('dev.0.', myObj)).to.be.eql(expectedObj)
expect(util.buildPathValuePairs('dev.0', myObj)).to.be.eql(expectedObj)
})
})
describe('#.isGoodResponse', function() {
it('should be true if input is a good status code', function () {
expect(util.isGoodResponse(200)).to.be.true;
expect(util.isGoodResponse(201)).to.be.true;
expect(util.isGoodResponse(202)).to.be.true;
expect(util.isGoodResponse(204)).to.be.true;
expect(util.isGoodResponse(205)).to.be.true;
describe('#.isGoodResponse', () => {
it('should be true if input is a good status code', () => {
expect(util.isGoodResponse(200)).to.equal(true)
expect(util.isGoodResponse(201)).to.equal(true)
expect(util.isGoodResponse(202)).to.equal(true)
expect(util.isGoodResponse(204)).to.equal(true)
expect(util.isGoodResponse(205)).to.equal(true)
expect(util.isGoodResponse('OK')).to.be.true;
expect(util.isGoodResponse('Created')).to.be.true;
expect(util.isGoodResponse('Deleted')).to.be.true;
expect(util.isGoodResponse('Changed')).to.be.true;
expect(util.isGoodResponse('Content')).to.be.true;
});
expect(util.isGoodResponse('OK')).to.equal(true)
expect(util.isGoodResponse('Created')).to.equal(true)
expect(util.isGoodResponse('Deleted')).to.equal(true)
expect(util.isGoodResponse('Changed')).to.equal(true)
expect(util.isGoodResponse('Content')).to.equal(true)
})
it('should be false if input is a bad status code', function () {
expect(util.isGoodResponse(400)).to.be.false;
expect(util.isGoodResponse(401)).to.be.false;
expect(util.isGoodResponse(404)).to.be.false;
expect(util.isGoodResponse(405)).to.be.false;
expect(util.isGoodResponse(408)).to.be.false;
expect(util.isGoodResponse(409)).to.be.false;
expect(util.isGoodResponse(500)).to.be.false;
it('should be false if input is a bad status code', () => {
expect(util.isGoodResponse(400)).to.equal(false)
expect(util.isGoodResponse(401)).to.equal(false)
expect(util.isGoodResponse(404)).to.equal(false)
expect(util.isGoodResponse(405)).to.equal(false)
expect(util.isGoodResponse(408)).to.equal(false)
expect(util.isGoodResponse(409)).to.equal(false)
expect(util.isGoodResponse(500)).to.equal(false)
expect(util.isGoodResponse('BadRequest')).to.be.false;
expect(util.isGoodResponse('Unauthorized')).to.be.false;
expect(util.isGoodResponse('NotFound')).to.be.false;
expect(util.isGoodResponse('MethodNotAllowed')).to.be.false;
expect(util.isGoodResponse('Timeout')).to.be.false;
expect(util.isGoodResponse('Conflict')).to.be.false;
expect(util.isGoodResponse('InternalServerError')).to.be.false;
});
expect(util.isGoodResponse('BadRequest')).to.equal(false)
expect(util.isGoodResponse('Unauthorized')).to.equal(false)
expect(util.isGoodResponse('NotFound')).to.equal(false)
expect(util.isGoodResponse('MethodNotAllowed')).to.equal(false)
expect(util.isGoodResponse('Timeout')).to.equal(false)
expect(util.isGoodResponse('Conflict')).to.equal(false)
expect(util.isGoodResponse('InternalServerError')).to.equal(false)
})
it('should be false if input is an unknown status code', () => {
expect(util.isGoodResponse(108)).to.equal(false)
expect(util.isGoodResponse('xx')).to.equal(false)
})
})
it('should be false if input is an unknown status code', function () {
expect(util.isGoodResponse(108)).to.be.false;
expect(util.isGoodResponse('xx')).to.be.false;
});
});
describe('#.getAccessCtrl', () => {
it('should get right value', () => {
expect(util.getAccessCtrl('temperature', 'sensorValue')).to.be.eql('R')
expect(util.getAccessCtrl('lightCtrl', 5850)).to.be.eql('RW')
})
describe('#.getAccessCtrl', function() {
it('should get right value', function () {
expect(util.getAccessCtrl('temperature', 'sensorValue')).to.be.eql('R');
expect(util.getAccessCtrl('lightCtrl', 5850)).to.be.eql('RW');
});
it('should get undefined if target not found', () => {
expect(util.getAccessCtrl('temperature', 1234)).to.equal(undefined)
expect(util.getAccessCtrl('xxxx', 1234)).to.equal(undefined)
})
})
it('should get undefined if target not found', function () {
expect(util.getAccessCtrl('temperature', 1234)).to.be.undefined;
expect(util.getAccessCtrl('xxxx', 1234)).to.be.undefined;
});
});
describe('#.jsonify', () => {
it('is a string hello', () => {
expect(util.jsonify('hello')).to.be.eql('hello')
})
describe('#.jsonify', function() {
it('is a string hello', function () {
expect(util.jsonify('hello')).to.be.eql('hello');
});
it('is a string which cannot be parsed', () => {
expect(util.jsonify('{: { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}')).to.be.eql('{: { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}')
})
it('is a string which cannot be parsed', function () {
expect(util.jsonify('{: { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}')).to.be.eql('{: { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}');
});
it('is ab object', function () {
expect(util.jsonify('{"rspCode": { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}')).to.be.eql({ "rspCode": { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 } });
});
});
});
it('is ab object', () => {
expect(util.jsonify('{"rspCode": { "OK": 200, "Created": 201, "Deleted": 202, "Changed": 204, "Content": 205 }}')).to.be.eql({
rspCode: {
OK: 200, Created: 201, Deleted: 202, Changed: 204, Content: 205
}
})
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc