Change signature of customFields and make ListenerRSSInfos properties ro

This commit is contained in:
Florent 2021-02-14 17:37:03 +01:00 committed by Florent F
parent f8c9eb7d35
commit 5c430b61b1
3 changed files with 37 additions and 41 deletions

View File

@ -1,6 +1,6 @@
export interface ListenerRSSInfos {
name: string; // name of the listener
address: string; // feed's address
timeloop?: number; // update time RSS feed
customfields?: [string, string | [string, string]][]; // rss fields custom
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
}

View File

@ -7,7 +7,7 @@ export class ListenerRss {
name: string = "";
address: string = "";
timeloop: number = DEFAULT_TIMELOOP; // time in seconds
customfields?: [string, string | [string, string]][];
customfields?: { [key: string]: string[] | string };
// private fields
parser: Parser | undefined = undefined;
@ -24,8 +24,8 @@ export class ListenerRss {
this.customfields !== undefined
? {
customFields: {
item: this.customfields.map((elt) => {
return Array.isArray(elt[1]) ? elt[1][0] : elt[1];
item: Object.entries(this.customfields).map(([, value]) => {
return Array.isArray(value[1]) ? value[1][0] : value[1];
}),
},
}
@ -39,8 +39,7 @@ export class ListenerRss {
this.address = infos.address;
this.timeloop =
infos.timeloop === undefined ? DEFAULT_TIMELOOP : infos.timeloop;
this.customfields =
infos.customfields === undefined ? undefined : infos.customfields;
this.customfields = infos.customfields;
}
fetchRSS(): any {

View File

@ -25,10 +25,10 @@ describe("test class RSS: jsonfile", function () {
name: "my-test-service",
address: "fake.rss.service",
timeloop: 15,
customfields: [
["description", ["media:group", "media:description"]],
["icon", ["media:group", "media:thumbnail"]],
],
customfields: {
description: ["media:group", "media:description"],
icon: ["media:group", "media:thumbnail"],
},
};
// parseURL tests
@ -101,10 +101,10 @@ describe("test class RSS: jsonfile", function () {
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"]],
["icon", ["media:group", "media:thumbnail"]],
]);
expect(myListener.customfields).to.eql({
description: ["media:group", "media:description"],
icon: ["media:group", "media:thumbnail"],
});
/* // TODO test des champs dans l'objet parser
expect(myListener.parser.options.customFields).to.eql({
feed: [],
@ -112,20 +112,18 @@ describe("test class RSS: jsonfile", function () {
});*/
});
// it("The build without issues (raw infos : 4 params)", function () {
// myListener = new Listeners("my-test-service", "fake.rss.service", 15, [
// ["description", ["media:group", "media:description"]],
// ["icon", ["media:group", "media:thumbnail"]],
// ]);
// myListener = new Listeners("my-test-service", "fake.rss.service", 15, { // description: ["media:group", "media:description"],
// icon: ["media:group", "media:thumbnail"],
// });
//
// // 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"]],
// ["icon", ["media:group", "media:thumbnail"]],
// ]);
// expect(myListener.customfields).to.eql({ // description: ["media:group", "media:description"],
// icon: ["media:group", "media:thumbnail"],
// });
// /*
// expect(myListener.parser.options.customFields).to.eql({
// feed: [],
@ -167,10 +165,9 @@ describe("test class RSS: jsonfile", function () {
// "my-test-service",
// "fake.rss.service",
// undefined,
// [
// ["description", ["media:group", "media:description"]],
// ["icon", ["media:group", "media:thumbnail"]],
// ]
// { // description: ["media:group", "media:description"],
// icon: ["media:group", "media:thumbnail"],
// }
// );
//
// // assertions
@ -218,10 +215,10 @@ describe("test class RSS: jsonfile", function () {
myListener = new Listeners({
name: "my-test-service",
address: "bad.rss.service",
customfields: [
["description", ["media:group", "media:description"]],
["icon", ["media:group", "media:thumbnail"]],
],
customfields: {
description: ["media:group", "media:description"],
icon: ["media:group", "media:thumbnail"],
},
});
myListener.parser = stubParser; // replace the parser by my fake parser
// fetch
@ -249,10 +246,10 @@ describe("test class RSS: jsonfile", function () {
name: "my-test-service",
address: "fake.rss.service",
timeloop: 2,
customfields: [
["description", ["media:group", "media:description"]],
["icon", ["media:group", "media:thumbnail"]],
],
customfields: {
description: ["media:group", "media:description"],
icon: ["media:group", "media:thumbnail"],
},
});
//spy
@ -280,10 +277,10 @@ describe("test class RSS: jsonfile", function () {
name: "my-test-service",
address: "fake.rss.service",
timeloop: 2,
customfields: [
["description", ["media:group", "media:description"]],
["icon", ["media:group", "media:thumbnail"]],
],
customfields: {
description: ["media:group", "media:description"],
icon: ["media:group", "media:thumbnail"],
},
});
//spy