From ce1d8f4ab6828ccc0243000bd1c9175e1285400c Mon Sep 17 00:00:00 2001 From: Amaury Joly Date: Sun, 21 Mar 2021 21:35:22 +0100 Subject: [PATCH] Remove name field adding lastentries parameter and give the new entries for the first update --- src/Models/ListenerRSSInfos.ts | 2 +- src/index.ts | 2 -- src/listener-rss.ts | 5 +++-- tests/index-spec.ts | 17 +++-------------- 4 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 src/index.ts diff --git a/src/Models/ListenerRSSInfos.ts b/src/Models/ListenerRSSInfos.ts index 6e8a26f..dfbe635 100644 --- a/src/Models/ListenerRSSInfos.ts +++ b/src/Models/ListenerRSSInfos.ts @@ -1,6 +1,6 @@ export interface ListenerRSSInfos { - readonly name: string; // name of the listener readonly address: string; // feed's address readonly timeloop?: number; // update time RSS feed readonly customfields?: { [key: string]: string | string[] }; // rss fields custom + readonly lastEntriesLinks?: [string]; // links from lastentries } diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 4046865..0000000 --- a/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { ListenerRss } from "./listener-rss"; -export { ListenerRSSInfos } from "./Models/ListenerRSSInfos"; diff --git a/src/listener-rss.ts b/src/listener-rss.ts index fab200b..1d48aae 100644 --- a/src/listener-rss.ts +++ b/src/listener-rss.ts @@ -27,11 +27,12 @@ export class ListenerRss extends EventEmitter { constructor(config: ListenerInfo) { super(); - this.name = config.name; this.address = config.address; this.timeloop = config.timeloop === undefined ? DEFAULT_TIMELOOP : config.timeloop; this.customfields = config.customfields; + this.lastEntriesLinks = + config.lastEntriesLinks === undefined ? [] : config.lastEntriesLinks; this.parser = this.generateParser(); } @@ -78,7 +79,7 @@ export class ListenerRss extends EventEmitter { !this.lastEntriesLinks.includes(item.link) ); - if (this.lastEntriesLinks.length !== 0 && newEntries.length !== 0) { + if (newEntries.length !== 0) { this.emit("newEntries", newEntries); } this.lastEntriesLinks = updatedEntriesLinks; diff --git a/tests/index-spec.ts b/tests/index-spec.ts index 9abc0f4..ee07fc0 100644 --- a/tests/index-spec.ts +++ b/tests/index-spec.ts @@ -5,7 +5,7 @@ import * as Parser from "rss-parser"; import { ListenerRSSInfos as ListenerRRSInfo, ListenerRss as Listeners, -} from "./../src/index"; +} from "../"; // Unit test import assert from "assert"; @@ -20,7 +20,6 @@ const expect = chai.expect; describe("test class RSS: jsonfile", function () { const infosListener: ListenerRRSInfo = { - name: "my-test-service", address: "fake.rss.service", timeloop: 15, customfields: { @@ -74,7 +73,6 @@ describe("test class RSS: jsonfile", function () { // assertions // myListener data expect(myListener.timeloop).to.eql(15); - expect(myListener.name).to.eql("my-test-service"); expect(myListener.address).to.eql("fake.rss.service"); expect(myListener.customfields).to.eql({ description: ["media:group", "media:description"], @@ -91,7 +89,6 @@ describe("test class RSS: jsonfile", function () { it("builds without issues (raw infos : 4 params)", function () { const myListener = new Listeners({ - name: "my-test-service", address: "fake.rss.service", timeloop: 15, customfields: { @@ -103,7 +100,6 @@ describe("test class RSS: jsonfile", function () { // assertions // myListener data expect(myListener.timeloop).to.eql(15); - expect(myListener.name).to.eql("my-test-service"); expect(myListener.address).to.eql("fake.rss.service"); expect(myListener.customfields).to.eql({ description: ["media:group", "media:description"], @@ -120,14 +116,12 @@ describe("test class RSS: jsonfile", function () { it("builds without issues (raw infos : just 2 params)", function () { const myListener = new Listeners({ - name: "my-test-service", address: "fake.rss.service", }); // assertions // myListener data expect(myListener.timeloop).to.eql(5 * 60); - expect(myListener.name).to.eql("my-test-service"); expect(myListener.address).to.eql("fake.rss.service"); expect(myListener.customfields).to.eql(undefined); expect(myListener.parser) @@ -142,7 +136,6 @@ describe("test class RSS: jsonfile", function () { it("builds without issues (raw infos: just 3 params (no custom fields))", function () { const myListener = new Listeners({ - name: "my-test-service", address: "fake.rss.service", timeloop: 15, }); @@ -150,7 +143,6 @@ describe("test class RSS: jsonfile", function () { // assertions // myListener data expect(myListener.timeloop).to.eql(15); - expect(myListener.name).to.eql("my-test-service"); expect(myListener.address).to.eql("fake.rss.service"); expect(myListener.customfields).to.eql(undefined); expect(myListener.parser) @@ -164,7 +156,6 @@ describe("test class RSS: jsonfile", function () { it("The build without issues (raw infos : just 3 params (no timeloop))", function () { const myListener = new Listeners({ - name: "my-test-service", address: "fake.rss.service", customfields: { description: ["media:group", "media:description"], @@ -175,7 +166,6 @@ describe("test class RSS: jsonfile", function () { // assertions // myListener data expect(myListener.timeloop).to.eql(5 * 60); - expect(myListener.name).to.eql("my-test-service"); expect(myListener.address).to.eql("fake.rss.service"); expect(myListener.customfields).to.eql({ description: ["media:group", "media:description"], @@ -220,7 +210,6 @@ describe("test class RSS: jsonfile", function () { stubParser.rejects(err); const myListener = new Listeners({ - name: "my-test-service", address: "bad.rss.service", customfields: { description: ["media:group", "media:description"], @@ -409,7 +398,7 @@ describe("test class RSS: jsonfile", function () { // then await clock.tickAsync(1); expect(updateListenerSpy).to.have.been.calledOnce; - expect(newEntriesListenerSpy).to.not.have.been.called; + expect(newEntriesListenerSpy).to.have.been.calledOnce; // given stubParser.resolves(newRSSOutput); @@ -417,7 +406,7 @@ describe("test class RSS: jsonfile", function () { // then await clock.tickAsync(60000); expect(updateListenerSpy).to.have.been.calledTwice; - expect(newEntriesListenerSpy).to.have.been.calledOnce; + expect(newEntriesListenerSpy).to.have.been.calledTwice; expect(newEntriesListenerSpy).to.have.been.calledWith([newEntry]); // given