forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube Node): Issue in published before and after dates filters (n…
- Loading branch information
1 parent
d9259a2
commit 7381c28
Showing
3 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/nodes-base/nodes/Google/YouTube/test/GenericFunctions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.`, | ||
); | ||
}); | ||
}); |