node-red-node-test-helper
node-red-node-test-helper copied to clipboard
Tests of nodes that use config nodes that implement RED.httpAdmin.get(… fail
When testing nodes that use a config node that implements RED.httpAdmin.get(…, the tests fail.
When doing helper.getNode("node1")
It fails with this error:
TypeError: Cannot read property ‘get’ of null
at Array.module.exports (location to line number with RED.httpAdmin.get(… )
at Object.load (node_modules/node-red-node-test-helper/index.js:131:28)
at Context.<anonymous> (to location of the helper.load(<node that implements the config>))
Code of the config
module.exports = function (RED) {
const { Account, PublicAccount, NetworkType } = require('nem2-sdk');
function accountConfig(config) {
RED.nodes.createNode(this, config);
this.name = config.name;
this.privateKey = config.privateKey;
this.publicKey = config.publicKey;
this.address = config.address;
this.network = RED.nodes.getNode(config.network).network
}
RED.nodes.registerType("accountConfig", accountConfig);
RED.httpAdmin.get("/accountinfo", RED.auth.needsPermission('accountConfig.read'), function (req, res) {
const network = RED.nodes.getNode(req.query.network).network
let publicKey = req.query.privateKey ? Account.createFromPrivateKey(req.query.privateKey, NetworkType[network]).publicKey : req.query.publicKey;
let address = publicKey ? PublicAccount.createFromPublicKey(publicKey, NetworkType[network]).address.plain() : req.query.address;
res.json({ publicKey: publicKey, address: address });
});
};