// external lib const Parser = require("rss-parser"); // tested class const ListenerRssPackage = require("../index"); const Listeners = ListenerRssPackage.ListenerRss const ListenerRRSInfo = ListenerRssPackage.ListenerRssInfos const YtbBuilder = ListenerRssPackage.YoutubeListenerRSSBuilder const Director = ListenerRssPackage.ListenerBuildDirector // Unit test const chai = require("chai"); const sinon = require("sinon"); const sinon_chai = require("sinon-chai"); chai.use(sinon_chai); const expect = chai.expect; describe("test class RSS: jsonfile", function () { let myListener = undefined; let infosListener = new ListenerRRSInfo(); infosListener.name = 'my-test-service'; infosListener.address = 'fake.rss.service'; infosListener.timeloop = 15; // parseURL tests let stubParser; const mockedRSSOutput = { items: [ { 'title': 'my title 00', 'media:group': { 'media:description': 'my description 00', 'media:thumbnail': [{$: {height: 360, width: 420, url: 'my_image00.jpg'}}], }, 'link': 'my_url_00.com', 'pubDate': 'myDate00' }, { 'title': 'my title 01', 'media:group' : { 'media:description': 'my description 01', 'media:thumbnail': [{$: { height: 360, width: 420, url: 'my_image01.jpg'}}], }, 'link': 'my_url_01.com', 'pubDate': 'myDate01' }, { 'title': 'my title 02', 'media:group' : { 'media:description': 'my description 02', 'media:thumbnail': [{$: { height: 360, width: 420, url: 'my_image02.jpg'}}], }, 'link': 'my_url_02.com', 'pubDate': 'myDate02' }, ] }; beforeEach(function () { // stubs stubParser = sinon.stub(Parser.prototype, 'parseURL') .withArgs(infosListener.address) .resolves(mockedRSSOutput); // constructor myListener = undefined; }) afterEach(function () { // restore stubs Parser.prototype.parseURL.restore(); }); describe("Building Ytb listener", function () { it("The build without issues", function () { let builder = new YtbBuilder(); let director = new Director(builder); director.build(infosListener); myListener = director.getListener(); // assertions // myListener data expect(myListener.timeloop).to.eql(infosListener._timeloop); expect(myListener.name).to.eql(infosListener._name) expect(myListener.address).to.eql(infosListener._address) expect(myListener.customfields).to.eql([ ['description', ['media:group', 'media:description']], ['icon', ['media:group', 'media:thumbnail']] ]); }); }); describe("fetch some data", function () { it("fetch without issues", function () { // classic build let builder = new YtbBuilder(); let director = new Director(builder); director.build(infosListener); myListener = director.getListener(); // fetch myListener.fetchRSS(); //assertion // calls expect(stubParser).to.have.been.calledOnce; expect(stubParser).to.have.been.calledWith(infosListener._address); }) }) describe.skip("start", function () { it("Let's start the timer", function () { myListener.setDatas(infosListener); myListener.start(); }); }); });