mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +00:00
feat(Email Trigger (IMAP) Node): Limit new mails fetched (#16926)
Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { type ImapSimple } from '@n8n/imap';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { mock, mockDeep } from 'jest-mock-extended';
|
||||
import { returnJsonArray } from 'n8n-core';
|
||||
import { type IDataObject, type ITriggerFunctions } from 'n8n-workflow';
|
||||
import type { INode, ITriggerFunctions } from 'n8n-workflow';
|
||||
|
||||
import { getNewEmails } from '../../v2/utils';
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('Test IMap V2 utils', () => {
|
||||
afterEach(() => jest.resetAllMocks());
|
||||
|
||||
describe('getNewEmails', () => {
|
||||
const triggerFunctions = mock<ITriggerFunctions>({
|
||||
const triggerFunctions = mockDeep<ITriggerFunctions>({
|
||||
helpers: { returnJsonArray },
|
||||
});
|
||||
|
||||
@@ -73,27 +73,27 @@ describe('Test IMap V2 utils', () => {
|
||||
];
|
||||
|
||||
expectedResults.forEach(async (expectedResult) => {
|
||||
// use new staticData for each iteration
|
||||
const staticData: IDataObject = {};
|
||||
|
||||
triggerFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 2.1 }));
|
||||
triggerFunctions.getNodeParameter
|
||||
.calledWith('format')
|
||||
.mockReturnValue(expectedResult.format);
|
||||
triggerFunctions.getNodeParameter
|
||||
.calledWith('dataPropertyAttachmentsPrefixName')
|
||||
.mockReturnValue('resolved');
|
||||
triggerFunctions.getWorkflowStaticData.mockReturnValue({});
|
||||
|
||||
const result = getNewEmails.call(
|
||||
triggerFunctions,
|
||||
const onEmailBatch = jest.fn();
|
||||
await getNewEmails.call(triggerFunctions, {
|
||||
imapConnection,
|
||||
[],
|
||||
staticData,
|
||||
'',
|
||||
searchCriteria: [],
|
||||
postProcessAction: '',
|
||||
getText,
|
||||
getAttachment,
|
||||
);
|
||||
onEmailBatch,
|
||||
});
|
||||
|
||||
await expect(result).resolves.toEqual([expectedResult.expected]);
|
||||
expect(onEmailBatch).toHaveBeenCalledTimes(1);
|
||||
expect(onEmailBatch).toHaveBeenCalledWith([expectedResult.expected]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user