Adding getProperty to export the ListenerRSS properties + related tests

This commit is contained in:
Amaury Joly 2021-03-28 13:22:55 +02:00
parent 271f445aef
commit c02df46440
2 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,8 @@
import Parser from "rss-parser";
import { ListenerRSSInfos as ListenerInfo } from "./Models/ListenerRSSInfos";
import {
ListenerRSSInfos as ListenerInfo,
ListenerRSSInfos,
} from "./Models/ListenerRSSInfos";
import EventEmitter from "events";
const DEFAULT_TIMELOOP: number = 5 * 60; // default timeloop is 5 min
@ -10,7 +13,6 @@ const DEFAULT_TIMELOOP: number = 5 * 60; // default timeloop is 5 min
* Emit 'newEntries' when the fetch has new entris
*/
export class ListenerRss extends EventEmitter {
name: string = "";
address: string = "";
timeloop: number = DEFAULT_TIMELOOP; // time in seconds
customfields?: { [key: string]: string[] | string };
@ -103,4 +105,17 @@ export class ListenerRss extends EventEmitter {
stop(): void {
this.loopRunning = false;
}
/**
* @brief parse the datas inti a ListenerRSSInfos object
* @return return a ListenerRSSInfos object
*/
getProperty(): ListenerRSSInfos {
return {
address: this.address,
customfields: this.customfields,
lastEntriesLinks: this.lastEntriesLinks,
timeloop: this.timeloop,
};
}
}

View File

@ -195,6 +195,16 @@ describe("test class RSS: jsonfile", function () {
});
});
describe("export property", function () {
it("should export properties into a ListenerRSSInfos", function () {
// given
const myListener = new Listeners(infosListener);
// assertions
expect(myListener.getProperty()).to.be.eql(infosListener);
});
});
describe("data fetching", function () {
it("fetches without issues", async function () {
// given