Update packages version
Add first test Add design pattern builder + Youtube builder
This commit is contained in:
@ -1,59 +1,100 @@
|
||||
const chai = require("chai");
|
||||
const sinon = require("sinon");
|
||||
const proxyquire = require("proxyquire");
|
||||
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("RSS Youtube", function () {
|
||||
let rssYoutubeService;
|
||||
let timecode;
|
||||
let routage;
|
||||
let parseUrlStub;
|
||||
let mockedInput = {
|
||||
items: [
|
||||
{
|
||||
id: "::account",
|
||||
url:
|
||||
isoDate: Date.now().toISOString(),
|
||||
"media:group": {
|
||||
"media:description": [
|
||||
"my description"
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
describe("test class RSS: jsonfile", function () {
|
||||
let myListener = undefined;
|
||||
|
||||
beforeEach(function () {
|
||||
timecode = {
|
||||
"lastCheck": "2020-11-12T17:44:11.713Z",
|
||||
"MyUser": "2020-11-12T17:44:11.713Z"
|
||||
};
|
||||
routage = {
|
||||
log: sinon.stub(),
|
||||
send: sinon.stub()
|
||||
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'
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
parseUrlStub = sinon.stub(Parser.prototype, "parseURL")
|
||||
.callsFake((_, callback) => callback(null, "data"));
|
||||
beforeEach(function () {
|
||||
// stubs
|
||||
stubParser = sinon.stub(Parser.prototype, 'parseURL')
|
||||
.withArgs(listenerInfo.address)
|
||||
.resolves(mockedRSSOutput);
|
||||
|
||||
rssYoutubeService = proxyquire("../services/rss-youtube", {
|
||||
"../modules/routage": () => routage,
|
||||
"../db/rss-youtube.json": {
|
||||
config: {
|
||||
timeLoop: 5,
|
||||
urlFeeds: "https://www.youtube.com/feeds/videos.xml?channel_id=",
|
||||
sliceDescription: 142
|
||||
},
|
||||
feeds: {
|
||||
MyUser: "Some channel"
|
||||
},
|
||||
timecode
|
||||
}
|
||||
// constructor
|
||||
myListener = new Listeners();
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
// restore stubs
|
||||
Parser.prototype.parseURL.restore();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Parser.prototype.parseURL.reset();
|
||||
});
|
||||
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();
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user