Add tests, improve workflow settings for testing, toString the results

This commit is contained in:
agobrech 2023-04-11 16:20:56 +02:00
parent 7b38555281
commit 7aa2bce505
6 changed files with 311 additions and 177 deletions

View file

@ -104,9 +104,9 @@ export class DateTimeV2 implements INodeType {
}
responseData.push(
includeTime
? { [outputFieldName]: DateTime.now().setZone(newLocal) }
? { [outputFieldName]: DateTime.now().setZone(newLocal).toString() }
: {
[outputFieldName]: DateTime.now().setZone(newLocal).startOf('day'),
[outputFieldName]: DateTime.now().setZone(newLocal).startOf('day').toString(),
},
);
} else if (operation === 'addToDate') {
@ -116,7 +116,7 @@ export class DateTimeV2 implements INodeType {
const outputFieldName = this.getNodeParameter('outputFieldName', i) as string;
const dateToAdd = parseDate.call(this, addToDate, workflowTimezone);
const returnedDate = dateToAdd.plus({ [timeUnit]: duration });
responseData.push({ [outputFieldName]: returnedDate });
responseData.push({ [outputFieldName]: returnedDate.toString() });
} else if (operation === 'subtractFromDate') {
const subtractFromDate = this.getNodeParameter('subtractFromDate', i) as string;
const timeUnit = this.getNodeParameter('timeUnit', i) as string;
@ -124,7 +124,7 @@ export class DateTimeV2 implements INodeType {
const outputFieldName = this.getNodeParameter('outputFieldName', i) as string;
const dateToAdd = parseDate.call(this, subtractFromDate, workflowTimezone);
const returnedDate = dateToAdd.minus({ [timeUnit]: duration });
responseData.push({ [outputFieldName]: returnedDate });
responseData.push({ [outputFieldName]: returnedDate.toString() });
} else if (operation === 'formatDate') {
const date = this.getNodeParameter('date', i) as string;
const format = this.getNodeParameter('format', i) as string;
@ -148,12 +148,15 @@ export class DateTimeV2 implements INodeType {
if (mode === 'roundDown') {
const toNearest = this.getNodeParameter('toNearest', i) as string;
responseData.push({
[outputFieldName]: dateLuxon.startOf(toNearest as DateTimeUnit),
[outputFieldName]: dateLuxon.startOf(toNearest as DateTimeUnit).toString(),
});
} else if (mode === 'roundUp') {
const to = this.getNodeParameter('to', i) as string;
responseData.push({
[outputFieldName]: dateLuxon.plus({ [to]: 1 }).startOf(to as DateTimeUnit),
[outputFieldName]: dateLuxon
.plus({ [to]: 1 })
.startOf(to as DateTimeUnit)
.toString(),
});
}
} else if (operation === 'getTimeBetweenDates') {

View file

@ -0,0 +1,289 @@
{
"name": "node-360-quick-overhaul-of-date-and-time-node",
"nodes": [
{
"parameters": {},
"id": "21ff2e15-375d-4e68-b1ca-d48a110be238",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-420,
20
]
},
{
"parameters": {
"operation": "addToDate",
"addToDate": "={{ $json.currentDate }}",
"duration": 2
},
"id": "b99986f1-edeb-434c-b7ed-9cc86eaec522",
"name": "Add to date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
140,
40
]
},
{
"parameters": {
"operation": "subtractFromDate",
"subtractFromDate": "={{ $json.newDate }}",
"duration": 2
},
"id": "aa75a04b-0d42-46ff-87e7-75d4b4f6c7ea",
"name": "Subtract date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
300,
200
]
},
{
"parameters": {
"operation": "formatDate",
"date": "={{ $json.newDate }}",
"format": "yyyy/MM/dd"
},
"id": "52076d89-bc6d-4253-8ca4-9aad3a058d17",
"name": "Format Date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
420,
40
]
},
{
"parameters": {
"operation": "roundDate",
"date": "={{ $json.formattedDate }}",
"toNearest": "day"
},
"id": "10016499-c9da-4984-9a5f-2f8c8844fb63",
"name": "Round Date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
560,
200
]
},
{
"parameters": {
"operation": "getTimeBetweenDates",
"startDate": "={{ $node['Subtract date'].json.newDate }}",
"endDate": "={{ $node['Add to date'].json.newDate }}",
"units": [
"day"
]
},
"id": "f62b6d0b-b13a-4fcd-b4eb-3ec7ea85e80c",
"name": "Get between date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
660,
40
]
},
{
"parameters": {
"operation": "extractDate",
"date": "={{ $node.Code.json.currentDate }}",
"part": "hour",
"outputFieldName": "date"
},
"id": "764e3e08-f71b-4e42-b059-36285076fe10",
"name": "Extract Date",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
780,
220
]
},
{
"parameters": {
"options": {
"fromFormat": ""
}
},
"id": "f0b75198-74a4-4a13-8842-340539f41d80",
"name": "V1",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [
0,
-180
],
"disabled": true
},
{
"parameters": {
"jsCode": "return {\"currentDate\":\"2023-04-11T13:51:59.965+00:00\"}\n"
},
"id": "7ba0c2a1-a683-4975-a2ca-70904111a3fc",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
-140,
140
]
}
],
"pinData": {
"Code": [
{
"json": {
"currentDate": "2023-04-11T13:51:59.965+00:00"
}
}
],
"Add to date": [
{
"json": {
"newDate": "2023-04-13T13:51:59.965+00:00"
}
}
],
"Subtract date": [
{
"json": {
"newDate": "2023-04-11T13:51:59.965+00:00"
}
}
],
"Format Date": [
{
"json": {
"formattedDate": "2023/04/11"
}
}
],
"Round Date": [
{
"json": {
"roundedDate": "2023-04-11T00:00:00.000+00:00"
}
}
],
"Get between date": [
{
"json": {
"timeDifference": {
"days": 2
}
}
}
],
"Extract Date": [
{
"json": {
"date": 13
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "V1",
"type": "main",
"index": 0
},
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Add to date": {
"main": [
[
{
"node": "Subtract date",
"type": "main",
"index": 0
}
]
]
},
"Subtract date": {
"main": [
[
{
"node": "Format Date",
"type": "main",
"index": 0
}
]
]
},
"Format Date": {
"main": [
[
{
"node": "Round Date",
"type": "main",
"index": 0
}
]
]
},
"Round Date": {
"main": [
[
{
"node": "Get between date",
"type": "main",
"index": 0
}
]
]
},
"Get between date": {
"main": [
[
{
"node": "Extract Date",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Add to date",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"saveManualExecutions": false,
"callerPolicy": "workflowsFromSameOwner",
"timezone": "Etc/GMT",
"executionTimeout": -1
},
"versionId": "c21daa0b-83ae-45f1-b680-d2e57423800b",
"id": "48",
"meta": {
"instanceId": "8e9416f42a954d0a370d988ac3c0f916f44074a6e45189164b1a8559394a7516"
},
"tags": []
}

View file

@ -1,165 +0,0 @@
{
"name": "My workflow 10",
"nodes": [
{
"parameters": {},
"id": "4d3b2f7b-1ae9-432d-b765-c6134cd11afc",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [-60, 2060]
},
{
"parameters": {
"value": "={{ DateTime.fromISO($json.testData) }}",
"toFormat": "X",
"options": {
"toTimezone": "UTC"
}
},
"id": "31ad53db-5cfd-44e5-917b-b90105ae687d",
"name": "Date & Time",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [400, 1960]
},
{
"parameters": {
"value": "={{ DateTime.fromISO($json.testData).minus({days:1}) }}",
"toFormat": "X",
"options": {
"toTimezone": "UTC"
}
},
"id": "f959c146-2cd3-4bc5-aa55-5b974466ba90",
"name": "Date & Time1",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [400, 2180]
},
{
"parameters": {
"value": "={{ Number($json.data) }}",
"toFormat": "YYYY-MM-DD",
"options": {
"toTimezone": "UTC"
}
},
"id": "8bf5b635-607e-4207-8b0e-66f0540b103c",
"name": "Date & Time2",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [620, 1960]
},
{
"parameters": {
"value": "={{ Number($json.data) }}",
"toFormat": "YYYY-MM-DD",
"options": {
"toTimezone": "UTC"
}
},
"id": "350ce053-d415-4a7d-8447-6d7c73758f35",
"name": "Date & Time3",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [620, 2180]
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "testData",
"value": "2023-03-31T06:31:01.000"
}
]
},
"options": {}
},
"id": "b57950a6-3a6a-4e23-8c3b-16abe12bfe16",
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 2,
"position": [140, 2060]
}
],
"pinData": {
"Date & Time2": [
{
"json": {
"testData": "2023-03-31T06:31:01.000",
"data": "2023-03-31"
}
}
],
"Date & Time3": [
{
"json": {
"testData": "2023-03-31T06:31:01.000",
"data": "2023-03-30"
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Date & Time": {
"main": [
[
{
"node": "Date & Time2",
"type": "main",
"index": 0
}
]
]
},
"Date & Time1": {
"main": [
[
{
"node": "Date & Time3",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Date & Time",
"type": "main",
"index": 0
},
{
"node": "Date & Time1",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "ff99618e-6e8e-49d8-b899-021caff6d01d",
"id": "151",
"meta": {
"instanceId": "36203ea1ce3cef713fa25999bd9874ae26b9e4c2c3a90a365f2882a154d031d0"
},
"tags": []
}

View file

@ -12,11 +12,13 @@ export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INo
active: false,
nodeTypes,
});
const waitPromise = await createDeferredPromise<IRun>();
const nodeExecutionOrder: string[] = [];
const additionalData = Helpers.WorkflowExecuteAdditionalData(waitPromise, nodeExecutionOrder);
const additionalData = Helpers.WorkflowExecuteAdditionalData(
waitPromise,
nodeExecutionOrder,
testData,
);
const workflowExecute = new WorkflowExecute(additionalData, executionMode);
const executionData = await workflowExecute.run(workflowInstance);

View file

@ -77,6 +77,7 @@ export class CredentialsHelper extends ICredentialsHelper {
export function WorkflowExecuteAdditionalData(
waitPromise: IDeferredPromise<IRun>,
nodeExecutionOrder: string[],
workflowTestData?: WorkflowTestData,
): IWorkflowExecuteAdditionalData {
const hookFunctions = {
nodeExecuteAfter: [
@ -99,7 +100,6 @@ export function WorkflowExecuteAdditionalData(
nodes: [],
connections: {},
};
return {
credentialsHelper: new CredentialsHelper(''),
hooks: new WorkflowHooks(hookFunctions, 'trigger', '1', workflowData),
@ -107,7 +107,7 @@ export function WorkflowExecuteAdditionalData(
sendMessageToUI: (message: string) => {},
restApiUrl: '',
encryptionKey: 'test',
timezone: 'America/New_York',
timezone: workflowTestData?.input.workflowData.settings?.timezone || 'America/New_York',
webhookBaseUrl: 'webhook',
webhookWaitingBaseUrl: 'webhook-waiting',
webhookTestBaseUrl: 'webhook-test',
@ -265,7 +265,6 @@ const preparePinData = (pinData: IDataObject) => {
);
return returnData;
};
export const workflowToTests = (workflowFiles: string[]) => {
const testCases: WorkflowTestData[] = [];
for (const filePath of workflowFiles) {

View file

@ -6,6 +6,12 @@ export interface WorkflowTestData {
workflowData: {
nodes: INode[];
connections: IConnections;
settings?: {
saveManualExecutions: boolean;
callerPolicy: string;
timezone: string;
saveExecutionProgress: string;
};
};
};
output: {