fix(YouTube Node): Issue in published before and after dates filters (#11741)

This commit is contained in:
Shireen Missi
2024-11-14 16:02:26 +00:00
committed by GitHub
parent d9259a2d93
commit 7381c28af0
3 changed files with 69 additions and 26 deletions

View File

@@ -0,0 +1,38 @@
import { DateTime } from 'luxon';
import { NodeOperationError, type IExecuteFunctions } from 'n8n-workflow';
import { validateAndSetDate } from '../../GenericFunctions';
const mockContext = {
getNode: jest.fn().mockReturnValue('Youtube'),
} as unknown as IExecuteFunctions;
describe('validateAndSetDate', () => {
const timezone = 'America/New_York';
let filter: { [key: string]: string };
beforeEach(() => {
filter = {};
});
it('should convert a valid ISO date and set it with the specified timezone', () => {
filter.publishedAfter = '2023-10-05T10:00:00.000Z';
validateAndSetDate(filter, 'publishedAfter', timezone, mockContext);
expect(filter.publishedAfter).toBe(
DateTime.fromISO('2023-10-05T10:00:00.000Z').setZone(timezone).toISO(),
);
});
it('should throw NodeOperationError for an invalid date', () => {
filter.publishedAfter = 'invalid-date';
expect(() => validateAndSetDate(filter, 'publishedAfter', timezone, mockContext)).toThrow(
NodeOperationError,
);
expect(() => validateAndSetDate(filter, 'publishedAfter', timezone, mockContext)).toThrow(
`The value "${filter.publishedAfter}" is not a valid DateTime.`,
);
});
});