feat(Microsoft Teams Node): Overhaul (#7477)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2024-01-22 18:35:09 +02:00
committed by GitHub
parent 44f6ef2ed7
commit 2c146cca62
68 changed files with 6284 additions and 664 deletions

View File

@@ -0,0 +1,111 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';
import * as transport from '../../../../v2/transport';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest');
microsoftApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'POST') {
return {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity',
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="',
planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf',
bucketId: 'CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m',
title: 'do this',
orderHint: '8584964728139267910',
assigneePriority: '',
percentComplete: 25,
startDateTime: null,
createdDateTime: '2024-01-13T08:21:11.5507897Z',
dueDateTime: '2023-10-30T22:00:00Z',
hasDescription: false,
previewType: 'automatic',
completedDateTime: null,
completedBy: null,
referenceCount: 0,
checklistItemCount: 0,
activeChecklistItemCount: 0,
conversationThreadId: null,
priority: 5,
id: 'mYxTKaD9VkqWaBCJE5v4E5gAHcPB',
createdBy: {
user: {
displayName: null,
id: 'b834447b-6848-4af9-8390-d2259ce46b74',
},
application: {
displayName: null,
id: '66bdd989-4a29-465d-86fb-d94ed8fd86ed',
},
},
appliedCategories: {},
assignments: {
'ba4a422e-bdce-4795-b4b6-579287363f0e': {
'@odata.type': '#microsoft.graph.plannerAssignment',
assignedDateTime: '2024-01-13T08:21:11.5507897Z',
orderHint: '8584964728740986700PZ',
assignedBy: {
user: {
displayName: null,
id: 'b834447b-6848-4af9-8390-d2259ce46b74',
},
application: {
displayName: null,
id: '66bdd989-4a29-465d-86fb-d94ed8fd86ed',
},
},
},
},
};
}
});
describe('Test MicrosoftTeamsV2, task => create', () => {
const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/create.workflow.json'];
const tests = workflowToTests(workflows);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.resetAllMocks();
});
const nodeTypes = setup(tests);
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith('POST', '/v1.0/planner/tasks', {
assignments: {
'ba4a422e-bdce-4795-b4b6-579287363f0e': {
'@odata.type': 'microsoft.graph.plannerAssignment',
orderHint: ' !',
},
},
bucketId: 'CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m',
dueDateTime: '2023-10-30T22:00:00.000Z',
percentComplete: 25,
planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf',
title: 'do this',
});
expect(result.finished).toEqual(true);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View File

@@ -0,0 +1,167 @@
{
"name": "My workflow 69",
"nodes": [
{
"parameters": {},
"id": "28f1f78e-0d50-4bfe-aa16-1a53f0832793",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
520,
300
]
},
{
"parameters": {
"resource": "task",
"groupId": {
"__rl": true,
"value": "1644e7fe-547e-4223-a24f-922395865343",
"mode": "list",
"cachedResultName": "5w1hb7"
},
"planId": {
"__rl": true,
"value": "THwgIivuyU26ki8qS7ufcJgAB6zf",
"mode": "list",
"cachedResultName": "my best plan"
},
"bucketId": {
"__rl": true,
"value": "CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m",
"mode": "list",
"cachedResultName": "To do"
},
"title": "do this",
"options": {
"assignedTo": {
"__rl": true,
"value": "ba4a422e-bdce-4795-b4b6-579287363f0e",
"mode": "list",
"cachedResultName": "Henrietta Mueller"
},
"dueDateTime": "2023-10-30T22:00:00.000Z",
"percentComplete": 25
}
},
"id": "e1c2eafd-4a1e-48aa-bc0e-d5a03644fedc",
"name": "Microsoft Teams",
"type": "n8n-nodes-base.microsoftTeams",
"typeVersion": 2,
"position": [
740,
300
],
"credentials": {
"microsoftTeamsOAuth2Api": {
"id": "6isd5ytvA0qV78eK",
"name": "Microsoft Teams account"
}
}
},
{
"parameters": {},
"id": "a05a3079-3431-44b8-a317-79e5d8babe25",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1040,
300
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity",
"@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=\"",
"planId": "THwgIivuyU26ki8qS7ufcJgAB6zf",
"bucketId": "CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m",
"title": "do this",
"orderHint": "8584964728139267910",
"assigneePriority": "",
"percentComplete": 25,
"startDateTime": null,
"createdDateTime": "2024-01-13T08:21:11.5507897Z",
"dueDateTime": "2023-10-30T22:00:00Z",
"hasDescription": false,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"priority": 5,
"id": "mYxTKaD9VkqWaBCJE5v4E5gAHcPB",
"createdBy": {
"user": {
"displayName": null,
"id": "b834447b-6848-4af9-8390-d2259ce46b74"
},
"application": {
"displayName": null,
"id": "66bdd989-4a29-465d-86fb-d94ed8fd86ed"
}
},
"appliedCategories": {},
"assignments": {
"ba4a422e-bdce-4795-b4b6-579287363f0e": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2024-01-13T08:21:11.5507897Z",
"orderHint": "8584964728740986700PZ",
"assignedBy": {
"user": {
"displayName": null,
"id": "b834447b-6848-4af9-8390-d2259ce46b74"
},
"application": {
"displayName": null,
"id": "66bdd989-4a29-465d-86fb-d94ed8fd86ed"
}
}
}
}
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Teams",
"type": "main",
"index": 0
}
]
]
},
"Microsoft Teams": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "8cb42e14-a12c-4c24-8374-4105664065c3",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"id": "73ZPNCHsvTvFBx1V",
"tags": []
}

View File

@@ -0,0 +1,65 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';
import * as transport from '../../../../v2/transport';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest');
microsoftApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'DELETE') {
return {};
}
if (method === 'GET') {
return {
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="',
};
}
});
describe('Test MicrosoftTeamsV2, task => deleteTask', () => {
const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/deleteTask.workflow.json'];
const tests = workflowToTests(workflows);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.resetAllMocks();
});
const nodeTypes = setup(tests);
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(2);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith(
'GET',
'/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith(
'DELETE',
'/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
{},
{},
undefined,
{ 'If-Match': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="' },
);
expect(result.finished).toEqual(true);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View File

@@ -0,0 +1,91 @@
{
"name": "My workflow 35",
"nodes": [
{
"parameters": {},
"id": "6666-9999-77777",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
880,
380
]
},
{
"parameters": {
"resource": "task",
"operation": "deleteTask",
"taskId": "lDrRJ7N_-06p_26iKBtJ6ZgAKffD"
},
"id": "6666-5555-77777",
"name": "Microsoft Teams",
"type": "n8n-nodes-base.microsoftTeams",
"typeVersion": 2,
"position": [
1100,
380
],
"credentials": {
"microsoftTeamsOAuth2Api": {
"id": "6isd5ytvA0qV78eK",
"name": "Microsoft Teams account"
}
}
},
{
"parameters": {},
"id": "9d1a2e59-c71c-486c-b3ac-dec6adbc26b3",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
380
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"success": true
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Teams",
"type": "main",
"index": 0
}
]
]
},
"Microsoft Teams": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "ae5ed0d2-4513-457a-80a4-262126523553",
"id": "i3NYGF0LXV4qDFV9",
"meta": {
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"tags": []
}

View File

@@ -0,0 +1,102 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';
import * as transport from '../../../../v2/transport';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest');
microsoftApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'GET') {
return {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity',
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="',
planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf',
bucketId: 'CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m',
title: 'do this',
orderHint: '8585032308935758184',
assigneePriority: '',
percentComplete: 25,
startDateTime: null,
createdDateTime: '2023-10-27T03:06:31.9017623Z',
dueDateTime: '2023-10-30T22:00:00Z',
hasDescription: false,
previewType: 'automatic',
completedDateTime: null,
completedBy: null,
referenceCount: 0,
checklistItemCount: 0,
activeChecklistItemCount: 0,
conversationThreadId: null,
priority: 5,
id: 'lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
createdBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
application: {
displayName: null,
id: '11111-2222-3333-44444',
},
},
appliedCategories: {},
assignments: {
'ba4a422e-bdce-4795-b4b6-579287363f0e': {
'@odata.type': '#microsoft.graph.plannerAssignment',
assignedDateTime: '2023-10-27T03:06:31.9017623Z',
orderHint: '8585032309536070726PE',
assignedBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
application: {
displayName: null,
id: '11111-2222-3333-44444',
},
},
},
},
};
}
});
describe('Test MicrosoftTeamsV2, task => get', () => {
const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/get.workflow.json'];
const tests = workflowToTests(workflows);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.resetAllMocks();
});
const nodeTypes = setup(tests);
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith(
'GET',
'/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
);
expect(result.finished).toEqual(true);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View File

@@ -0,0 +1,139 @@
{
"name": "My workflow 35",
"nodes": [
{
"parameters": {},
"id": "6666-9999-77777",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
880,
380
]
},
{
"parameters": {
"resource": "task",
"operation": "get",
"taskId": "lDrRJ7N_-06p_26iKBtJ6ZgAKffD"
},
"id": "6666-5555-77777",
"name": "Microsoft Teams",
"type": "n8n-nodes-base.microsoftTeams",
"typeVersion": 2,
"position": [
1100,
380
],
"credentials": {
"microsoftTeamsOAuth2Api": {
"id": "6isd5ytvA0qV78eK",
"name": "Microsoft Teams account"
}
}
},
{
"parameters": {},
"id": "9d1a2e59-c71c-486c-b3ac-dec6adbc26b3",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
380
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity",
"@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=\"",
"planId": "THwgIivuyU26ki8qS7ufcJgAB6zf",
"bucketId": "CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m",
"title": "do this",
"orderHint": "8585032308935758184",
"assigneePriority": "",
"percentComplete": 25,
"startDateTime": null,
"createdDateTime": "2023-10-27T03:06:31.9017623Z",
"dueDateTime": "2023-10-30T22:00:00Z",
"hasDescription": false,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"priority": 5,
"id": "lDrRJ7N_-06p_26iKBtJ6ZgAKffD",
"createdBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
},
"application": {
"displayName": null,
"id": "11111-2222-3333-44444"
}
},
"appliedCategories": {},
"assignments": {
"ba4a422e-bdce-4795-b4b6-579287363f0e": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2023-10-27T03:06:31.9017623Z",
"orderHint": "8585032309536070726PE",
"assignedBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
},
"application": {
"displayName": null,
"id": "11111-2222-3333-44444"
}
}
}
}
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Teams",
"type": "main",
"index": 0
}
]
]
},
"Microsoft Teams": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "8147cd45-b1e6-44b3-abd2-232b44102660",
"id": "i3NYGF0LXV4qDFV9",
"meta": {
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"tags": []
}

View File

@@ -0,0 +1,201 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';
import * as transport from '../../../../v2/transport';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
const microsoftApiRequestAllItemsSpy = jest.spyOn(transport, 'microsoftApiRequestAllItems');
microsoftApiRequestAllItemsSpy.mockImplementation(async (_, method: string) => {
if (method === 'GET') {
return [
{
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAZCc="',
planId: 'coJdCqzqNUKULQtTRWDa6pgACTln',
bucketId: null,
title: 'tada',
orderHint: '8585516884147534440',
assigneePriority: '8585516882706975451',
percentComplete: 10,
startDateTime: null,
createdDateTime: '2022-04-14T06:41:10.7241367Z',
dueDateTime: '2022-04-24T21:00:00Z',
hasDescription: false,
previewType: 'automatic',
completedDateTime: null,
completedBy: null,
referenceCount: 0,
checklistItemCount: 0,
activeChecklistItemCount: 0,
conversationThreadId: null,
priority: 5,
id: '1KgwUqOmbU2C9mZWiqxiv5gAPp8Q',
createdBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
},
appliedCategories: {},
assignments: {
'11111-2222-3333': {
'@odata.type': '#microsoft.graph.plannerAssignment',
assignedDateTime: '2022-04-14T06:43:34.7800356Z',
orderHint: '8585516882406130277PO',
assignedBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
},
},
},
},
{
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="',
planId: 'coJdCqzqNUKULQtTRWDa6pgACTln',
bucketId: '2avE1BwPmEKp7Lxh0E-EmZgALF72',
title: '1',
orderHint: '8585516897613076919P1',
assigneePriority: '8585516890164965803',
percentComplete: 0,
startDateTime: null,
createdDateTime: '2022-04-14T06:19:44.2011467Z',
dueDateTime: null,
hasDescription: false,
previewType: 'automatic',
completedDateTime: null,
completedBy: null,
referenceCount: 0,
checklistItemCount: 0,
activeChecklistItemCount: 0,
conversationThreadId: null,
priority: 5,
id: 'J3MLUgtmJ06YJgenyujiYpgANMF1',
createdBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
},
appliedCategories: {},
assignments: {
'11111-2222-3333': {
'@odata.type': '#microsoft.graph.plannerAssignment',
assignedDateTime: '2022-04-14T06:31:08.9810004Z',
orderHint: '8585516890765590890Pw',
assignedBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
},
},
},
},
{
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAVCc="',
planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf',
bucketId: 'CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m',
title: 'td 54',
orderHint: '8585034751365009589',
assigneePriority: '8585034751365009589',
percentComplete: 0,
startDateTime: null,
createdDateTime: '2023-10-24T07:15:48.9766218Z',
dueDateTime: null,
hasDescription: true,
previewType: 'automatic',
completedDateTime: null,
completedBy: null,
referenceCount: 0,
checklistItemCount: 0,
activeChecklistItemCount: 0,
conversationThreadId: null,
priority: 5,
id: 'silreUDQskqFYfrO4EObD5gAKt_G',
createdBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
application: {
displayName: null,
id: '11111-2222-3333-44444',
},
},
appliedCategories: {},
assignments: {
'11111-2222-3333': {
'@odata.type': '#microsoft.graph.plannerAssignment',
assignedDateTime: '2023-10-24T07:15:48.9766218Z',
orderHint: '8585034751965947109Pc',
assignedBy: {
user: {
displayName: null,
id: '11111-2222-3333',
},
application: {
displayName: null,
id: '11111-2222-3333-44444',
},
},
},
},
},
];
}
});
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest');
microsoftApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'GET') {
return {
id: '123456789',
};
}
});
describe('Test MicrosoftTeamsV2, task => getAll', () => {
const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/getAll.workflow.json'];
const tests = workflowToTests(workflows);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.resetAllMocks();
});
const nodeTypes = setup(tests);
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith('GET', '/v1.0/me');
expect(microsoftApiRequestAllItemsSpy).toHaveBeenCalledTimes(1);
expect(microsoftApiRequestAllItemsSpy).toHaveBeenCalledWith(
'value',
'GET',
'/v1.0/users/123456789/planner/tasks',
);
expect(result.finished).toEqual(true);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View File

@@ -0,0 +1,232 @@
{
"name": "My workflow 35",
"nodes": [
{
"parameters": {},
"id": "6666-9999-77777",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
880,
380
]
},
{
"parameters": {
"resource": "task",
"operation": "getAll",
"groupId": {
"__rl": true,
"value": "1644e7fe-547e-4223-a24f-922395865343",
"mode": "list",
"cachedResultName": "5w1hb7"
},
"returnAll": true
},
"id": "6666-5555-77777",
"name": "Microsoft Teams",
"type": "n8n-nodes-base.microsoftTeams",
"typeVersion": 2,
"position": [
1100,
380
],
"credentials": {
"microsoftTeamsOAuth2Api": {
"id": "6isd5ytvA0qV78eK",
"name": "Microsoft Teams account"
}
}
},
{
"parameters": {},
"id": "9d1a2e59-c71c-486c-b3ac-dec6adbc26b3",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
380
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAZCc=\"",
"planId": "coJdCqzqNUKULQtTRWDa6pgACTln",
"bucketId": null,
"title": "tada",
"orderHint": "8585516884147534440",
"assigneePriority": "8585516882706975451",
"percentComplete": 10,
"startDateTime": null,
"createdDateTime": "2022-04-14T06:41:10.7241367Z",
"dueDateTime": "2022-04-24T21:00:00Z",
"hasDescription": false,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"priority": 5,
"id": "1KgwUqOmbU2C9mZWiqxiv5gAPp8Q",
"createdBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
}
},
"appliedCategories": {},
"assignments": {
"11111-2222-3333": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2022-04-14T06:43:34.7800356Z",
"orderHint": "8585516882406130277PO",
"assignedBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
}
}
}
}
}
},
{
"json": {
"@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"",
"planId": "coJdCqzqNUKULQtTRWDa6pgACTln",
"bucketId": "2avE1BwPmEKp7Lxh0E-EmZgALF72",
"title": "1",
"orderHint": "8585516897613076919P1",
"assigneePriority": "8585516890164965803",
"percentComplete": 0,
"startDateTime": null,
"createdDateTime": "2022-04-14T06:19:44.2011467Z",
"dueDateTime": null,
"hasDescription": false,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"priority": 5,
"id": "J3MLUgtmJ06YJgenyujiYpgANMF1",
"createdBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
}
},
"appliedCategories": {},
"assignments": {
"11111-2222-3333": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2022-04-14T06:31:08.9810004Z",
"orderHint": "8585516890765590890Pw",
"assignedBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
}
}
}
}
}
},
{
"json": {
"@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAVCc=\"",
"planId": "THwgIivuyU26ki8qS7ufcJgAB6zf",
"bucketId": "CO-ZsX1s4kO7FtO6ZHZdDpgAFL1m",
"title": "td 54",
"orderHint": "8585034751365009589",
"assigneePriority": "8585034751365009589",
"percentComplete": 0,
"startDateTime": null,
"createdDateTime": "2023-10-24T07:15:48.9766218Z",
"dueDateTime": null,
"hasDescription": true,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"priority": 5,
"id": "silreUDQskqFYfrO4EObD5gAKt_G",
"createdBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
},
"application": {
"displayName": null,
"id": "11111-2222-3333-44444"
}
},
"appliedCategories": {},
"assignments": {
"11111-2222-3333": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2023-10-24T07:15:48.9766218Z",
"orderHint": "8585034751965947109Pc",
"assignedBy": {
"user": {
"displayName": null,
"id": "11111-2222-3333"
},
"application": {
"displayName": null,
"id": "11111-2222-3333-44444"
}
}
}
}
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Teams",
"type": "main",
"index": 0
}
]
]
},
"Microsoft Teams": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "34bcdc66-9dad-4c93-8456-4019f94c2f88",
"id": "i3NYGF0LXV4qDFV9",
"meta": {
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"tags": []
}

View File

@@ -0,0 +1,65 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';
import * as transport from '../../../../v2/transport';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest');
microsoftApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'PATCH') {
return {};
}
if (method === 'GET') {
return {
'@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="',
};
}
});
describe('Test MicrosoftTeamsV2, task => update', () => {
const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/update.workflow.json'];
const tests = workflowToTests(workflows);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.resetAllMocks();
});
const nodeTypes = setup(tests);
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
const { result } = await executeWorkflow(testData, types);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(2);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith(
'GET',
'/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
);
expect(microsoftApiRequestSpy).toHaveBeenCalledWith(
'PATCH',
'/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD',
{ dueDateTime: '2023-10-24T21:00:00.000Z', percentComplete: 78, title: 'do that' },
{},
undefined,
{ 'If-Match': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="' },
);
expect(result.finished).toEqual(true);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View File

@@ -0,0 +1,96 @@
{
"name": "My workflow 35",
"nodes": [
{
"parameters": {},
"id": "6666-9999-77777",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
880,
380
]
},
{
"parameters": {
"resource": "task",
"operation": "update",
"taskId": "lDrRJ7N_-06p_26iKBtJ6ZgAKffD",
"updateFields": {
"dueDateTime": "2023-10-24T21:00:00.000Z",
"percentComplete": 78,
"title": "do that"
}
},
"id": "6666-5555-77777",
"name": "Microsoft Teams",
"type": "n8n-nodes-base.microsoftTeams",
"typeVersion": 2,
"position": [
1100,
380
],
"credentials": {
"microsoftTeamsOAuth2Api": {
"id": "6isd5ytvA0qV78eK",
"name": "Microsoft Teams account"
}
}
},
{
"parameters": {},
"id": "9d1a2e59-c71c-486c-b3ac-dec6adbc26b3",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
380
]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"success": true
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Microsoft Teams",
"type": "main",
"index": 0
}
]
]
},
"Microsoft Teams": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "74d2873c-c1e1-4628-b398-e2a72c6eed9c",
"id": "i3NYGF0LXV4qDFV9",
"meta": {
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"tags": []
}