mirror of
https://github.com/yuto-yuto/node-red-contrib-password-generator.git
synced 2026-03-04 02:17:22 +01:00
Implement
This commit is contained in:
57
test/PasswordGeneratorNode_spec.ts
Normal file
57
test/PasswordGeneratorNode_spec.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import "mocha";
|
||||
import { expect } from "chai";
|
||||
// import * as helper from "node-red-node-test-helper";
|
||||
import helper = require("node-red-node-test-helper");
|
||||
|
||||
import valueChangeNode = require("../lib/PasswordGeneratorNode");
|
||||
|
||||
describe("PasswordGeneratorNode", () => {
|
||||
before(() => {
|
||||
helper.init(require.resolve('node-red'));
|
||||
});
|
||||
|
||||
beforeEach((done) => {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
afterEach((done) => {
|
||||
helper.unload().then(() => helper.stopServer(done));
|
||||
});
|
||||
|
||||
const nodeId = "node-id";
|
||||
const outNodeId = "out-node-id";
|
||||
const flows = [
|
||||
{
|
||||
id: nodeId,
|
||||
type: "password-generator",
|
||||
size: 10,
|
||||
setTo: "payload.value",
|
||||
name: "generator-name",
|
||||
wires: [[outNodeId]]
|
||||
},
|
||||
{
|
||||
id: outNodeId,
|
||||
type: "helper",
|
||||
}
|
||||
];
|
||||
|
||||
it("should be loaded", (done) => {
|
||||
helper.load([valueChangeNode], flows, () => {
|
||||
const node = helper.getNode(nodeId);
|
||||
expect(node.name).to.equal("generator-name");
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
it("should set value to the property specified in setTo", (done) => {
|
||||
helper.load([valueChangeNode], flows, () => {
|
||||
const node = helper.getNode(nodeId);
|
||||
const outNode = helper.getNode(outNodeId);
|
||||
outNode.on("input", (msg: any) => {
|
||||
expect(msg.payload.value).not.to.be.undefined;
|
||||
done();
|
||||
});
|
||||
node.receive({ payload: 1 });
|
||||
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
11
test/PasswordGenerator_spec.ts
Normal file
11
test/PasswordGenerator_spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import "mocha";
|
||||
import { expect } from "chai";
|
||||
import { generatePassword } from "../lib/PasswordGenerator";
|
||||
|
||||
describe.only("PasswordGenerator", () => {
|
||||
it("should return true for the first time", async () => {
|
||||
const result = await generatePassword(10);
|
||||
console.log(`before: "${result}"`)
|
||||
expect(result).to.lengthOf(10);
|
||||
});
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
import "mocha";
|
||||
import { expect } from "chai";
|
||||
import { ValueChangeDetector } from "../lib/ValueChangeDetector";
|
||||
|
||||
describe("ValueChangeDetector", () => {
|
||||
let instance: ValueChangeDetector;
|
||||
|
||||
beforeEach(() => {
|
||||
instance = new ValueChangeDetector();
|
||||
});
|
||||
|
||||
describe("isUpdated", () => {
|
||||
it("should return true for the first time", () => {
|
||||
const result = instance.isUpdated({ key: 1, value: 1 });
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
it("should return false when specifying the same data", () => {
|
||||
const data = { key: "key", value: "value" };
|
||||
instance.update(data);
|
||||
const result = instance.isUpdated({ ...data });
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
|
||||
it("should return true for different key", () => {
|
||||
instance.update({ key: "key", value: "value" });
|
||||
const result = instance.isUpdated({ key: "key2", value: "value" });
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
it("should convert number to string for key", () => {
|
||||
instance.update({ key: 1, value: "value" });
|
||||
const result = instance.isUpdated({ key: "1", value: "value" });
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
|
||||
it("should convert object to string for key", () => {
|
||||
instance.update({ key: { obj: 1 }, value: "value" });
|
||||
const result = instance.isUpdated({ key: { obj: 1 }, value: "value" });
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user