test(YouTube Node): Add tests for YouTube Node (#14459)

Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
Shireen Missi
2025-04-14 10:05:05 +01:00
committed by GitHub
parent 6b2d31ca2b
commit e1246ab65c
12 changed files with 2117 additions and 1 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.`,
);
});
});