Add workflow test for Summarize with hint

This commit is contained in:
Dana Lee 2025-01-22 13:01:15 +01:00
parent 51848490c4
commit 6189c72bdb
No known key found for this signature in database
2 changed files with 70 additions and 26 deletions

View file

@ -27,32 +27,6 @@ describe('Test Summarize Node', () => {
} as unknown as IExecuteFunctions;
});
// fails
it('should handle field not found with hints in version 1.1', async () => {
const node = new Summarize();
const context = {
getNodeParameter: jest
.fn()
.mockReturnValueOnce({}) // options
.mockReturnValueOnce('') // fieldsToSplitBy
.mockReturnValueOnce([{ field: 'nonexistentField', aggregation: 'sum' }]), // fieldsToSummarize
getInputData: jest.fn().mockReturnValue([{ json: { someField: 1 } }]),
getNode: jest.fn().mockReturnValue({ typeVersion: 1.1 }),
} as unknown as IExecuteFunctions;
await node.execute.call(context);
expect(NodeExecutionOutput).toHaveBeenCalledWith(
expect.any(Array),
expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('nonexistentField'),
location: 'outputPane',
}),
]),
);
});
it('should throw error if node version is < 1.1 and fields not found', async () => {
mockExecuteFunctions.getNode = jest.fn().mockReturnValue({ typeVersion: 1 });
const items = [{ a: 1 }, { b: 2 }, { c: 3 }];

View file

@ -0,0 +1,70 @@
{
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [520, -80],
"id": "9ff1d8e0-ebe8-4c52-931a-e482e14ac911",
"name": "When clicking Test workflow"
},
{
"parameters": {
"category": "randomData",
"randomDataSeed": "ria",
"randomDataCount": 5
},
"type": "n8n-nodes-base.debugHelper",
"typeVersion": 1,
"position": [700, -80],
"id": "50cea846-f8ed-4b5a-a14a-c11bf4ba0f5d",
"name": "DebugHelper2"
},
{
"parameters": {
"fieldsToSummarize": {
"values": [
{
"field": "passwor"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.summarize",
"typeVersion": 1.1,
"position": [900, -80],
"id": "d39fedc9-62e1-45bc-8c9a-d20f2b63b543",
"name": "Summarize1"
}
],
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "DebugHelper2",
"type": "main",
"index": 0
}
]
]
},
"DebugHelper2": {
"main": [
[
{
"node": "Summarize1",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "ee90fdf8d57662f949e6c691dc07fa0fd2f66e1eee28ed82ef06658223e67255"
}
}