# How can I add credential into my test function (Node-red-node-test-helper)?

**URL:** <https://discourse.nodered.org/t/how-can-i-add-credential-into-my-test-function-node-red-node-test-helper/57429>\
**Category:** Developing Nodes\
**Created:** [28 January 2022 21:51 UTC](https://discourse.nodered.org/t/how-can-i-add-credential-into-my-test-function-node-red-node-test-helper/57429 "2022-01-28T21:51:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)\
**Post date:** [28 January 2022 21:51 UTC](https://discourse.nodered.org/t/how-can-i-add-credential-into-my-test-function-node-red-node-test-helper/57429/1 "2022-01-28T21:51:05Z")

</div>

Hi all,

First, I have a created node and it use credential value.

Normally, the credential is from input from screen.

Now I want to test, if I use invalid token with my request to destination server. It should return error 401.

How can I add credential into my test function (Node-red-node-test-helper)?

Additional, I am not sure about characteristics of the data credentials that must be assigned to test function.

Below is main operation function of my created node.

```auto
function NodeLineNotify(config) {
        RED.nodes.createNode(this, config);
        this.accessToken = this.credentials.token; <--- This line get credential section from input 
        this.message = config.message;
        this.useExternalData = config.useExternalData;
        .... 

```

Below is my test function

```auto
it("error token", (done) => {
        const flow = [
            { 
                id: "n1", 
                type: "node-line-notify", 
                name: "node-line-notify", 
                message: "test", 
                useExternalData: true, 
                useImageUrl: false, 
                useImageFile: false, 
                useSticker: false, 
                wires: [["n2"]] 
            },
            { id: "n2", type: "helper" }
        ];
        helper.load(nodeLineNotify, flow, () => { <--- I am not sure about characteristics credential data for send into this function
            const n1 = helper.getNode("n1");
            const n2 = helper.getNode("n2");

            n1.on("call:error", (err) => {
                should.equal(err.lastArg.status, 401);
                should.equal(err.lastArg.payload, "Invalid access token");
                done();
            });
            n1.receive({ payload: "test" });
        });
    });

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 March 2022 21:51 UTC](https://discourse.nodered.org/t/how-can-i-add-credential-into-my-test-function-node-red-node-test-helper/57429/2 "2022-03-29T21:51:27Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
