1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
This commit is contained in:
Dave Conway-Jones 2019-08-11 10:41:44 +01:00
commit bf02668228
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4

View File

@ -0,0 +1,74 @@
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();
});
});
});
});