2020-12-20 18:53:35 +01:00
|
|
|
const chai = require("chai");
|
|
|
|
const sinon = require("sinon");
|
2021-01-19 13:12:44 +01:00
|
|
|
const sinon_chai = require("sinon-chai");
|
|
|
|
chai.use(sinon_chai);
|
2020-12-20 18:53:35 +01:00
|
|
|
const Parser = require("rss-parser");
|
|
|
|
|
2021-01-19 13:12:44 +01:00
|
|
|
const Listeners = require('../src/listener-rss')
|
|
|
|
const ListenerRRSInfo = require('../src/Models/listenerRSSInfos')
|
|
|
|
const YtbBuilder = require('../src/Models/YoutubeListenerRSSBuilder')
|
|
|
|
const YtbDirector = require('../src/listener-director')
|
|
|
|
|
|
|
|
|
2020-12-20 18:53:35 +01:00
|
|
|
const expect = chai.expect;
|
|
|
|
|
2021-01-19 13:12:44 +01:00
|
|
|
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'
|
|
|
|
},
|
|
|
|
]
|
2020-12-20 18:53:35 +01:00
|
|
|
};
|
|
|
|
|
2021-01-19 13:12:44 +01:00
|
|
|
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"
|
|
|
|
});
|
2020-12-20 18:53:35 +01:00
|
|
|
});
|
|
|
|
|
2021-01-19 13:12:44 +01:00
|
|
|
//Todo
|
|
|
|
describe.skip("start", function () {
|
|
|
|
it("Let's start the timer", function () {
|
|
|
|
myListener.setDatas(listenerInfo);
|
|
|
|
myListener.start();
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2020-12-20 18:53:35 +01:00
|
|
|
});
|