forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Microsoft Teams Node): Overhaul (n8n-io#7477)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
- Loading branch information
1 parent
44f6ef2
commit 2c146cc
Showing
68 changed files
with
6,288 additions
and
668 deletions.
There are no files selected for viewing
692 changes: 24 additions & 668 deletions
692
packages/nodes-base/nodes/Microsoft/Teams/MicrosoftTeams.node.ts
Large diffs are not rendered by default.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { INodeTypes } from 'n8n-workflow'; | ||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; | ||
import type { WorkflowTestData } from '@test/nodes/types'; | ||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; | ||
|
||
import nock from 'nock'; | ||
|
||
import * as transport from '../../../../v2/transport'; | ||
|
||
const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); | ||
|
||
microsoftApiRequestSpy.mockImplementation(async (method: string) => { | ||
if (method === 'POST') { | ||
return { | ||
'@odata.context': | ||
"https://graph.microsoft.com/v1.0/$metadata#teams('1644e7fe-547e-4223-a24f-922395865343')/channels/$entity", | ||
id: '19:16259efabba44a66916d91dd91862a6f@thread.tacv2', | ||
createdDateTime: '2023-10-26T05:37:43.4798824Z', | ||
displayName: 'New Channel', | ||
description: 'new channel description', | ||
isFavoriteByDefault: null, | ||
email: '', | ||
webUrl: | ||
'https://teams.microsoft.com/l/channel/19%3a16259efabba44a66916d91dd91862a6f%40thread.tacv2/New+Channel?groupId=1644e7fe-547e-4223-a24f-922395865343&tenantId=tenantId-111-222-333', | ||
membershipType: 'private', | ||
}; | ||
} | ||
}); | ||
|
||
describe('Test MicrosoftTeamsV2, channel => create', () => { | ||
const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/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/teams/1644e7fe-547e-4223-a24f-922395865343/channels', | ||
{ | ||
description: 'new channel description', | ||
displayName: 'New Channel', | ||
membershipType: 'private', | ||
}, | ||
); | ||
|
||
expect(result.finished).toEqual(true); | ||
}; | ||
|
||
for (const testData of tests) { | ||
test(testData.description, async () => await testNode(testData, nodeTypes)); | ||
} | ||
}); |
107 changes: 107 additions & 0 deletions
107
packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.workflow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"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": { | ||
"teamId": { | ||
"__rl": true, | ||
"value": "1644e7fe-547e-4223-a24f-922395865343", | ||
"mode": "list", | ||
"cachedResultName": "5w1hb7" | ||
}, | ||
"name": "New Channel", | ||
"options": { | ||
"description": "new channel description", | ||
"type": "private" | ||
} | ||
}, | ||
"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#teams('1644e7fe-547e-4223-a24f-922395865343')/channels/$entity", | ||
"id": "19:16259efabba44a66916d91dd91862a6f@thread.tacv2", | ||
"createdDateTime": "2023-10-26T05:37:43.4798824Z", | ||
"displayName": "New Channel", | ||
"description": "new channel description", | ||
"isFavoriteByDefault": null, | ||
"email": "", | ||
"webUrl": "https://teams.microsoft.com/l/channel/19%3a16259efabba44a66916d91dd91862a6f%40thread.tacv2/New+Channel?groupId=1644e7fe-547e-4223-a24f-922395865343&tenantId=tenantId-111-222-333", | ||
"membershipType": "private" | ||
} | ||
} | ||
] | ||
}, | ||
"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": "ec0b4e3d-2fd7-4fac-90e5-f18ecd620a8f", | ||
"id": "i3NYGF0LXV4qDFV9", | ||
"meta": { | ||
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363" | ||
}, | ||
"tags": [] | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 {}; | ||
} | ||
}); | ||
|
||
describe('Test MicrosoftTeamsV2, channel => deleteChannel', () => { | ||
const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.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( | ||
'DELETE', | ||
'/v1.0/teams/1644e7fe-547e-4223-a24f-922395865343/channels/19:16259efabba44a66916d91dd91862a6f@thread.tacv2', | ||
); | ||
|
||
expect(result.finished).toEqual(true); | ||
}; | ||
|
||
for (const testData of tests) { | ||
test(testData.description, async () => await testNode(testData, nodeTypes)); | ||
} | ||
}); |
102 changes: 102 additions & 0 deletions
102
packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.workflow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"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": { | ||
"operation": "deleteChannel", | ||
"teamId": { | ||
"__rl": true, | ||
"value": "1644e7fe-547e-4223-a24f-922395865343", | ||
"mode": "list", | ||
"cachedResultName": "5w1hb7" | ||
}, | ||
"channelId": { | ||
"__rl": true, | ||
"value": "19:16259efabba44a66916d91dd91862a6f@thread.tacv2", | ||
"mode": "list", | ||
"cachedResultName": "New Channel", | ||
"cachedResultUrl": "https://teams.microsoft.com/l/channel/19%3A16259efabba44a66916d91dd91862a6f%40thread.tacv2/New%20Channel?groupId=1644e7fe-547e-4223-a24f-922395865343&tenantId=tenantId-111-222-333&allowXTenantAccess=False" | ||
} | ||
}, | ||
"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": "fb9028a2-b502-45f1-b907-825e8d754991", | ||
"id": "i3NYGF0LXV4qDFV9", | ||
"meta": { | ||
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363" | ||
}, | ||
"tags": [] | ||
} |
Oops, something went wrong.