1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/test/social/feedparse/32-feedparse_spec.js
2019-10-09 22:35:21 +01:00

74 lines
2.5 KiB
JavaScript

const should = require("should");
const helper = require("node-red-node-test-helper");
const feedParserNode = require("../../../social/feedparser/32-feedparse");
describe("FeedParseNode", () => {
beforeEach(function (done) {
helper.startServer(done);
});
afterEach(function (done) {
helper.unload();
helper.stopServer(done);
});
it("should be loaded", (done) => {
const flow = [{id:"n1", type:"feedparse", interval: 15, url: "test", name: "feedparse" }];
helper.load(feedParserNode, flow, () => {
const n1 = helper.getNode("n1");
n1.should.have.property("name", "feedparse");
done();
});
});
it("get feed", (done) => {
const flow = [
{id:"n1", type:"feedparse", interval: 15, url: "https://discourse.nodered.org/posts.rss", name: "feedparse" , wires:[["n2"]] },
{ id: "n2", type: "helper" }
];
helper.load(feedParserNode, flow, () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
let count = 0;
n2.on("input", (msg) => {
msg.topic.should.startWith("https://discourse.nodered.org/");
if(count === 0){
done();
count++;
}
});
});
});
it("invalid interval", (done) => {
const flow = [
{id:"n1", type:"feedparse", interval: 35791, url: "https://discourse.nodered.org/posts.rss", name: "feedparse" , wires:[["n2"]] },
{ id: "n2", type: "helper" }
];
helper.load(feedParserNode, flow, () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n1.on('call:warn', call => {
call.should.have.property("lastArg", "feedparse.errors.invalidinterval");
done();
});
});
});
it("bad host", (done) => {
const flow = [
{id:"n1", type:"feedparse", interval: 15, url: "https://discourse.nodered.org/dummy.rss", name: "feedparse" , wires:[["n2"]] },
{ id: "n2", type: "helper" }
];
helper.load(feedParserNode, flow, () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n1.on('call:warn', call => {
call.lastArg.should.have.startWith("feedparse.errors.badstatuscode");
done();
});
});
});
});