mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
slight tidy of YAML PR (remove excess console.log in test)
and improve XML test coverage slightly
This commit is contained in:
parent
9bbc8eda9d
commit
d63996eea1
@ -36,8 +36,8 @@
|
||||
<option value="javascript">Javascript</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="markdown">Markdown</option>
|
||||
<option value="text">none</option>
|
||||
<option value="yaml">YAML</option>
|
||||
<option value="text">none</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="yaml">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var yaml = require('js-yaml');
|
||||
|
@ -57,6 +57,26 @@ describe('XML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a valid xml string to a javascript object with options', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(xmlNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 'bar');
|
||||
msg.payload.should.have.property('employees');
|
||||
msg.payload.employees.should.have.property('firstName');
|
||||
should.equal(msg.payload.employees.firstName[0], 'John');
|
||||
msg.payload.employees.should.have.property('lastName');
|
||||
should.equal(msg.payload.employees.lastName[0], 'Smith');
|
||||
done();
|
||||
});
|
||||
var string = '<employees><firstName>John</firstName><lastName>Smith</lastName></employees>';
|
||||
n1.receive({payload:string, topic:"bar", options:{trim:true}});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a javascript object to an xml string', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
@ -74,6 +94,23 @@ describe('XML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a javascript object to an xml string with options', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(xmlNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 'bar');
|
||||
var index = msg.payload.indexOf('<employees>\n <firstName>John</firstName>\n <lastName>Smith</lastName>\n</employees>');
|
||||
index.should.be.above(-1);
|
||||
done();
|
||||
});
|
||||
var obj = {"employees":{"firstName":["John"],"lastName":["Smith"] }};
|
||||
n1.receive({payload:obj, topic:"bar", options:{headless:true}});
|
||||
});
|
||||
});
|
||||
|
||||
it('should log an error if asked to parse an invalid xml string', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
@ -89,7 +126,6 @@ describe('XML node', function() {
|
||||
logEvents.should.have.length(1);
|
||||
logEvents[0][0].should.have.a.property('msg');
|
||||
logEvents[0][0].msg.toString().should.startWith("Error: Attribute without value");
|
||||
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
|
@ -44,8 +44,6 @@ describe('YAML node', function() {
|
||||
var yn1 = helper.getNode("yn1");
|
||||
var yn2 = helper.getNode("yn2");
|
||||
yn2.on("input", function(msg) {
|
||||
console.log('msg', msg);
|
||||
console.log('payload', msg.payload.employees[0]);
|
||||
msg.should.have.property('topic', 'bar');
|
||||
msg.payload.should.have.property('employees');
|
||||
msg.payload.employees[0].should.have.property('firstName', 'John');
|
||||
|
Loading…
Reference in New Issue
Block a user