Added editConfig Function

This commit is contained in:
Amaury 2021-07-12 13:49:02 +02:00
parent 14b2df7bdc
commit b0811ea505
2 changed files with 16 additions and 7 deletions

View File

@ -63,26 +63,35 @@ export class ListenerRssAggregator extends EventEmitter {
return await ListenerRssAggregator.extractConfig(this.sqliteDb);
}
async editConfig(
callback: (config: ListenerRss.Config[]) => ListenerRss.Config[]
): Promise<void> {
this.stopAll();
const actualConfig = await this.getAllConfigs();
this.saveOverride(callback(actualConfig));
this.startAll();
}
private addNewListener(info: ListenerRss.Config): ListenerRss {
const newListener = new ListenerRss(info);
this.listenerMap.set(newListener.address, newListener);
newListener.on("update", (obj) =>
this.emit("update", {
...obj,
...{ addressListener: newListener.address },
items: obj,
addressListener: newListener.address,
})
);
newListener.on("newEntries", (obj) =>
this.emit("newEntries", {
...obj,
...{ addressListener: newListener.address },
items: obj,
addressListener: newListener.address,
})
);
newListener.on("error", (err) =>
this.emit("error", {
...err,
...{ addressListener: newListener.address },
error: err,
addressListener: newListener.address,
})
);

View File

@ -95,7 +95,7 @@ describe("test class ManageListener", function () {
await events.once(ml, "update");
//expect
expect(updateSpy).to.have.been.calledThrice;
// expect(newEntriesSpy).to.have.been.calledTwice;
// expect(newEntriesSpy).to.have.been.calledTwice; // TODO
// here we're testing the second call for the first listener
// given