node-red-contrib-mockingbird
v0.1.0
Published
A Node-RED node to create a mockdata for test-cases.
Downloads
5
Maintainers
Readme
node-red-mockingbird
base on node-red-node-web-data-generator
A Node-RED node to create a mockdata for test-cases.
Install
Run the following command in your Node-RED user directory - typically ~/.node-red
npm install node-red-contrib-mockingbird
Usage
Creates dummy data based on a handlebars-style template.
Uses the dummy-json module, which can create rich sets of dummy data for testing or other uses.
It will build a string, or a parsed JSON object, creating values based on the helper names below:
title, firstname, lastname, company, domain, tld, email,
street, city, country, countryCode, zipcode, postcode,
lat, long, phone, color, hexColor, guid,
ipv4, ipv6, lorem, date, time,
lowercase, uppercase, int, float, boolean
Multiple values can be generated by use of the repeat
syntax.
In addition any properties passed in on the msg
object can also be used - for example {{payload}}.
Finally msg.seed
can be used to preset the pseudo-random seed to ensure repeatability across calls.
Example
The example flow below produces a JSON string which is then converted into an object, for example:
{
"name": "Theo Cumbie",
"work": "CoreXTS",
"email": "[email protected]",
"address": "83 Sherman Road",
"country": "Angola",
"text": "Sagittis orci elementum e vel scelerisque. Amet ac tristique lectus. Morbi e suscipit scelerisque auctor curabitur velit metus gravida quis."
}
Example flow
[{"id":"10189452.18ef3c","type":"tab","label":"流程1"},{"id":"ed7643.abe789c","type":"inject","z":"10189452.18ef3c","name":"","topic":"","payload":"","payloadType":"str","repeat":"3","crontab":"","once":false,"x":270,"y":240,"wires":[["6c645b2e.b7f0f4"]]},{"id":"75379d17.68c494","type":"debug","z":"10189452.18ef3c","name":"","active":true,"console":"false","complete":"false","x":673,"y":240,"wires":[]},{"id":"6c645b2e.b7f0f4","type":"mockingbird","z":"10189452.18ef3c","name":"","field":"payload","fieldType":"msg","optionField":"MBOption","optionFieldType":"flow","syntax":"json","template":"{\n \"ID\": \"{{guid}}\",\n \"value\": {{float 20 80 '0.00'}},\n \"manufacturerID\": \"{{randomItem 'IBM' 'SONY' 'APPLE'}}\",\n \"tags\":[\n {{#repeat 0 3}}\n \"{{tag}}\"\n {{/repeat}}\n ],\n \"location\":{\n \"city\": \"{{city}}\",\n \"zone\": \"{{randomItem 'A区' 'B区' 'C区'}}\",\n \"building\": \"{{randomItem '1号楼' '2号楼'}}\",\n \"floor\": \"{{randomItem '1F' '2F' '3F'}}\",\n \"room\": \"{{randomItem '01' '02' '03'}}\"\n }\n}","x":450,"y":240,"wires":[["75379d17.68c494"]]},{"id":"9f723d02.3aaa3","type":"function","z":"10189452.18ef3c","name":"option","func":"function randomArrayItem(arr){\n return arr[Math.floor(Math.random() * arr.length)]\n}\nflow.set('MBOption', {\n mockdata:{\n cities: ['上海','北京','广州','武汉']\n },\n helpers:{\n tag: function (){\n return 'Tag-' + Math.floor(Math.random() * 99);\n }\n }\n\n})","outputs":1,"noerr":0,"x":330,"y":140,"wires":[[]]},{"id":"425de352.e346cc","type":"inject","z":"10189452.18ef3c","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"x":150,"y":140,"wires":[["9f723d02.3aaa3"]]}]