adding listener rss package + better addNewListener's implementation + better sqlite management
This commit is contained in:
		@@ -32,7 +32,7 @@ describe("test class ManageListener", function () {
 | 
			
		||||
        const ml = new ManageListener(path);
 | 
			
		||||
        await ml.load();
 | 
			
		||||
 | 
			
		||||
        for (const item of dataWithoutHistory) await ml.addNewListener(item);
 | 
			
		||||
        for (const item of dataWithoutHistory) await ml.registerListener(item);
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        ml.save();
 | 
			
		||||
@@ -62,7 +62,7 @@ describe("test class ManageListener", function () {
 | 
			
		||||
        const clock = sinon.useFakeTimers();
 | 
			
		||||
        const ml = new ManageListener(path);
 | 
			
		||||
        await ml.load();
 | 
			
		||||
        for (const item of dataWithoutHistory) await ml.addNewListener(item);
 | 
			
		||||
        for (const item of dataWithoutHistory) await ml.registerListener(item);
 | 
			
		||||
 | 
			
		||||
        const updateSpy = sinon.spy();
 | 
			
		||||
        const newEntriesSpy = sinon.spy();
 | 
			
		||||
@@ -152,7 +152,7 @@ describe("test class ManageListener", function () {
 | 
			
		||||
        const clock = sinon.useFakeTimers();
 | 
			
		||||
        const ml = new ManageListener(path);
 | 
			
		||||
        await ml.load();
 | 
			
		||||
        for (const item of dataWithHistory) await ml.addNewListener(item);
 | 
			
		||||
        for (const item of dataWithHistory) await ml.registerListener(item);
 | 
			
		||||
 | 
			
		||||
        const updateSpy = sinon.spy();
 | 
			
		||||
        const newEntriesSpy = sinon.spy();
 | 
			
		||||
@@ -251,176 +251,5 @@ describe("test class ManageListener", function () {
 | 
			
		||||
        ml.stopAll();
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    //   it("should call correctly the events (with aggregation)", async function () {
 | 
			
		||||
    //     // given
 | 
			
		||||
    //     const clock = sinon.useFakeTimers();
 | 
			
		||||
    //     const ml = new ManageListener({
 | 
			
		||||
    //       timeloop: 30,
 | 
			
		||||
    //       path: "tests/RessourcesTest/RealRessources/save_no_history.json",
 | 
			
		||||
    //     });
 | 
			
		||||
 | 
			
		||||
    //     const updateSpy = sinon.spy((obj) => console.log(obj));
 | 
			
		||||
    //     const newEntriesSpy = sinon.spy();
 | 
			
		||||
 | 
			
		||||
    //     const tabChannelId = [
 | 
			
		||||
    //       "UCOuIgj0CYCXCvjWywjDbauw",
 | 
			
		||||
    //       "UCh2YBKhYIy-_LtfCIn2Jycg",
 | 
			
		||||
    //       "UCY7klexd1qEqxgqYK6W7BVQ",
 | 
			
		||||
    //     ];
 | 
			
		||||
 | 
			
		||||
    //     ml.on("update", updateSpy);
 | 
			
		||||
    //     ml.on("newEntries", newEntriesSpy);
 | 
			
		||||
    //     tabChannelId.forEach((item: string) => {
 | 
			
		||||
    //       nock("https://www.youtube.com")
 | 
			
		||||
    //         .get(`/feeds/videos.xml?channel_id=${item}`)
 | 
			
		||||
    //         .replyWithFile(
 | 
			
		||||
    //           200,
 | 
			
		||||
    //           path.join(__dirname, `RessourcesTest/RealRessources/${item}.rss`),
 | 
			
		||||
    //           { "content-type": "text/xml", charset: "utf-8" }
 | 
			
		||||
    //         )
 | 
			
		||||
    //         .persist();
 | 
			
		||||
    //     });
 | 
			
		||||
    //     ml.startAll();
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[1], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[2], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.have.been.calledOnce;
 | 
			
		||||
    //     expect(newEntriesSpy).to.have.been.calledOnce;
 | 
			
		||||
 | 
			
		||||
    //     // given
 | 
			
		||||
    //     updateSpy.resetHistory();
 | 
			
		||||
    //     newEntriesSpy.resetHistory();
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await events.once(ml.listenerArray[0], "update");
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.not.have.been.called;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[1], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.not.have.been.called;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[2], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.have.been.calledOnce;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     ml.stopAll();
 | 
			
		||||
    //   });
 | 
			
		||||
 | 
			
		||||
    //   it("should call correctly the events with a new entry (with aggregation)", async function () {
 | 
			
		||||
    //     // given
 | 
			
		||||
    //     const clock = sinon.useFakeTimers();
 | 
			
		||||
    //     const ml = new ManageListener({
 | 
			
		||||
    //       timeloop: 30,
 | 
			
		||||
    //       path: "tests/RessourcesTest/RealRessources/save.json",
 | 
			
		||||
    //     });
 | 
			
		||||
 | 
			
		||||
    //     const updateSpy = sinon.spy();
 | 
			
		||||
    //     const newEntriesSpy = sinon.spy();
 | 
			
		||||
 | 
			
		||||
    //     const tabChannelId = [
 | 
			
		||||
    //       "UCOuIgj0CYCXCvjWywjDbauw",
 | 
			
		||||
    //       "UCh2YBKhYIy-_LtfCIn2Jycg",
 | 
			
		||||
    //       "UCY7klexd1qEqxgqYK6W7BVQ",
 | 
			
		||||
    //     ];
 | 
			
		||||
 | 
			
		||||
    //     ml.on("update", updateSpy);
 | 
			
		||||
    //     ml.on("newEntries", newEntriesSpy);
 | 
			
		||||
    //     tabChannelId.forEach((item: string) => {
 | 
			
		||||
    //       nock("https://www.youtube.com")
 | 
			
		||||
    //         .get(`/feeds/videos.xml?channel_id=${item}`)
 | 
			
		||||
    //         .once()
 | 
			
		||||
    //         .replyWithFile(
 | 
			
		||||
    //           200,
 | 
			
		||||
    //           path.join(__dirname, `RessourcesTest/RealRessources/${item}.rss`),
 | 
			
		||||
    //           { "content-type": "text/xml", charset: "utf-8" }
 | 
			
		||||
    //         );
 | 
			
		||||
    //     });
 | 
			
		||||
    //     ml.startAll();
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[1], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[2], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.have.been.calledOnce;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     // given
 | 
			
		||||
    //     updateSpy.resetHistory();
 | 
			
		||||
 | 
			
		||||
    //     tabChannelId.forEach((item: string) => {
 | 
			
		||||
    //       nock("https://www.youtube.com")
 | 
			
		||||
    //         .get(`/feeds/videos.xml?channel_id=${item}`)
 | 
			
		||||
    //         .replyWithFile(
 | 
			
		||||
    //           200,
 | 
			
		||||
    //           path.join(
 | 
			
		||||
    //             __dirname,
 | 
			
		||||
    //             `RessourcesTest/RealRessources/WithUpdate/${item}.rss`
 | 
			
		||||
    //           ),
 | 
			
		||||
    //           { "content-type": "text/xml", charset: "utf-8" }
 | 
			
		||||
    //         )
 | 
			
		||||
    //         .persist();
 | 
			
		||||
    //     });
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await events.once(ml.listenerArray[0], "update");
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.not.have.been.called;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[1], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.not.have.been.called;
 | 
			
		||||
    //     expect(newEntriesSpy).to.not.have.been.called;
 | 
			
		||||
 | 
			
		||||
    //     // when
 | 
			
		||||
    //     await clock.tickAsync(10000);
 | 
			
		||||
    //     await Promise.all([
 | 
			
		||||
    //       events.once(ml.listenerArray[0], "update"),
 | 
			
		||||
    //       events.once(ml.listenerArray[2], "update"),
 | 
			
		||||
    //     ]);
 | 
			
		||||
 | 
			
		||||
    //     //expect
 | 
			
		||||
    //     expect(updateSpy).to.have.been.calledOnce;
 | 
			
		||||
    //     expect(newEntriesSpy).to.have.been.calledOnce;
 | 
			
		||||
 | 
			
		||||
    //     ml.stopAll();
 | 
			
		||||
    //   });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user