Remove name field adding lastentries parameter and give the new entries for the first update
This commit is contained in:
parent
f919726e4d
commit
ce1d8f4ab6
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
export { ListenerRss } from "./listener-rss";
|
||||
export { ListenerRSSInfos } from "./Models/ListenerRSSInfos";
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user