fix(Gmail Trigger Node): Don't return date instances, but date strings instead (#10582)

This commit is contained in:
Danny Martini 2024-08-28 15:43:04 +02:00 committed by GitHub
parent 3b43ff69a7
commit 9e1dac0465
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View file

@ -202,6 +202,11 @@ export async function parseRawEmail(
headers,
headerLines: undefined,
attachments: undefined,
// Having data in IDataObjects that is not representable in JSON leads to
// inconsistencies between test executions and production executions.
// During a manual execution this would be stringified and during a
// production execution the next node would receive a date instance.
date: responseData.date ? responseData.date.toISOString() : responseData.date,
}) as IDataObject;
return {

View file

@ -1,6 +1,7 @@
import type { INode } from 'n8n-workflow';
import type { IExecuteFunctions, INode } from 'n8n-workflow';
import { DateTime } from 'luxon';
import { prepareTimestamp } from '../../GenericFunctions';
import { mock } from 'jest-mock-extended';
import { parseRawEmail, prepareTimestamp } from '../../GenericFunctions';
const node: INode = {
id: '1',
@ -108,3 +109,21 @@ describe('Google Gmail v2, prepareTimestamp', () => {
);
});
});
describe('parseRawEmail', () => {
it('should return a date string', async () => {
// ARRANGE
const executionFunctions = mock<IExecuteFunctions>();
const rawEmail = 'Date: Wed, 28 Aug 2024 00:36:37 -0700'.replace(/\n/g, '\r\n');
// ACT
const { json } = await parseRawEmail.call(
executionFunctions,
{ raw: Buffer.from(rawEmail, 'utf8').toString('base64') },
'attachment_',
);
// ASSERT
expect(typeof json.date).toBe('string');
});
});