From d2bc0760e2b5c977fcc683f0a0281f099a9c538d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 27 Sep 2024 11:56:04 +0200 Subject: [PATCH] fix(RSS Feed Trigger Node): Fix regression on missing timestamps (#10991) --- .../nodes/RssFeedRead/RssFeedReadTrigger.node.ts | 7 ++++--- .../nodes/RssFeedRead/test/RssFeedRead.test.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/RssFeedRead/RssFeedReadTrigger.node.ts b/packages/nodes-base/nodes/RssFeedRead/RssFeedReadTrigger.node.ts index a0607f3b86..523860ddd1 100644 --- a/packages/nodes-base/nodes/RssFeedRead/RssFeedReadTrigger.node.ts +++ b/packages/nodes-base/nodes/RssFeedRead/RssFeedReadTrigger.node.ts @@ -78,14 +78,15 @@ export class RssFeedReadTrigger implements INodeType { return [this.helpers.returnJsonArray(feed.items[0])]; } feed.items.forEach((item) => { - if (Date.parse(item.isoDate as string) > dateToCheck) { + if (item.isoDate && Date.parse(item.isoDate) > dateToCheck) { returnData.push(item); } }); if (feed.items.length) { - const maxIsoDate = Math.max(...feed.items.map(({ isoDate }) => Date.parse(isoDate!))); - pollData.lastItemDate = new Date(maxIsoDate).toISOString(); + pollData.lastItemDate = feed.items.reduce((a, b) => + new Date(a.isoDate!) > new Date(b.isoDate!) ? a : b, + ).isoDate; } } diff --git a/packages/nodes-base/nodes/RssFeedRead/test/RssFeedRead.test.ts b/packages/nodes-base/nodes/RssFeedRead/test/RssFeedRead.test.ts index 0f7b13fbe9..d942859764 100644 --- a/packages/nodes-base/nodes/RssFeedRead/test/RssFeedRead.test.ts +++ b/packages/nodes-base/nodes/RssFeedRead/test/RssFeedRead.test.ts @@ -46,6 +46,20 @@ describe('RssFeedReadTrigger', () => { expect(pollData.lastItemDate).toEqual(newItemDate); }); + it('should gracefully handle missing timestamps', async () => { + const pollData = mock(); + pollFunctions.getNodeParameter.mockReturnValue(feedUrl); + pollFunctions.getWorkflowStaticData.mockReturnValue(pollData); + (Parser.prototype.parseURL as jest.Mock).mockResolvedValue({ items: [{}, {}] }); + + const result = await node.poll.call(pollFunctions); + + expect(result).toEqual(null); + expect(pollFunctions.getWorkflowStaticData).toHaveBeenCalledWith('node'); + expect(pollFunctions.getNodeParameter).toHaveBeenCalledWith('feedUrl'); + expect(Parser.prototype.parseURL).toHaveBeenCalledWith(feedUrl); + }); + it('should return null if the feed is empty', async () => { const pollData = mock({ lastItemDate }); pollFunctions.getNodeParameter.mockReturnValue(feedUrl);