add new test + some little refactors
This commit is contained in:
parent
01392a2c20
commit
30f5e576d0
|
@ -32,15 +32,15 @@ describe("test class RSS: jsonfile", function () {
|
|||
const mockedRSSOutput: Parser.Output<any> = {
|
||||
items: [
|
||||
{
|
||||
title: "my title 00",
|
||||
title: "my title 02",
|
||||
"media:group": {
|
||||
"media:description": "my description 00",
|
||||
"media:description": "my description 02",
|
||||
"media:thumbnail": [
|
||||
{ $: { height: 360, width: 420, url: "my_image00.jpg" } },
|
||||
{ $: { height: 360, width: 420, url: "my_image02.jpg" } },
|
||||
],
|
||||
},
|
||||
link: "my_url_00.com",
|
||||
pubDate: "myDate00",
|
||||
link: "my_url_02.com",
|
||||
pubDate: "myDate02",
|
||||
},
|
||||
{
|
||||
title: "my title 01",
|
||||
|
@ -54,15 +54,15 @@ describe("test class RSS: jsonfile", function () {
|
|||
pubDate: "myDate01",
|
||||
},
|
||||
{
|
||||
title: "my title 02",
|
||||
title: "my title 00",
|
||||
"media:group": {
|
||||
"media:description": "my description 02",
|
||||
"media:description": "my description 00",
|
||||
"media:thumbnail": [
|
||||
{ $: { height: 360, width: 420, url: "my_image02.jpg" } },
|
||||
{ $: { height: 360, width: 420, url: "my_image00.jpg" } },
|
||||
],
|
||||
},
|
||||
link: "my_url_02.com",
|
||||
pubDate: "myDate02",
|
||||
link: "my_url_00.com",
|
||||
pubDate: "myDate00",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -366,5 +366,70 @@ describe("test class RSS: jsonfile", function () {
|
|||
|
||||
myListener.stop();
|
||||
});
|
||||
|
||||
it("notifies with 'newEntries' when a new entry is detected", async function () {
|
||||
// given
|
||||
const clock = sinon.useFakeTimers();
|
||||
|
||||
const mockManager = ImportMock.mockClassInPlace<Parser>(Parser);
|
||||
const stubParser = mockManager.mock("parseURL");
|
||||
stubParser.resolves(mockedRSSOutput);
|
||||
const newEntry = {
|
||||
title: "my title 03",
|
||||
"media:group": {
|
||||
"media:description": "my description 03",
|
||||
"media:thumbnail": [
|
||||
{ $: { height: 360, width: 420, url: "my_image03.jpg" } },
|
||||
],
|
||||
},
|
||||
link: "my_url_03.com",
|
||||
pubDate: "myDate03",
|
||||
};
|
||||
const newRSSOutput = {
|
||||
...mockedRSSOutput,
|
||||
items: [newEntry, ...mockedRSSOutput.items],
|
||||
};
|
||||
|
||||
// classic build
|
||||
const myListener = new Listeners({
|
||||
...infosListener,
|
||||
timeloop: 60,
|
||||
});
|
||||
|
||||
//spy
|
||||
const updateListenerSpy = sinon.spy();
|
||||
const newEntriesListenerSpy = sinon.spy();
|
||||
|
||||
myListener.on("update", updateListenerSpy);
|
||||
myListener.on("newEntries", newEntriesListenerSpy);
|
||||
|
||||
// when
|
||||
myListener.start();
|
||||
|
||||
// then
|
||||
await clock.tickAsync(1);
|
||||
expect(updateListenerSpy).to.have.been.calledOnce;
|
||||
expect(newEntriesListenerSpy).to.not.have.been.called;
|
||||
|
||||
// given
|
||||
stubParser.resolves(newRSSOutput);
|
||||
|
||||
// then
|
||||
await clock.tickAsync(60000);
|
||||
expect(updateListenerSpy).to.have.been.calledTwice;
|
||||
expect(newEntriesListenerSpy).to.have.been.calledOnce;
|
||||
expect(newEntriesListenerSpy).to.have.been.calledWith([newEntry]);
|
||||
|
||||
// given
|
||||
newEntriesListenerSpy.resetHistory();
|
||||
|
||||
// then
|
||||
await clock.tickAsync(60000);
|
||||
expect(updateListenerSpy).to.have.been.calledThrice;
|
||||
expect(updateListenerSpy).to.have.been.calledWith(mockedRSSOutput);
|
||||
expect(newEntriesListenerSpy).to.not.have.been.called;
|
||||
|
||||
myListener.stop();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user