-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Gmail Node): Gmail luxon object support, fix for timestamp
- Loading branch information
1 parent
f0a51a0
commit 695fabb
Showing
4 changed files
with
184 additions
and
61 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
111 changes: 111 additions & 0 deletions
111
packages/nodes-base/nodes/Google/Gmail/test/v2/utils.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,111 @@ | ||
import type { INode } from 'n8n-workflow'; | ||
import { prepareTimestamp } from '../../GenericFunctions'; | ||
|
||
import { DateTime } from 'luxon'; | ||
|
||
const node: INode = { | ||
id: '1', | ||
name: 'Gmail node', | ||
typeVersion: 2, | ||
type: 'n8n-nodes-base.gmail', | ||
position: [50, 50], | ||
parameters: { | ||
operation: 'getAll', | ||
}, | ||
}; | ||
|
||
describe('Google Gmail v2, prepareTimestamp', () => { | ||
it('should return a valid timestamp from ISO', () => { | ||
const dateInput = '2020-01-01T00:00:00.000Z'; | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from integer in miliseconds', () => { | ||
const dateInput = 1577836800000; | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from integer in seconds', () => { | ||
const dateInput = 1577836800; | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from string in miliseconds', () => { | ||
const dateInput = '1577836800000'; | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from string in seconds', () => { | ||
const dateInput = '1577836800'; | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from luxon DateTime', () => { | ||
const dateInput = DateTime.fromISO('2020-01-01T00:00:00.000Z'); | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should return a valid timestamp from luxon DateTime ISO', () => { | ||
const dateInput = DateTime.fromISO('2020-01-01T00:00:00.000Z').toISO(); | ||
const timestampBefore = prepareTimestamp(node, 0, '', dateInput, 'before'); | ||
const timestampAfter = prepareTimestamp(node, 0, '', dateInput, 'after'); | ||
|
||
expect(timestampBefore).toBeDefined(); | ||
expect(timestampBefore).toBe('before:1577836800'); | ||
|
||
expect(timestampAfter).toBeDefined(); | ||
expect(timestampAfter).toBe('after:1577836800'); | ||
}); | ||
|
||
it('should throw error on invalid data', () => { | ||
const dateInput = 'invalid'; | ||
expect(() => prepareTimestamp(node, 0, '', dateInput, 'before')).toThrow( | ||
"Invalid date/time in 'Received Before' field", | ||
); | ||
expect(() => prepareTimestamp(node, 0, '', dateInput, 'after')).toThrow( | ||
"Invalid date/time in 'Received After' field", | ||
); | ||
}); | ||
}); |
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