Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
helper.load(sentimentNode, flow, () => {
// At this point the flow is "running". We now need to send in some data.
const n1 = helper.getNode("n1");
const n2 = helper.getNode("n2");
n2.on('input', (msg) => {
msg.sentiment.score.should.be.above(0.5);
done();
});
n1.receive({payload: "This is great!"});
});
});
helper.load(sentimentNode, flow, () => {
// At this point the flow is "running". We now need to send in some data.
const n1 = helper.getNode("n1");
const n2 = helper.getNode("n2");
n2.on('input', (msg) => {
msg.sentiment.score.should.be.above(0.5);
done();
});
n1.receive({payload: "This is great!"});
});
});
helper.load(pubsubInNode, flow, () => {
// At this point the flow is "running". We now need to send in some data.
const n1 = helper.getNode("n1");
const n2 = helper.getNode("n2");
const text = "Hello World!"; // The message we publish which should be received by the flow.
n2.on('input', (msg) => {
msg.should.have.property('payload'); // Check that we have msg.payload
msg.should.have.property('message'); // Check that we have msg.message
msg.payload.toString().should.be.equal(text);
done();
});
// Publish a message using the API which should now wake us up.
const topic = pubsub.topic('node-red-topic');
topic.publish(Buffer.from(text));
});
});
it('should be loaded (link in)', function(done) {
var flow = [{id:"n1", type:"link in", name: "link-in" }];
helper.load(linkNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('name', 'link-in');
done();
});
});
it('should be loaded', function(done) {
var flow = [{id:"htmlNode1", type:"html", name: "htmlNode" }];
helper.load(htmlNode, flow, function() {
var htmlNode1 = helper.getNode("htmlNode1");
htmlNode1.should.have.property('name', 'htmlNode');
done();
});
});
it('should be loaded with any defaults', function(done) {
var flow = [{id:"n1", type:"exec", name: "exec1"}];
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property("name", "exec1");
n1.should.have.property("cmd", "");
n1.should.have.property("append", "");
n1.should.have.property("addpay",true);
n1.should.have.property("timer",0);
n1.should.have.property("oldrc","false");
done();
});
});
it('should be loaded', function(done) {
var flow = [{id:"n1", type:"unknown", name: "unknown" }];
helper.load(unknown, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('name', 'unknown');
done();
});
});
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.a.property("payload");
msg.payload.should.be.a.Object;
msg.payload.should.have.length(43);
buf = msg.payload;
done();
});
n1.emit("input", {payload:{A:1, B:"string", C:true, D:[1,true,"string"], E:{Y:9,Z:"string"}}});
});
});
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload");
msg.payload.should.be.approximately(0,3);
msg.payload.toString().indexOf(".").should.equal(-1);
done();
}
});
n1.emit("input", {payload:"a"});
});
});
afterEach(function(done) {
helper.unload().then(function() {
helper.stopServer(done);
});
});