From c02df464403828098994c4bc8d59e9e910e17c91 Mon Sep 17 00:00:00 2001 From: Amaury Joly Date: Sun, 28 Mar 2021 13:22:55 +0200 Subject: [PATCH] Adding getProperty to export the ListenerRSS properties + related tests --- src/listener-rss.ts | 19 +++++++++++++++++-- tests/index-spec.ts | 10 ++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/listener-rss.ts b/src/listener-rss.ts index f72011c..db49208 100644 --- a/src/listener-rss.ts +++ b/src/listener-rss.ts @@ -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, + }; + } } diff --git a/tests/index-spec.ts b/tests/index-spec.ts index 279d156..8ddef98 100644 --- a/tests/index-spec.ts +++ b/tests/index-spec.ts @@ -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