Starting unit testing (hard work)

This commit is contained in:
Florent 2020-12-20 18:53:35 +01:00 committed by Florent F
parent 0b8719e262
commit bf55adf8da
4 changed files with 889 additions and 2 deletions

818
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"scripts": {
"start": "node index.js",
"service": "node index.js --service",
"stop": "node index.js stop"
"stop": "node index.js stop",
"test": "mocha tests/*-spec.js"
},
"author": "Ju [kataku] / Skeptikon",
"dependencies": {
@ -18,5 +19,11 @@
"lodash": "^4.17.15",
"pm2": "^4.2.3",
"rss-parser": "^3.7.5"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1",
"proxyquire": "^2.1.3",
"sinon": "^9.2.2"
}
}

View File

@ -88,4 +88,7 @@ function rssLoop(time) {
// INIT
console.log(` --- [RSS-Youtube] Load`)
routage.log(`Load`)
rssLoop(db.config.timeLoop*60*1000)
// rssLoop(db.config.timeLoop*60*1000)
module.exports = {
rssLoop
};

59
tests/rss-youtube-spec.js Normal file
View File

@ -0,0 +1,59 @@
const chai = require("chai");
const sinon = require("sinon");
const proxyquire = require("proxyquire");
const Parser = require("rss-parser");
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"
]
}
]
};
beforeEach(function () {
timecode = {
"lastCheck": "2020-11-12T17:44:11.713Z",
"MyUser": "2020-11-12T17:44:11.713Z"
};
routage = {
log: sinon.stub(),
send: sinon.stub()
};
parseUrlStub = sinon.stub(Parser.prototype, "parseURL")
.callsFake((_, callback) => callback(null, "data"));
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
}
});
});
afterEach(function () {
Parser.prototype.parseURL.reset();
});
});