node-red-contrib-set-defaults 0.9.1

A Node-RED node that can set undefined values on context or msg to configured default value. It can send those values out with msg.

npm install node-red-contrib-set-defaults

node-red-contrib-set-defaults

Install

cd ~\.node-red
npm install node-red-contrib-set-defaults

Run tests

cd <your location>/node-red-contrib-set-defaults
npm install node-red-node-test-helper --save-dev
npm install mocha --save-dev
npm install <path to your Node-RED install> --no-save
npm test

For further information about unit testing Node-RED nodes, please refer to Node Test Helper Github or NPM page.

Flow - unit test nodes

The following flow are the nodes I have used for unit tests. Flow can be easily imported into Node-RED project. Together with checking the test code, it may help in understanding the capabilities of this node.

[{"id":"659d1f91.524e7","type":"set-defaults","z":"c4771134.58bd4","name":"t11n","rules":[{"t":"set","p":"first","pt":"flow","to":"v1","tot":"str"},{"t":"set","p":"msg.devil","pt":"flow","to":"funny","tot":"str"}],"chbox_DoOutputToMessage":false,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":170,"y":260,"wires":[["2767e8ad.0b9568"]]},{"id":"3a6692e6.07f59e","type":"set-defaults","z":"c4771134.58bd4","name":"t12n","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"never","tot":"str"},{"t":"set","p":"third","pt":"global","to":"glob","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":170,"y":320,"wires":[["2767e8ad.0b9568"]]},{"id":"2767e8ad.0b9568","type":"link out","z":"c4771134.58bd4","name":"sinkNode","links":[],"x":1015,"y":360,"wires":[]},{"id":"5f8c5e.1ff1c3a4","type":"set-defaults","z":"c4771134.58bd4","name":"t18n","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"msg","to":"never","tot":"str"},{"t":"set","p":"r3","pt":"msg","to":"last","tot":"str"},{"t":"set","p":"items.one","pt":"msg","to":"112","tot":"num"},{"t":"set","p":"items.two","pt":"msg","to":"{\"what\":\"is\",\"this\":\"rly\"}","tot":"json"}],"chbox_DoOutputToMessage":false,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":170,"y":660,"wires":[["2767e8ad.0b9568"]]},{"id":"9437e488.02abf8","type":"set-defaults","z":"c4771134.58bd4","name":"t22n","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"never","tot":"str"},{"t":"set","p":"third","pt":"global","to":"glob","tot":"str"},{"t":"set","p":"second1.smthElse","pt":"flow","to":"complicated","tot":"str"},{"t":"set","p":"second1.finisher","pt":"flow","to":"awsome","tot":"str"},{"t":"set","p":"h1.h2.h3","pt":"global","to":"hierarchy","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":350,"y":320,"wires":[[]]},{"id":"37080c31.05f304","type":"set-defaults","z":"c4771134.58bd4","name":"t32n","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"never","tot":"str"},{"t":"set","p":"third","pt":"global","to":"glob","tot":"str"},{"t":"set","p":"awsomness","pt":"msg","to":"great","tot":"str"},{"t":"set","p":"unchangable.v1","pt":"msg","to":"something","tot":"str"},{"t":"set","p":"unchangeable.v2","pt":"msg","to":"something_else","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":550,"y":320,"wires":[[]]},{"id":"3ad294aa.a5a89c","type":"set-defaults","z":"c4771134.58bd4","name":"t13","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"never","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"multiple","dropdownObjOrVal":"value","outputs":2,"x":170,"y":400,"wires":[["2767e8ad.0b9568"],["a63130b9.18102"]]},{"id":"a63130b9.18102","type":"link out","z":"c4771134.58bd4","name":"sinkNode1","links":[],"x":1015,"y":760,"wires":[]},{"id":"4be643c2.27563c","type":"set-defaults","z":"c4771134.58bd4","name":"t14_changedId","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"never","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"msg","modifiedValue":"tstt"},"dropdown_HowManyMessages":"multiple","dropdownObjOrVal":"keyValue","outputs":2,"x":200,"y":820,"wires":[[],[]]},{"id":"249376fc.5cc1ca","type":"set-defaults","z":"c4771134.58bd4","name":"t15","rules":[{"p":"first","pt":"flow","to":"kiw","tot":"str"},{"p":"second","pt":"flow","to":"df","tot":"str"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"tstt","type":"full","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"keyValue","outputs":1,"x":170,"y":500,"wires":[["2767e8ad.0b9568"]]},{"id":"40f5d2a9.2016bc","type":"set-defaults","z":"c4771134.58bd4","name":"t16","rules":[{"t":"set","p":"first","pt":"flow","to":"kiw","tot":"str"},{"t":"set","p":"second","pt":"flow","to":"df","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"full","modifiedValue":"tstt"},"dropdown_HowManyMessages":"multiple","dropdownObjOrVal":"value","outputs":2,"x":170,"y":560,"wires":[["2767e8ad.0b9568"],["a63130b9.18102"]]},{"id":"69b3a271.cf7e2c","type":"set-defaults","z":"c4771134.58bd4","name":"t19n","rules":[{"t":"set","p":"first","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"second","pt":"msg","to":"never","tot":"str"},{"t":"set","p":"r3","pt":"msg","to":"last","tot":"str"},{"t":"set","p":"first","pt":"msg","to":"some string","tot":"str"},{"t":"set","p":"first","pt":"msg","to":"this will never be","tot":"str"},{"t":"set","p":"first.some.object","pt":"msg","to":"imaginary1","tot":"str"},{"t":"set","p":"first.some.another","pt":"msg","to":"imaginary2","tot":"str"},{"t":"set","p":"someObject.subobject.somestring","pt":"msg","to":"str","tot":"str"},{"t":"set","p":"someObject.subobject.someint","pt":"msg","to":"88114.11","tot":"num"},{"t":"set","p":"someObject.subobject.the_false","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"someObject.stringval","pt":"msg","to":"actualString","tot":"str"},{"t":"set","p":"someObject","pt":"msg","to":"dropEverything","tot":"str"}],"chbox_DoOutputToMessage":true,"howSend":{"text":"tstt","type":"full","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":170,"y":720,"wires":[["2767e8ad.0b9568"]]},{"id":"231025f4.61663a","type":"set-defaults","z":"c4771134.58bd4","name":"t23","rules":[{"p":"first","pt":"flow","to":"v2","tot":"str"},{"p":"first","pt":"flow","to":"nochange_v3","tot":"str"},{"p":"first.advanced","pt":"flow","to":"nochange_v4","tot":"str"},{"p":"first.advanced","pt":"global","to":"v5","tot":"str"},{"p":"tree.first.v1","pt":"flow","to":"v6","tot":"str"},{"p":"tree.first.v2","pt":"flow","to":"v7","tot":"str"},{"p":"tree.second","pt":"flow","to":"v8","tot":"str"},{"p":"xfirst.advanced.anotherobj.payload1","pt":"flow","to":"terminated","tot":"str"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"tstt","type":"full","modifiedValue":"tstt"},"dropdown_HowManyMessages":"multiple","dropdownObjOrVal":"value","outputs":8,"x":350,"y":400,"wires":[["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"],["2767e8ad.0b9568"]]},{"id":"258c499e.ca8326","type":"set-defaults","z":"c4771134.58bd4","name":"taa1","rules":[{"t":"set","p":"dt","pt":"msg","to":"$toMillis('2018-08-15T18:43:02Z')","tot":"jsonata"},{"t":"set","p":"minus.one_hour","pt":"flow","to":"dt-$toMillis(\"1970-01-01T01:00:00Z\")","tot":"jsonata"},{"t":"set","p":"minus.approx_one_day","pt":"flow","to":"dt-$toMillis(\"1970-01-02T01:32:00Z\")","tot":"jsonata"},{"t":"set","p":"tomorrow","pt":"msg","to":"dt+$toMillis(\"1970-01-02T00:00:00Z\")","tot":"jsonata"},{"t":"set","p":"humanFriendly.minus.one_hour","pt":"global","to":"$fromMillis(minus.one_hour)","tot":"jsonata"},{"t":"set","p":"humanFriendly.minus.approx_one_day","pt":"global","to":"$fromMillis(minus.approx_one_day)","tot":"jsonata"},{"t":"set","p":"humanFriendly.tomorrow","pt":"global","to":"$fromMillis(tomorrow)","tot":"jsonata"},{"t":"set","p":"humanFriendly.dt","pt":"global","to":"$fromMillis(dt)","tot":"jsonata"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"tstt","type":"full","modifiedValue":"tstt"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":890,"y":320,"wires":[["2767e8ad.0b9568"]]},{"id":"62197683.d74f68","type":"set-defaults","z":"c4771134.58bd4","name":"taa5_set","rules":[{"t":"set","p":"simple1","pt":"flow","to":"v1","tot":"str"},{"t":"set","p":"simpleStays","pt":"flow","to":"v2","tot":"str"},{"t":"set","p":"deep.willDelete","pt":"flow","to":"v3","tot":"str"},{"t":"set","p":"deep.wontDelete","pt":"flow","to":"v4","tot":"str"},{"t":"set","p":"deep.deletingObj.v1","pt":"flow","to":"v5","tot":"str"},{"t":"set","p":"deep.deletingObj.v2","pt":"flow","to":"v6","tot":"str"},{"t":"set","p":"deep.deletingObj.v3","pt":"flow","to":"v7","tot":"str"},{"t":"set","p":"deep.deeper.first_del","pt":"flow","to":"v8","tot":"str"},{"t":"set","p":"deep.deeper.second","pt":"flow","to":"v9","tot":"str"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"payload","type":"full","modifiedValue":"payload"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":1220,"y":460,"wires":[["407ea555.fa4b3c"]]},{"id":"14af3dfd.79a382","type":"set-defaults","z":"c4771134.58bd4","name":"taa5_delmsg","rules":[{"p":"deep.wontDelete","pt":"msg","to":"","tot":"to_undefined"},{"p":"deep.deeper","pt":"msg","to":"","tot":"to_undefined"},{"p":"simpleStays","pt":"msg","to":"","tot":"to_undefined"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"payload","type":"full","modifiedValue":"payload"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":1230,"y":620,"wires":[["a63130b9.18102"]]},{"id":"4e4f4f6f.e0dbf","type":"comment","z":"c4771134.58bd4","name":"delete flow","info":"","x":1220,"y":500,"wires":[]},{"id":"2d738d8a.b62f62","type":"comment","z":"c4771134.58bd4","name":"Set flow, msg","info":"","x":1230,"y":420,"wires":[]},{"id":"407ea555.fa4b3c","type":"set-defaults","z":"c4771134.58bd4","name":"taa5_del","rules":[{"t":"set","p":"simple1","pt":"flow","to":"","tot":"to_undefined"},{"t":"set","p":"deep.willDelete","pt":"flow","to":"","tot":"to_undefined"},{"t":"set","p":"deep.deletingObj","pt":"flow","to":"","tot":"to_undefined"},{"t":"set","p":"deep.deeper.first_del","pt":"flow","to":"","tot":"to_undefined"}],"chbox_DoOutputToMessage":true,"chbox_SetCurrentToMsg":true,"howSend":{"text":"payload","type":"full","modifiedValue":"payload"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":1220,"y":540,"wires":[["2767e8ad.0b9568","14af3dfd.79a382"]]},{"id":"35df47a2.cbdc48","type":"comment","z":"c4771134.58bd4","name":"Delete from msg","info":"","x":1240,"y":580,"wires":[]},{"id":"22ab3dd7.436d92","type":"set-defaults","z":"c4771134.58bd4","name":"taa6","rules":[{"t":"set","p":"ways","pt":"flow","to":"s1","tot":"str"},{"t":"set","p":"ways1","pt":"flow","to":"ways","tot":"flow"},{"t":"set","p":"q1","pt":"msg","to":"ways","tot":"flow"},{"t":"set","p":"final","pt":"flow","to":"q1","tot":"msg"},{"t":"set","p":"final","pt":"msg","to":"final","tot":"flow"},{"t":"set","p":"ways","pt":"msg","to":"ways","tot":"flow"},{"t":"set","p":"ways1","pt":"msg","to":"ways1","tot":"flow"},{"t":"set","p":"globs","pt":"global","to":"final","tot":"flow"}],"chbox_DoOutputToMessage":false,"chbox_SetCurrentToMsg":false,"howSend":{"text":"payload","type":"msg","modifiedValue":"payload"},"dropdown_HowManyMessages":"single","dropdownObjOrVal":"value","outputs":1,"x":870,"y":820,"wires":[["2767e8ad.0b9568"]]}]

Node Info

Version: 0.9.1
Updated 6 years, 9 months ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

54 in the last week

Nodes

  • set-defaults

Keywords

  • node-red

Maintainers