Skip to content

Tests of nodes that use config nodes that implement RED.httpAdmin.get(… fail  #33

Open

Description

@jorisadri

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 });
    });
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions