# How can I initial credential in my created node for node-red-node-test-helper?

**URL:** <https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679>\
**Category:** Developing Nodes\
**Created:** [16 May 2022 08:27 UTC](https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679 "2022-05-16T08:27:42Z")\
**Posts on this page:** 4\
**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:** [16 May 2022 08:27 UTC](https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679/1 "2022-05-16T08:27:42Z")

</div>

Hi all,

I have some problem about initial credential in my created node for node-red-node-test-helper.

i try to follow node-red-node-test-helper help, [node-red/node-red-node-test-helper: A test framework for Node-RED nodes (github.com)](https://github.com/node-red/node-red-node-test-helper#loadtestnode-testflows-testcredentials-cb). But it had remain error.

 ![2022-05-16_151658](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52ee62f688f1a8c1e463c162bbd4f3c99f135226.png)

The error is from my checking in .js file in my created node. If it has not input the credentials, my created node status return -1 value.

![2022-05-16_152048](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/258a2eb1470e03e0d3e8aa5a5df865ad1bc5fddf.png)

Below code is the credentials in node registerType in html file ...

```auto
....
credentials: {
    token: {
        type: "text",
        required: true
    }
},
....

```

Below is the unit test

 ![2022-05-16_152349](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9db85ca5abb80464b6078d3620d831b762894f56.png)

I am not sure, I initiate correct credentials value or not? or Where is my mistake in my code? 🤔

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [16 May 2022 08:43 UTC](https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679/2 "2022-05-16T08:43:52Z")

</div>

You need to include the credentials in the flow itself:

```auto
const flow = [
   {
      id: "n1",
      type: "node-line-notify",
      ...
      credentials: {
         token: "test"
      }
   }
]

```

---

<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:** [16 May 2022 09:30 UTC](https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679/3 "2022-05-16T09:30:34Z")

</div>

Thank you very much for you help. 😊

But the error has remain.

Below is my full unit test file.

```auto
const should = require("should");
const helper = require("node-red-node-test-helper");
const nodeLineNotify = require("../nodes/node-line-notify/node-line-notify.js");

helper.init(require.resolve('node-red'));

describe('Line Notify Node', function () {

    beforeEach((done) => {
        helper.startServer(done);
    });

    afterEach((done) => {
        helper.unload();
        helper.stopServer(done);
    });

    it('should be loaded', (done) => {
        const flow = [{ id: "n1", type: "node-line-notify", name: "node-line-notify", useExternalData: true }];
        helper.load(nodeLineNotify, flow, () => {
            const n1 = helper.getNode("n1");
            try {
                n1.should.have.property("name", "node-line-notify");
                done();
            } catch (err) {
                done(err);
            }
        });
    });

    it("should make payload without token", (done) => {
        const flow = [
            {
                id: "n1",
                type: "node-line-notify",
                name: "node-line-notify",
                message: "test",
                useExternalData: false
            }
        ];
        helper.load(nodeLineNotify, flow, () => {
            const n1 = helper.getNode("n1");
            n1.on("call:error", (err) => {
                should.equal(err.lastArg.payload, "node-line-notify.errors.notFoundToken");
                should.equal(err.lastArg.status, -1);
                done();
            });
            n1.receive({ payload: "test" });
        });
    });

    it("error token", (done) => {
        const flow = [
            {
                id: "n1",
                type: "node-line-notify",
                name: "node-line-notify",
                message: "test",
                useExternalData: false,
                useImageUrl: false,
                useImageFile: false,
                useSticker: false,
                credentials: {
                    token: "test"
                }
            }
        ];
        helper.load(nodeLineNotify, flow, () => {
            const n1 = helper.getNode("n1");
            n1.on("call:error", (err) => {
                console.log(err);
                should.equal(err.lastArg.status, 401);
                should.equal(err.lastArg.payload, "Invalid access token");
                done();
            });
            n1.receive({ payload: "test" });
        });
    });
});

```

I use console.log for display 'err' object. It does not have values credential object. (I am not sure, can I use console.log for debugging)

 ![2022-05-16_162911](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4ab0cfe74025091d6a8c1d59a5e9648e490b104a.png)

---

<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:** [15 July 2022 09:30 UTC](https://discourse.nodered.org/t/how-can-i-initial-credential-in-my-created-node-for-node-red-node-test-helper/62679/4 "2022-07-15T09:30:36Z")

</div>

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