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