mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(RSS Feed Trigger Node): Fix regression on missing timestamps (#10991)
This commit is contained in:
committed by
GitHub
parent
fe7d060568
commit
d2bc0760e2
@@ -78,14 +78,15 @@ export class RssFeedReadTrigger implements INodeType {
|
|||||||
return [this.helpers.returnJsonArray(feed.items[0])];
|
return [this.helpers.returnJsonArray(feed.items[0])];
|
||||||
}
|
}
|
||||||
feed.items.forEach((item) => {
|
feed.items.forEach((item) => {
|
||||||
if (Date.parse(item.isoDate as string) > dateToCheck) {
|
if (item.isoDate && Date.parse(item.isoDate) > dateToCheck) {
|
||||||
returnData.push(item);
|
returnData.push(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (feed.items.length) {
|
if (feed.items.length) {
|
||||||
const maxIsoDate = Math.max(...feed.items.map(({ isoDate }) => Date.parse(isoDate!)));
|
pollData.lastItemDate = feed.items.reduce((a, b) =>
|
||||||
pollData.lastItemDate = new Date(maxIsoDate).toISOString();
|
new Date(a.isoDate!) > new Date(b.isoDate!) ? a : b,
|
||||||
|
).isoDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,20 @@ describe('RssFeedReadTrigger', () => {
|
|||||||
expect(pollData.lastItemDate).toEqual(newItemDate);
|
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 () => {
|
it('should return null if the feed is empty', async () => {
|
||||||
const pollData = mock({ lastItemDate });
|
const pollData = mock({ lastItemDate });
|
||||||
pollFunctions.getNodeParameter.mockReturnValue(feedUrl);
|
pollFunctions.getNodeParameter.mockReturnValue(feedUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user