const chai = require("chai"); const sinon = require("sinon"); const sinon_chai = require("sinon-chai"); chai.use(sinon_chai); const Parser = require("rss-parser"); const Listeners = require('../src/listener-rss') const ListenerRRSInfo = require('../src/Models/listenerRSSInfos') const YtbBuilder = require('../src/Models/YoutubeListenerRSSBuilder') const YtbDirector = require('../src/listener-director') 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(listenerInfo.address) .resolves(mockedRSSOutput); // constructor myListener = new Listeners(); }) afterEach(function () { // restore stubs Parser.prototype.parseURL.restore(); }); describe("Building Ytb listener", function () { it("The build without problems", function () { let builder = new YtbBuilder(); let director = new YtbDirector(builder); director.build(infosListener); myListener = director.getListener(); // assertions expect(stubParser).to.have.been.calledOnce; expect(stubParser).to.have.been.calledWith(infosListener._address); expect(myListener.customFields).to.eql([ ['description', ['media:group', 'media:description']], ['icon', ['media:group', 'media:thumbnail']] ]); //TODO test les infos dans "myListener" }); }); //Todo describe.skip("start", function () { it("Let's start the timer", function () { myListener.setDatas(listenerInfo); myListener.start(); }); }); });