Skip to content

Commit

Permalink
chore: Get past execution's start and destination nodes while running…
Browse files Browse the repository at this point in the history
… tests (no-changelog) (n8n-io#11983)
  • Loading branch information
burivuhster authored Dec 2, 2024
1 parent e68c9da commit b0e9085
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { readFileSync } from 'fs';
import path from 'path';

import { createPinData } from '../utils.ee';

const wfUnderTestJson = JSON.parse(
readFileSync(path.join(__dirname, './mock-data/workflow.under-test.json'), { encoding: 'utf-8' }),
);

const executionDataJson = JSON.parse(
readFileSync(path.join(__dirname, './mock-data/execution-data.json'), { encoding: 'utf-8' }),
);

describe('createPinData', () => {
test('should create pin data from past execution data', () => {
const pinData = createPinData(wfUnderTestJson, executionDataJson);

expect(pinData).toEqual(
expect.objectContaining({
'When clicking ‘Test workflow’': expect.anything(),
}),
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { readFileSync } from 'fs';
import path from 'path';

import { getPastExecutionStartNode } from '../utils.ee';

const executionDataJson = JSON.parse(
readFileSync(path.join(__dirname, './mock-data/execution-data.json'), { encoding: 'utf-8' }),
);

const executionDataMultipleTriggersJson = JSON.parse(
readFileSync(path.join(__dirname, './mock-data/execution-data.multiple-triggers.json'), {
encoding: 'utf-8',
}),
);

const executionDataMultipleTriggersJson2 = JSON.parse(
readFileSync(path.join(__dirname, './mock-data/execution-data.multiple-triggers-2.json'), {
encoding: 'utf-8',
}),
);

describe('getPastExecutionStartNode', () => {
test('should return the start node of the past execution', () => {
const startNode = getPastExecutionStartNode(executionDataJson);

expect(startNode).toEqual('When clicking ‘Test workflow’');
});

test('should return the start node of the past execution with multiple triggers', () => {
const startNode = getPastExecutionStartNode(executionDataMultipleTriggersJson);

expect(startNode).toEqual('When clicking ‘Test workflow’');
});

test('should return the start node of the past execution with multiple triggers - chat trigger', () => {
const startNode = getPastExecutionStartNode(executionDataMultipleTriggersJson2);

expect(startNode).toEqual('When chat message received');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"startData": {},
"resultData": {
"runData": {
"When chat message received": [
{
"startTime": 1732882447976,
"executionTime": 0,
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"sessionId": "192c5b3c0b0642d68eab1a747a59cb6e",
"action": "sendMessage",
"chatInput": "hey"
}
}
]
]
},
"source": [null]
}
],
"NoOp": [
{
"hints": [],
"startTime": 1732882448034,
"executionTime": 0,
"source": [
{
"previousNode": "When clicking ‘Test workflow’"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"sessionId": "192c5b3c0b0642d68eab1a747a59cb6e",
"action": "sendMessage",
"chatInput": "hey"
},
"pairedItem": {
"item": 0
}
}
]
]
}
}
],
"NoOp2": [
{
"hints": [],
"startTime": 1732882448037,
"executionTime": 0,
"source": [
{
"previousNode": "NoOp"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"sessionId": "192c5b3c0b0642d68eab1a747a59cb6e",
"action": "sendMessage",
"chatInput": "hey"
},
"pairedItem": {
"item": 0
}
}
]
]
}
}
]
},
"pinData": {},
"lastNodeExecuted": "NoOp2"
},
"executionData": {
"contextData": {},
"nodeExecutionStack": [],
"metadata": {},
"waitingExecution": {},
"waitingExecutionSource": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"startData": {},
"resultData": {
"runData": {
"When clicking ‘Test workflow’": [
{
"hints": [],
"startTime": 1732882424975,
"executionTime": 0,
"source": [],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {},
"pairedItem": {
"item": 0
}
}
]
]
}
}
],
"NoOp": [
{
"hints": [],
"startTime": 1732882424977,
"executionTime": 1,
"source": [
{
"previousNode": "When clicking ‘Test workflow’"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {},
"pairedItem": {
"item": 0
}
}
]
]
}
}
],
"NoOp2": [
{
"hints": [],
"startTime": 1732882424978,
"executionTime": 0,
"source": [
{
"previousNode": "NoOp"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {},
"pairedItem": {
"item": 0
}
}
]
]
}
}
]
},
"pinData": {},
"lastNodeExecuted": "NoOp2"
},
"executionData": {
"contextData": {},
"nodeExecutionStack": [],
"metadata": {},
"waitingExecution": {},
"waitingExecutionSource": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "Multiple Triggers Workflow",
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [-20, -120],
"id": "19562c2d-d2c8-45c8-ae0a-1b1effe29817",
"name": "When clicking ‘Test workflow’"
},
{
"parameters": {
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"typeVersion": 1.1,
"position": [-20, 120],
"id": "9b4b833b-56f6-4099-9b7d-5e94b75a735c",
"name": "When chat message received",
"webhookId": "8aeccd03-d45f-48d2-a2c7-1fb8c53d2ad7"
},
{
"parameters": {},
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [260, -20],
"id": "d3ab7426-11e7-4f42-9a57-11b8de019783",
"name": "NoOp"
},
{
"parameters": {},
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [480, -20],
"id": "fb73bed6-ec2a-4283-b564-c96730b94889",
"name": "NoOp2"
}
],
"connections": {
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"NoOp": {
"main": [
[
{
"node": "NoOp2",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {}
}
Loading

0 comments on commit b0e9085

Please sign in to comment.