Ajout de test
Fix execution test Quelques renames
This commit is contained in:
parent
f1b1e23792
commit
fa6f1abadb
8
index.js
8
index.js
|
@ -170,3 +170,11 @@ if (process.argv[2] && process.argv[2] === '--service') {
|
|||
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AbstractListenerRSSBuilder: require('./src/Models/Builders/AbstractListenerRSSBuilder'),
|
||||
YoutubeListenerRSSBuilder: require('./src/Models/Builders/YoutubeListenerRSSBuilder'),
|
||||
ListenerRssInfos: require('./src/Models/ListenerRSSInfos'),
|
||||
ListenerBuildDirector: require('./src/ListenerDirector'),
|
||||
ListenerRss: require('./src/ListenerRss')
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const YoutubeListenerRSSBuilder = require('./Models/YoutubeListenerRSSBuilder');
|
||||
|
||||
class ListenerBuildDirector {
|
||||
_builder = undefined;
|
||||
|
||||
|
@ -9,7 +7,7 @@ class ListenerBuildDirector {
|
|||
}
|
||||
|
||||
getListener() {
|
||||
return this._builder.listenerRSS();
|
||||
return this._builder.listenerRSS;
|
||||
}
|
||||
|
||||
build(infos) {
|
|
@ -1,4 +1,3 @@
|
|||
const jsonFile = require('jsonfile');
|
||||
const Parser = require('rss-parser');
|
||||
|
||||
|
||||
|
@ -14,20 +13,29 @@ class ListenerRss {
|
|||
loopRunning = false;
|
||||
|
||||
constructor(info) {
|
||||
if(info !== undefined) {
|
||||
this.setData(info);
|
||||
this.setParser();
|
||||
}
|
||||
}
|
||||
|
||||
setParser() {
|
||||
// set parser
|
||||
this.parser = new Parser({
|
||||
this.parser = new Parser(this.customfields !== undefined ? {
|
||||
customFields: {
|
||||
item: info._customfields.map((elt) => {
|
||||
item: this.customfields.map((elt) => {
|
||||
return Array.isArray(elt[1]) ? elt[1][0] : elt[1];
|
||||
})
|
||||
}
|
||||
});
|
||||
} : undefined); // if customfield is set -> let's set the parser with, else let the option empty
|
||||
}
|
||||
|
||||
setData(infos) {
|
||||
// Set data
|
||||
this.name = info._name === undefined ? info._address : info._name; // if name is undefined let's take the address
|
||||
this.address = info._address;
|
||||
this.timeloop = info._timeloop;
|
||||
this.customfields = info._customfields;
|
||||
this.name = infos._name === undefined ? infos._address : infos._name; // if name is undefined let's take the address
|
||||
this.address = infos._address;
|
||||
this.timeloop = infos._timeloop;
|
||||
this.customfields = infos._customfields;
|
||||
}
|
||||
|
||||
fetchRSS() {
|
|
@ -1,10 +1,10 @@
|
|||
const ListenerRSS = require('../listener-rss');
|
||||
const ListenerRSS = require('../../ListenerRss')
|
||||
|
||||
class AbstractListnerRSSBuilder {
|
||||
class AbstractListenerRSSBuilder {
|
||||
_listenerRSS = undefined;
|
||||
|
||||
constructor() {
|
||||
if(this.constructor === AbstractListnerRSSBuilder)
|
||||
if(this.constructor === AbstractListenerRSSBuilder)
|
||||
throw new Error('The Abstract class "AbstractListnerRSSBuilder" cannot be instantiated');
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ class AbstractListnerRSSBuilder {
|
|||
|
||||
this.setInfos(infos);
|
||||
this.setSpecificInfos();
|
||||
this.listenerRSS.setParser()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,10 +32,7 @@ class AbstractListnerRSSBuilder {
|
|||
}
|
||||
|
||||
setInfos(infos) { // Nominal Infos (like name, addresse, and other)
|
||||
this._listenerRSS.name = infos._name;
|
||||
this._listenerRSS.address = infos._address;
|
||||
this._listenerRSS.timeloop = infos._timeloop;
|
||||
this._listenerRSS.name = infos._name;
|
||||
this._listenerRSS.setData(infos);
|
||||
}
|
||||
|
||||
setSpecificInfos() { // More generic infos who's depend of platforms
|
||||
|
@ -44,4 +42,4 @@ class AbstractListnerRSSBuilder {
|
|||
|
||||
}
|
||||
|
||||
module.exports = AbstractListnerRSSBuilder
|
||||
module.exports = AbstractListenerRSSBuilder
|
|
@ -1,4 +1,4 @@
|
|||
const AbstractListenerRSSBuilder = require('AbstractListenerRSSBuilder')
|
||||
const AbstractListenerRSSBuilder = require('./AbstractListenerRSSBuilder');
|
||||
|
||||
class YoutubeListenerRSSBuilder extends AbstractListenerRSSBuilder {
|
||||
constructor() {
|
||||
|
@ -6,7 +6,7 @@ class YoutubeListenerRSSBuilder extends AbstractListenerRSSBuilder {
|
|||
}
|
||||
|
||||
setSpecificInfos() {
|
||||
this.listenerRSS._customfields = [
|
||||
this.listenerRSS.customfields = [
|
||||
['description', ['media:group', 'media:description']],
|
||||
['icon', ['media:group', 'media:thumbnail']]
|
||||
]
|
||||
|
|
|
@ -39,4 +39,4 @@ class ListenerRSSInfos {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = ListenerRSSInfos
|
||||
module.exports = ListenerRSSInfos;
|
|
@ -1,13 +1,20 @@
|
|||
// 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 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;
|
||||
|
@ -58,11 +65,11 @@ describe("test class RSS: jsonfile", function () {
|
|||
beforeEach(function () {
|
||||
// stubs
|
||||
stubParser = sinon.stub(Parser.prototype, 'parseURL')
|
||||
.withArgs(listenerInfo.address)
|
||||
.withArgs(infosListener.address)
|
||||
.resolves(mockedRSSOutput);
|
||||
|
||||
// constructor
|
||||
myListener = new Listeners();
|
||||
myListener = undefined;
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -71,27 +78,44 @@ describe("test class RSS: jsonfile", function () {
|
|||
});
|
||||
|
||||
describe("Building Ytb listener", function () {
|
||||
it("The build without problems", function () {
|
||||
it("The build without issues", function () {
|
||||
let builder = new YtbBuilder();
|
||||
let director = new YtbDirector(builder);
|
||||
let director = new Director(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([
|
||||
// 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']]
|
||||
]);
|
||||
//TODO test les infos dans "myListener"
|
||||
});
|
||||
});
|
||||
|
||||
//Todo
|
||||
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(listenerInfo);
|
||||
myListener.setDatas(infosListener);
|
||||
myListener.start();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user