From 73e8d76e13934dd80e4ac6c83d2211537e01aba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 1 Apr 2025 10:15:13 +0200 Subject: [PATCH] refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303) --- .../cli/src/load-nodes-and-credentials.ts | 8 +- packages/core/src/constants.ts | 1 + .../__tests__/load-class-in-isolation.test.ts | 4 + .../nodes-loader/load-class-in-isolation.ts | 13 +- .../Airtable/test}/Airtable.node.test.ts | 20 +- .../Airtable/test}/workflow.json | 0 .../nodes/Aws/SES/test/AwsSes.node.test.ts | 7 +- .../__tests__/workflow/workflow.test.ts | 18 +- .../Compression/test/node/Compression.test.ts | 14 +- .../test/v2/node/channel/create.test.ts | 48 +- .../v2/node/channel/deleteChannel.test.ts | 55 +- .../node/channel/deleteChannel.workflow.json | 13 +- .../Discord/test/v2/node/channel/get.test.ts | 119 +--- .../test/v2/node/channel/getAll.test.ts | 47 +- .../test/v2/node/channel/update.test.ts | 73 +- .../test/v2/node/member/getAll.test.ts | 49 +- .../test/v2/node/member/roleAdd.test.ts | 47 +- .../test/v2/node/member/roleRemove.test.ts | 56 +- .../v2/node/message/deleteMessage.test.ts | 47 +- .../Discord/test/v2/node/message/get.test.ts | 47 +- .../test/v2/node/message/getAll.test.ts | 49 +- .../test/v2/node/message/react.test.ts | 47 +- .../Discord/test/v2/node/message/send.test.ts | 70 +- .../test/v2/node/webhook/sendLegacy.test.ts | 62 +- .../test/ExecutionData.node.test.ts | 3 +- .../ReadWriteFile/test/ReadWriteFile.test.ts | 7 +- .../Github/__tests__/Github.node.test.ts | 5 +- .../nodes/Gong/test/Gong.node.test.ts | 78 +-- .../test/v2/node/executeQuery.test.ts | 91 +-- .../test/v2/node/insert.autoMapMode.test.ts | 88 +-- .../test/v2/node/insert.manualMode.test.ts | 86 +-- .../Google/Gmail/test/v1/GmailV1.node.test.ts | 3 - .../Google/Gmail/test/v2/GmailV2.node.test.ts | 2 - .../nodes/GraphQL/test/GraphQL.node.test.ts | 18 +- .../test/binaryData/HttpRequest.test.ts | 17 +- .../test/encoding/HttpRequest.test.ts | 17 +- .../test/encodingQuoted/HttpRequest.test.ts | 17 +- .../HttpRequest/test/node/HttpRequest.test.ts | 17 +- .../ICalendar/test/node/ICalendar.test.ts | 13 +- .../tests/v1/MailerLite.v1.workflow.test.ts | 3 +- .../tests/v2/MailerLite.v2.workflow.test.ts | 3 +- .../nodes/Merge/test/v3/operations.test.ts | 3 +- .../Entra/test/GroupDescription.test.ts | 15 +- .../Entra/test/MicrosoftEntra.node.test.ts | 41 +- .../Entra/test/UserDescription.test.ts | 15 +- .../Excel/test/v2/node/table/addTable.test.ts | 75 +-- .../Excel/test/v2/node/table/append.test.ts | 97 +-- .../test/v2/node/table/convertToRange.test.ts | 67 +- .../test/v2/node/table/deleteTable.test.ts | 51 +- .../test/v2/node/table/getColumns.test.ts | 76 +-- .../Excel/test/v2/node/table/getRows.test.ts | 109 +-- .../Excel/test/v2/node/table/lookup.test.ts | 134 ++-- .../v2/node/workbook/addWorksheet.test.ts | 93 +-- .../v2/node/workbook/deleteWorkbook.test.ts | 49 +- .../test/v2/node/workbook/getAll.test.ts | 73 +- .../test/v2/node/worksheet/append.test.ts | 77 ++- .../test/v2/node/worksheet/clear.test.ts | 61 +- .../v2/node/worksheet/deleteWorksheet.test.ts | 59 +- .../test/v2/node/worksheet/getAll.test.ts | 81 +-- .../test/v2/node/worksheet/readRows.test.ts | 63 +- .../test/v2/node/worksheet/update.test.ts | 101 +-- .../test/v2/node/worksheet/upsert.test.ts | 105 +-- .../test/v2/node/calendar/create.test.ts | 89 +-- .../test/v2/node/calendar/delete.test.ts | 49 +- .../Outlook/test/v2/node/calendar/get.test.ts | 91 +-- .../test/v2/node/calendar/getAll.test.ts | 131 ++-- .../test/v2/node/calendar/update.test.ts | 89 +-- .../test/v2/node/contact/create.test.ts | 132 ++-- .../test/v2/node/contact/update.test.ts | 147 ++--- .../Outlook/test/v2/node/draft/create.test.ts | 225 +++---- .../Outlook/test/v2/node/draft/send.test.ts | 57 +- .../Outlook/test/v2/node/event/create.test.ts | 211 +++--- .../test/v2/node/folder/create.test.ts | 75 +-- .../test/v2/node/folderMessage/getAll.test.ts | 56 +- .../Outlook/test/v2/node/message/move.test.ts | 49 +- .../test/v2/node/message/reply.test.ts | 175 ++--- .../Outlook/test/v2/node/message/send.test.ts | 65 +- .../Storage/test/blob/create.test.ts | 15 +- .../Storage/test/blob/delete.test.ts | 15 +- .../Microsoft/Storage/test/blob/get.test.ts | 15 +- .../Storage/test/blob/getAll.test.ts | 15 +- .../test/blob/getAllLimitOptions.test.ts | 15 +- .../Storage/test/container/create.test.ts | 15 +- .../Storage/test/container/delete.test.ts | 15 +- .../Storage/test/container/get.test.ts | 15 +- .../Storage/test/container/getAll.test.ts | 15 +- .../test/container/getAllLimitOptions.test.ts | 15 +- .../Storage/test/credentials/oauth2.test.ts | 19 +- .../test/credentials/sharedKey.test.ts | 45 +- .../test/listSearch/listSearch.test.ts | 11 +- .../Teams/test/v2/node/channel/create.test.ts | 52 +- .../v2/node/channel/deleteChannel.test.ts | 45 +- .../Teams/test/v2/node/channel/get.test.ts | 49 +- .../Teams/test/v2/node/channel/getAll.test.ts | 121 ++-- .../Teams/test/v2/node/channel/update.test.ts | 45 +- .../v2/node/channelMessage/create.test.ts | 50 +- .../v2/node/channelMessage/getAll.test.ts | 154 ++--- .../test/v2/node/chatMessage/create.test.ts | 48 +- .../test/v2/node/chatMessage/get.test.ts | 47 +- .../test/v2/node/chatMessage/getAll.test.ts | 201 +++--- .../Teams/test/v2/node/task/create.test.ts | 68 +- .../test/v2/node/task/deleteTask.test.ts | 61 +- .../Teams/test/v2/node/task/get.test.ts | 47 +- .../Teams/test/v2/node/task/getAll.test.ts | 331 ++++------ .../Teams/test/v2/node/task/update.test.ts | 65 +- .../test/MoveBinaryData.test.ts | 6 +- .../nodes/MySql/test/v1/executeQuery.test.ts | 39 +- .../nodes/N8n/test/node/N8n.test.ts | 12 +- .../Notion/test/node/v2/block/append.test.ts | 27 +- .../Notion/test/node/v2/block/getAll.test.ts | 426 ++++++------ .../Notion/test/node/v2/database/get.test.ts | 27 +- .../test/node/v2/database/getAll.test.ts | 622 +++++++++--------- .../test/node/v2/database/search.test.ts | 384 ++++++----- .../test/node/v2/databasePage/create.test.ts | 82 +-- .../test/node/v2/databasePage/get.test.ts | 27 +- .../test/node/v2/databasePage/getAll.test.ts | 145 ++-- .../test/node/v2/databasePage/update.test.ts | 29 +- .../Notion/test/node/v2/page/archive.test.ts | 27 +- .../Notion/test/node/v2/page/create.test.ts | 43 +- .../Notion/test/node/v2/page/search.test.ts | 138 ++-- .../Notion/test/node/v2/user/get.test.ts | 27 +- .../Notion/test/node/v2/user/getAll.test.ts | 90 ++- .../test/OpenWeatherMap.test.ts | 12 +- .../nodes/Oura/test/oura.node.test.ts | 12 +- .../Peekalink/test/Peekalink.node.test.ts | 7 +- .../nodes/PhilipsHue/test/workflow.test.ts | 18 +- .../test}/Postgres.node.functions.test.ts | 31 +- .../nodes/Postgres/v1/genericFunctions.ts | 24 +- .../QuickChart/test/QuickChart.node.test.ts | 6 +- .../test/ReadBinaryFile.test.ts | 6 +- .../test/ReadBinaryFiles.test.ts | 6 +- .../RssFeedRead/test/node/RssFeedRead.test.ts | 11 +- .../nodes/SendGrid/test/SendGrid.node.test.ts | 22 +- .../test/v2/node/channel/archive.test.ts | 25 +- .../Slack/test/v2/node/channel/create.test.ts | 46 +- .../Slack/test/v2/node/channel/get.test.ts | 48 +- .../Slack/test/v2/node/channel/getAll.test.ts | 50 +- .../test/v2/node/channel/history.test.ts | 352 +++++----- .../Slack/test/v2/node/file/upload.test.ts | 78 +-- .../test/v2/node/file/upload.workflow.json | 2 +- .../Slack/test/v2/node/message/delete.test.ts | 46 +- .../test/v2/node/message/getPermalink.test.ts | 48 +- .../Slack/test/v2/node/message/post.test.ts | 66 +- .../Slack/test/v2/node/message/search.test.ts | 48 +- .../Slack/test/v2/node/message/update.test.ts | 60 +- .../test/v2/node/user/updateProfile.test.ts | 72 +- .../__tests__/workflow/workflow.test.ts | 18 +- .../test/SpreadsheetFile.test.ts | 7 +- .../Start/__tests__}/StartNode.test.ts | 10 +- .../test/node/StopAndError.test.ts | 8 +- .../Stripe/__tests__}/helpers.test.ts | 2 +- .../Telegram/tests/Workflow/workflow.test.ts | 5 +- .../nodes/Totp/test/Totp.node.test.ts | 7 +- .../test/WriteBinaryFile.test.ts | 6 +- .../nodes-base/test/nodes/ExecuteWorkflow.ts | 35 +- .../test/nodes/FakeCredentialsMap.ts | 15 + packages/nodes-base/test/nodes/Helpers.ts | 234 +------ .../nodes-base/test/nodes/credential-types.ts | 25 + .../test/nodes/credentials-helper.ts | 82 +++ .../test/nodes/load-nodes-and-credentials.ts | 39 ++ packages/nodes-base/test/nodes/node-types.ts | 23 + packages/nodes-base/test/nodes/types.ts | 3 - packages/nodes-base/tsconfig.json | 2 + .../__tests__}/utilities.test.ts | 0 packages/workflow/src/Interfaces.ts | 5 + 165 files changed, 3397 insertions(+), 6453 deletions(-) rename packages/nodes-base/{test/nodes/Airtable => nodes/Airtable/test}/Airtable.node.test.ts (56%) rename packages/nodes-base/{test/nodes/Airtable => nodes/Airtable/test}/workflow.json (100%) rename packages/nodes-base/{test/nodes/Postgres => nodes/Postgres/test}/Postgres.node.functions.test.ts (85%) rename packages/nodes-base/{test/nodes/Start => nodes/Start/__tests__}/StartNode.test.ts (82%) rename packages/nodes-base/{test/nodes/Stripe => nodes/Stripe/__tests__}/helpers.test.ts (90%) create mode 100644 packages/nodes-base/test/nodes/credential-types.ts create mode 100644 packages/nodes-base/test/nodes/credentials-helper.ts create mode 100644 packages/nodes-base/test/nodes/load-nodes-and-credentials.ts create mode 100644 packages/nodes-base/test/nodes/node-types.ts delete mode 100644 packages/nodes-base/test/nodes/types.ts rename packages/nodes-base/{test/utils => utils/__tests__}/utilities.test.ts (100%) diff --git a/packages/cli/src/load-nodes-and-credentials.ts b/packages/cli/src/load-nodes-and-credentials.ts index 1a7bd2a355..247941cd54 100644 --- a/packages/cli/src/load-nodes-and-credentials.ts +++ b/packages/cli/src/load-nodes-and-credentials.ts @@ -18,13 +18,12 @@ import type { KnownNodesAndCredentials, INodeTypeBaseDescription, INodeTypeDescription, - INodeTypeData, - ICredentialTypeData, LoadedClass, ICredentialType, INodeType, IVersionedNodeType, INodeProperties, + LoadedNodesAndCredentials, } from 'n8n-workflow'; import { deepCopy, NodeConnectionTypes, UnexpectedError, UserError } from 'n8n-workflow'; import path from 'path'; @@ -39,11 +38,6 @@ import { } from '@/constants'; import { isContainedWithin } from '@/utils/path-util'; -interface LoadedNodesAndCredentials { - nodes: INodeTypeData; - credentials: ICredentialTypeData; -} - @Service() export class LoadNodesAndCredentials { private known: KnownNodesAndCredentials = { nodes: {}, credentials: {} }; diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index bd44e25d10..d69b3f9170 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -1,6 +1,7 @@ const { NODE_ENV } = process.env; export const inProduction = NODE_ENV === 'production'; export const inDevelopment = !NODE_ENV || NODE_ENV === 'development'; +export const inTest = NODE_ENV === 'test'; export const CUSTOM_EXTENSION_ENV = 'N8N_CUSTOM_EXTENSIONS'; export const PLACEHOLDER_EMPTY_EXECUTION_ID = '__UNKNOWN__'; diff --git a/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts b/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts index 656830fa87..8640baf670 100644 --- a/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts +++ b/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts @@ -2,6 +2,10 @@ import vm from 'vm'; import { loadClassInIsolation } from '../load-class-in-isolation'; +jest.mock('@/constants', () => ({ + inTest: false, +})); + describe('loadClassInIsolation', () => { const filePath = '/path/to/TestClass.js'; const className = 'TestClass'; diff --git a/packages/core/src/nodes-loader/load-class-in-isolation.ts b/packages/core/src/nodes-loader/load-class-in-isolation.ts index 4c7dd6ec22..a4157cf263 100644 --- a/packages/core/src/nodes-loader/load-class-in-isolation.ts +++ b/packages/core/src/nodes-loader/load-class-in-isolation.ts @@ -1,10 +1,19 @@ import { createContext, Script } from 'vm'; +import { inTest } from '@/constants'; + const context = createContext({ require }); export const loadClassInIsolation = (filePath: string, className: string) => { if (process.platform === 'win32') { filePath = filePath.replace(/\\/g, '/'); } - const script = new Script(`new (require('${filePath}').${className})()`); - return script.runInContext(context) as T; + + // Note: Skip the isolation because it breaks nock mocks in tests + if (inTest) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access + return new (require(filePath)[className])() as T; + } else { + const script = new Script(`new (require('${filePath}').${className})()`); + return script.runInContext(context) as T; + } }; diff --git a/packages/nodes-base/test/nodes/Airtable/Airtable.node.test.ts b/packages/nodes-base/nodes/Airtable/test/Airtable.node.test.ts similarity index 56% rename from packages/nodes-base/test/nodes/Airtable/Airtable.node.test.ts rename to packages/nodes-base/nodes/Airtable/test/Airtable.node.test.ts index bb200851a0..9037e09af5 100644 --- a/packages/nodes-base/test/nodes/Airtable/Airtable.node.test.ts +++ b/packages/nodes-base/nodes/Airtable/test/Airtable.node.test.ts @@ -1,8 +1,8 @@ +import type { WorkflowTestData } from 'n8n-workflow'; import nock from 'nock'; -import { executeWorkflow } from '../ExecuteWorkflow'; -import * as Helpers from '../Helpers'; -import type { WorkflowTestData } from '../types'; +import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; +import * as Helpers from '@test/nodes/Helpers'; const records = [ { @@ -26,7 +26,7 @@ describe('Execute Airtable Node', () => { { description: 'List Airtable Records', input: { - workflowData: Helpers.readJsonFileSync('test/nodes/Airtable/workflow.json'), + workflowData: Helpers.readJsonFileSync('nodes/Airtable/test/workflow.json'), }, output: { nodeData: { @@ -36,19 +36,9 @@ describe('Execute Airtable Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - try { - // execute workflow - await executeWorkflow(testData, nodeTypes); - } catch (error) { - expect(error).toBeUndefined(); - expect(error.message).toEqual( - 'The API Key connection was deprecated by Airtable, please use Access Token or OAuth2 instead.', - ); - } + await executeWorkflow(testData); }); } }); diff --git a/packages/nodes-base/test/nodes/Airtable/workflow.json b/packages/nodes-base/nodes/Airtable/test/workflow.json similarity index 100% rename from packages/nodes-base/test/nodes/Airtable/workflow.json rename to packages/nodes-base/nodes/Airtable/test/workflow.json diff --git a/packages/nodes-base/nodes/Aws/SES/test/AwsSes.node.test.ts b/packages/nodes-base/nodes/Aws/SES/test/AwsSes.node.test.ts index 7cd4271f12..a28fc97528 100644 --- a/packages/nodes-base/nodes/Aws/SES/test/AwsSes.node.test.ts +++ b/packages/nodes-base/nodes/Aws/SES/test/AwsSes.node.test.ts @@ -1,10 +1,9 @@ -import { NodeConnectionTypes } from 'n8n-workflow'; +import { NodeConnectionTypes, type WorkflowTestData } from 'n8n-workflow'; import assert from 'node:assert'; import qs from 'node:querystring'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('AwsSes Node', () => { const email = 'test+user@example.com'; @@ -170,10 +169,8 @@ describe('AwsSes Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => expect(resultData).toEqual(testData.output.nodeData[nodeName]), diff --git a/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts b/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts index 7d6863153f..2cf847ad01 100644 --- a/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts +++ b/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts @@ -1,5 +1,7 @@ import nock from 'nock'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { createResponse, fieldsResponse, @@ -7,18 +9,9 @@ import { getResponse, updateResponse, } from './apiResponses'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, -} from '../../../../test/nodes/Helpers'; describe('Baserow > Workflows', () => { describe('Run workflow', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { const mock = nock('https://api.baserow.io'); // Baserow > Get Token @@ -54,10 +47,7 @@ describe('Baserow > Workflows', () => { mock.delete('/api/database/rows/table/482710/3/').reply(200, {}); }); - const nodeTypes = setup(tests); - - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts b/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts index a83d793eba..3c66af9ffb 100644 --- a/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts +++ b/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts @@ -1,16 +1,10 @@ /* eslint-disable @typescript-eslint/no-loop-func */ -import type { IDataObject } from 'n8n-workflow'; +import type { IDataObject, WorkflowTestData } from 'n8n-workflow'; import os from 'node:os'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { - getResultNodeData, - setup, - initBinaryDataService, - readJsonFileSync, -} from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { getResultNodeData, initBinaryDataService, readJsonFileSync } from '@test/nodes/Helpers'; if (os.platform() !== 'win32') { describe('Execute Compression Node', () => { @@ -53,11 +47,9 @@ if (os.platform() !== 'win32') { }, ]; - const nodeTypes = setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/create.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/channel/create.test.ts index 39fbf2f528..20088d7a9c 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/create.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/create.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test DiscordV2, channel => create', () => { + nock('https://discord.com/api/v10') + .post('/guilds/1168516062791340136/channels', { name: 'third', type: '0' }) + .reply(200, { id: '1168528323006181417', type: 0, last_message_id: null, @@ -23,35 +18,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { position: 3, permission_overwrites: [], nsfw: false, - }; - } -}); - -describe('Test DiscordV2, channel => create', () => { - const workflows = ['nodes/Discord/test/v2/node/channel/create.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'POST', - '/guilds/1168516062791340136/channels', - { name: 'third', type: '0' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Discord/test/v2/node/channel/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.test.ts index 9655bd13ab..5e4849f9b8 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.test.ts @@ -1,53 +1,12 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'DELETE') { - return { - id: '1168528323006181417', - type: 0, - last_message_id: null, - flags: 0, - guild_id: '1168516062791340136', - name: 'third', - parent_id: null, - rate_limit_per_user: 0, - topic: null, - position: 3, - permission_overwrites: [], - nsfw: false, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, channel => deleteChannel', () => { + nock('https://discord.com/api/v10') + .delete('/channels/1168528323006181417') + .reply(200, { success: true }); + const workflows = ['nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith('DELETE', '/channels/1168528323006181417'); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json b/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json index 051f3ff02d..c8ad2916a9 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json @@ -61,18 +61,7 @@ "No Operation, do nothing": [ { "json": { - "id": "1168528323006181417", - "type": 0, - "last_message_id": null, - "flags": 0, - "guild_id": "1168516062791340136", - "name": "third", - "parent_id": null, - "rate_limit_per_user": 0, - "topic": null, - "position": 3, - "permission_overwrites": [], - "nsfw": false + "success": true } } ] diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/get.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/channel/get.test.ts index d59488deda..e8768e2039 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/get.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/get.test.ts @@ -1,103 +1,28 @@ -import type { INodeTypes, IRequestOptions } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/helpers'; - -// TODO: use nock -const requestApiSpy = jest.spyOn(transport, 'requestApi'); - -requestApiSpy.mockImplementation( - async (_options: IRequestOptions, _credentialType: string, endpoint: string) => { - if (endpoint === '/users/@me/guilds') { - return { - headers: {}, - body: [ - { - id: '1168516062791340136', - }, - ], - }; - } else { - return { - headers: {}, - body: { - id: '1168516240332034067', - type: 0, - last_message_id: null, - flags: 0, - guild_id: '1168516062791340136', - name: 'first', - parent_id: '1168516063340789831', - rate_limit_per_user: 0, - topic: null, - position: 1, - permission_overwrites: [], - nsfw: false, - }, - }; - } - }, -); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, channel => get', () => { - const workflows = ['nodes/Discord/test/v2/node/channel/get.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://discord.com/api/v10') + .persist() + .get('/users/@me/guilds') + .reply(200, [{ id: '1168516062791340136' }]) + .get('/channels/1168516240332034067') + .reply(200, { + id: '1168516240332034067', + type: 0, + last_message_id: null, + flags: 0, + guild_id: '1168516062791340136', + name: 'first', + parent_id: '1168516063340789831', + rate_limit_per_user: 0, + topic: null, + position: 1, + permission_overwrites: [], + nsfw: false, }); - expect(requestApiSpy).toHaveBeenCalledTimes(3); - expect(requestApiSpy).toHaveBeenCalledWith( - { - body: undefined, - headers: {}, - json: true, - method: 'GET', - qs: undefined, - url: 'https://discord.com/api/v10/users/@me/guilds', - }, - 'discordOAuth2Api', - '/users/@me/guilds', - ); - expect(requestApiSpy).toHaveBeenCalledWith( - { - body: undefined, - headers: {}, - json: true, - method: 'GET', - qs: undefined, - url: 'https://discord.com/api/v10/channels/1168516240332034067', - }, - 'discordOAuth2Api', - '/channels/1168516240332034067', - ); - expect(requestApiSpy).toHaveBeenCalledWith( - { - body: undefined, - headers: {}, - json: true, - method: 'GET', - qs: undefined, - url: 'https://discord.com/api/v10/channels/1168516240332034067', - }, - 'discordOAuth2Api', - '/channels/1168516240332034067', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Discord/test/v2/node/channel/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/getAll.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/channel/getAll.test.ts index 8cfb777b56..2b8b58bc9e 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/getAll.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/getAll.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return [ +describe('Test DiscordV2, channel => getAll', () => { + nock('https://discord.com/api/v10') + .get('/guilds/1168516062791340136/channels') + .reply(200, [ { id: '1168516063340789831', type: 4, @@ -99,34 +94,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { permission_overwrites: [], nsfw: false, }, - ]; - } -}); + ]); -describe('Test DiscordV2, channel => getAll', () => { const workflows = ['nodes/Discord/test/v2/node/channel/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'GET', - '/guilds/1168516062791340136/channels', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/channel/update.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/channel/update.test.ts index 4c01a1bb99..2a8c83fac3 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/channel/update.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/channel/update.test.ts @@ -1,60 +1,23 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string, _) => { - if (method === 'PATCH') { - return { - id: '1168516240332034067', - type: 0, - last_message_id: null, - flags: 0, - guild_id: '1168516062791340136', - name: 'first-channel', - parent_id: '1168516063340789831', - rate_limit_per_user: 30, - topic: 'This is channel topic', - position: 3, - permission_overwrites: [], - nsfw: true, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, channel => update', () => { + nock('https://discord.com/api/v10').patch('/channels/1168516240332034067').reply(200, { + id: '1168516240332034067', + type: 0, + last_message_id: null, + flags: 0, + guild_id: '1168516062791340136', + name: 'first-channel', + parent_id: '1168516063340789831', + rate_limit_per_user: 30, + topic: 'This is channel topic', + position: 3, + permission_overwrites: [], + nsfw: true, + }); + const workflows = ['nodes/Discord/test/v2/node/channel/update.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith('PATCH', '/channels/1168516240332034067', { - name: 'First Channel', - nsfw: true, - parent_id: '1168516063340789831', - position: 3, - rate_limit_per_user: 30, - topic: 'This is channel topic', - }); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/member/getAll.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/member/getAll.test.ts index 9b92bc3d5a..89473586c7 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/member/getAll.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/member/getAll.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return [ +describe('Test DiscordV2, member => getAll', () => { + nock('https://discord.com/api/v10') + .get('/guilds/1168516062791340136/members?limit=2') + .reply(200, [ { user: { id: '470936827994570762', @@ -46,36 +41,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { }, roles: ['1168518368526077992'], }, - ]; - } -}); + ]); -describe('Test DiscordV2, member => getAll', () => { const workflows = ['nodes/Discord/test/v2/node/member/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'GET', - '/guilds/1168516062791340136/members', - undefined, - { limit: 2 }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/member/roleAdd.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/member/roleAdd.test.ts index 2b06ebed3e..5d0bbd2ff5 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/member/roleAdd.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/member/roleAdd.test.ts @@ -1,45 +1,12 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'PUT') { - return { - success: true, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, member => roleAdd', () => { + nock('https://discord.com/api/v10') + .put('/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890') + .reply(200, { success: true }); + const workflows = ['nodes/Discord/test/v2/node/member/roleAdd.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'PUT', - '/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/member/roleRemove.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/member/roleRemove.test.ts index d338a064b3..6fe2ea8bca 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/member/roleRemove.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/member/roleRemove.test.ts @@ -1,53 +1,13 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'DELETE') { - return { - success: true, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, member => roleRemove', () => { + nock('https://discord.com/api/v10') + .persist() + .delete(/\/guilds\/1168516062791340136\/members\/470936827994570762\/roles\/\d+/) + .reply(200, { success: true }); + const workflows = ['nodes/Discord/test/v2/node/member/roleRemove.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(3); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'DELETE', - '/guilds/1168516062791340136/members/470936827994570762/roles/1168773588963299428', - ); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'DELETE', - '/guilds/1168516062791340136/members/470936827994570762/roles/1168773645800308756', - ); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'DELETE', - '/guilds/1168516062791340136/members/470936827994570762/roles/1168772374540320890', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/message/deleteMessage.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/message/deleteMessage.test.ts index 746738fbd0..2aea6c7f48 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/message/deleteMessage.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/message/deleteMessage.test.ts @@ -1,45 +1,12 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'DELETE') { - return { - success: true, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, message => deleteMessage', () => { + nock('https://discord.com/api/v10') + .delete('/channels/1168516240332034067/messages/1168776343194972210') + .reply(200, { success: true }); + const workflows = ['nodes/Discord/test/v2/node/message/deleteMessage.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'DELETE', - '/channels/1168516240332034067/messages/1168776343194972210', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/message/get.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/message/get.test.ts index 67122f1aa1..25c0d321f0 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/message/get.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/message/get.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return { +describe('Test DiscordV2, message => get', () => { + nock('https://discord.com/api/v10') + .get('/channels/1168516240332034067/messages/1168777380144369718') + .reply(200, { id: '1168777380144369718', channel_id: '1168516240332034067', author: { @@ -31,34 +26,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { content: 'msg 3', timestamp: '2023-10-31T05:04:02.260000+00:00', type: 0, - }; - } -}); - -describe('Test DiscordV2, message => get', () => { - const workflows = ['nodes/Discord/test/v2/node/message/get.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'GET', - '/channels/1168516240332034067/messages/1168777380144369718', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Discord/test/v2/node/message/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/message/getAll.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/message/getAll.test.ts index c679a296c7..a98b995c99 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/message/getAll.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/message/getAll.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return [ +describe('Test DiscordV2, message => getAll', () => { + nock('https://discord.com/api/v10') + .get('/channels/1168516240332034067/messages?limit=1') + .reply(200, [ { id: '1168784010269433998', type: 0, @@ -54,36 +49,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { flags: 0, components: [], }, - ]; - } -}); + ]); -describe('Test DiscordV2, message => getAll', () => { const workflows = ['nodes/Discord/test/v2/node/message/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'GET', - '/channels/1168516240332034067/messages', - undefined, - { limit: 1 }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/message/react.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/message/react.test.ts index 56ec34e42b..1823ca0858 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/message/react.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/message/react.test.ts @@ -1,45 +1,12 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'PUT') { - return { - success: true, - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, message => react', () => { + nock('https://discord.com/api/v10') + .put('/channels/1168516240332034067/messages/1168777380144369718/reactions/%F0%9F%98%80/@me') + .reply(200, { success: true }); + const workflows = ['nodes/Discord/test/v2/node/message/react.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'PUT', - '/channels/1168516240332034067/messages/1168777380144369718/reactions/%F0%9F%98%80/@me', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/message/send.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/message/send.test.ts index 484be92f3b..8757806170 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/message/send.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/message/send.test.ts @@ -1,16 +1,22 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test DiscordV2, message => send', () => { + nock('https://discord.com/api/v10') + .post('/channels/1168516240332034067/messages', { + content: 'msg 4', + embeds: [ + { + author: { name: 'Me' }, + color: 2112935, + description: 'description', + timestamp: '2023-10-30T22:00:00.000Z', + title: 'Some Title', + }, + ], + }) + .reply(200, { id: '1168784010269433998', type: 0, content: 'msg 4', @@ -53,46 +59,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { flags: 0, components: [], referenced_message: null, - }; - } -}); - -describe('Test DiscordV2, message => send', () => { - const workflows = ['nodes/Discord/test/v2/node/message/send.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'POST', - '/channels/1168516240332034067/messages', - { - content: 'msg 4', - embeds: [ - { - author: { name: 'Me' }, - color: 2112935, - description: 'description', - timestamp: '2023-10-30T22:00:00.000Z', - title: 'Some Title', - }, - ], - }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Discord/test/v2/node/message/send.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Discord/test/v2/node/webhook/sendLegacy.test.ts b/packages/nodes-base/nodes/Discord/test/v2/node/webhook/sendLegacy.test.ts index 44a7113259..58b59c3972 100644 --- a/packages/nodes-base/nodes/Discord/test/v2/node/webhook/sendLegacy.test.ts +++ b/packages/nodes-base/nodes/Discord/test/v2/node/webhook/sendLegacy.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport/discord.api'; - -const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest'); - -discordApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test DiscordV2, webhook => sendLegacy', () => { + nock('https://discord.com') + .post('/webhook?wait=true') + .reply(200, { id: '1168768986385747999', type: 0, content: 'TEST Message', @@ -47,49 +42,8 @@ discordApiRequestSpy.mockImplementation(async (method: string) => { flags: 4096, components: [], webhook_id: '1153265494955135077', - }; - } -}); - -describe('Test DiscordV2, webhook => sendLegacy', () => { - const workflows = ['nodes/Discord/test/v2/node/webhook/sendLegacy.workflow.json']; - const tests = workflowToTests(workflows); - 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(discordApiRequestSpy).toHaveBeenCalledTimes(1); - expect(discordApiRequestSpy).toHaveBeenCalledWith( - 'POST', - '', - { - content: 'TEST Message', - embeds: [ - { - author: { name: 'Michael' }, - color: 10930459, - description: 'some description', - timestamp: '2023-10-17T21:00:00.000Z', - }, - ], - flags: 4096, - tts: true, - username: 'TEST_USER', - }, - { wait: true }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Discord/test/v2/node/webhook/sendLegacy.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/ExecutionData/test/ExecutionData.node.test.ts b/packages/nodes-base/nodes/ExecutionData/test/ExecutionData.node.test.ts index 19496b5de0..25c361eca7 100644 --- a/packages/nodes-base/nodes/ExecutionData/test/ExecutionData.node.test.ts +++ b/packages/nodes-base/nodes/ExecutionData/test/ExecutionData.node.test.ts @@ -1,7 +1,8 @@ import { mock } from 'jest-mock-extended'; import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; -import { testWorkflows, getWorkflowFilenames } from '../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + import { ExecutionData } from '../ExecutionData.node'; describe('ExecutionData Node', () => { diff --git a/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts b/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts index b4ae9971b3..4879a62ddf 100644 --- a/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts +++ b/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; + import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test ReadWriteFile Node', () => { beforeEach(async () => { @@ -84,11 +85,9 @@ describe('Test ReadWriteFile Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { diff --git a/packages/nodes-base/nodes/Github/__tests__/Github.node.test.ts b/packages/nodes-base/nodes/Github/__tests__/Github.node.test.ts index 11f55cb7f0..5700a424aa 100644 --- a/packages/nodes-base/nodes/Github/__tests__/Github.node.test.ts +++ b/packages/nodes-base/nodes/Github/__tests__/Github.node.test.ts @@ -62,9 +62,9 @@ describe('Test Github Node', () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); await initBinaryDataService(); }); + beforeEach(async () => { const baseUrl = 'https://api.github.com'; - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -83,9 +83,6 @@ describe('Test Github Node', () => { .reply(200, {}); }); - afterEach(() => { - nock.cleanAll(); - }); testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts b/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts index d7c35f802a..9251a002c8 100644 --- a/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts +++ b/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts @@ -2,27 +2,19 @@ import type { ICredentialDataDecryptedObject, IDataObject, IHttpRequestOptions, + WorkflowTestData, } from 'n8n-workflow'; import { NodeConnectionTypes } from 'n8n-workflow'; -import nock from 'nock'; +import { CredentialsHelper } from '@test/nodes/credentials-helper'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; import { gongApiResponse, gongNodeResponse } from './mocks'; -import { FAKE_CREDENTIALS_DATA } from '../../../test/nodes/FakeCredentialsMap'; describe('Gong Node', () => { const baseUrl = 'https://api.gong.io'; - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('Credentials', () => { const tests: WorkflowTestData[] = [ { @@ -121,12 +113,39 @@ describe('Gong Node', () => { ], }, }, + nock: { + baseUrl, + mocks: [ + { + method: 'post', + path: '/v2/calls/extensive', + requestBody: { filter: { callIds: ['7782342274025937895'] } }, + statusCode: 200, + responseBody: { + ...gongApiResponse.postCallsExtensive, + records: {}, + calls: [{ metaData: gongApiResponse.postCallsExtensive.calls[0].metaData }], + }, + }, + { + method: 'post', + path: '/v2/calls/extensive', + requestBody: { filter: { callIds: ['7782342274025937896'] } }, + statusCode: 200, + responseBody: { + ...gongApiResponse.postCallsExtensive, + records: {}, + calls: [{ metaData: gongApiResponse.postCallsExtensive.calls[0].metaData }], + }, + }, + ], + }, }, ]; beforeAll(() => { jest - .spyOn(Helpers.CredentialsHelper.prototype, 'authenticate') + .spyOn(CredentialsHelper.prototype, 'authenticate') .mockImplementation( async ( credentials: ICredentialDataDecryptedObject, @@ -159,35 +178,8 @@ describe('Gong Node', () => { ); }); - nock(baseUrl) - .post('/v2/calls/extensive', { filter: { callIds: ['7782342274025937895'] } }) - .matchHeader( - 'authorization', - 'basic ' + - Buffer.from( - `${FAKE_CREDENTIALS_DATA.gongApi.accessKey}:${FAKE_CREDENTIALS_DATA.gongApi.accessKeySecret}`, - ).toString('base64'), - ) - .reply(200, { - ...gongApiResponse.postCallsExtensive, - records: {}, - calls: [{ metaData: gongApiResponse.postCallsExtensive.calls[0].metaData }], - }) - .post('/v2/calls/extensive', { filter: { callIds: ['7782342274025937896'] } }) - .matchHeader( - 'authorization', - 'bearer ' + FAKE_CREDENTIALS_DATA.gongOAuth2Api.oauthTokenData.access_token, - ) - .reply(200, { - ...gongApiResponse.postCallsExtensive, - records: {}, - calls: [{ metaData: gongApiResponse.postCallsExtensive.calls[0].metaData }], - }); - - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => expect(resultData).toEqual(testData.output.nodeData[nodeName]), @@ -780,10 +772,8 @@ describe('Gong Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); if (testData.description === 'should handle error response') { // Only matches error message @@ -1051,10 +1041,8 @@ describe('Gong Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); if (testData.description === 'should handle error response') { expect(() => Helpers.getResultNodeData(result, testData)).toThrow( diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts index 616260f8b5..ba3559430e 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts @@ -1,67 +1,42 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../v2/transport'; - -jest.mock('../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../v2/transport'); - return { - ...originalModule, - googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { - if (resource === '/v2/projects/test-project/jobs' && method === 'POST') { - return { - jobReference: { - jobId: 'job_123', - }, - status: { - state: 'DONE', - }, - }; - } - if (resource === '/v2/projects/test-project/queries/job_123' && method === 'GET') { - return {}; - } - }), - googleBigQueryApiRequestAllItems: jest.fn(async () => ({ rows: [], schema: {} })), - }; -}); +jest.mock('jsonwebtoken', () => ({ + sign: jest.fn().mockReturnValue('signature'), +})); describe('Test Google BigQuery V2, executeQuery', () => { - const workflows = ['nodes/Google/BigQuery/test/v2/node/executeQuery.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://oauth2.googleapis.com') + .persist() + .post( + '/token', + 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=signature', + ) + .reply(200, { access_token: 'token' }); - const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { - const { result } = await executeWorkflow(testData, types); - - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(1); - expect(transport.googleBigQueryApiRequestAllItems).toHaveBeenCalledTimes(1); - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( - 'POST', - '/v2/projects/test-project/jobs', - { - configuration: { - query: { - query: 'SELECT * FROM bigquery_node_dev_test_dataset.test_json;', - useLegacySql: false, - }, + nock('https://bigquery.googleapis.com/bigquery') + .post('/v2/projects/test-project/jobs', { + configuration: { + query: { + query: 'SELECT * FROM bigquery_node_dev_test_dataset.test_json;', + useLegacySql: false, }, }, - ); - expect(transport.googleBigQueryApiRequestAllItems).toHaveBeenCalledWith( - 'GET', - '/v2/projects/test-project/queries/job_123', - undefined, - { location: undefined, maxResults: 1000, timeoutMs: 10000 }, - ); + }) + .reply(200, { + jobReference: { + jobId: 'job_123', + }, + status: { + state: 'DONE', + }, + }) + .get('/v2/projects/test-project/queries/job_123') + .reply(200) + .get('/v2/projects/test-project/queries/job_123?maxResults=1000&timeoutMs=10000') + .reply(200, { rows: [], schema: {} }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Google/BigQuery/test/v2/node/executeQuery.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts index 6b282c6bae..f7b0cd3dae 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts @@ -1,58 +1,31 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../v2/transport'; - -jest.mock('../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../v2/transport'); - return { - ...originalModule, - googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { - if ( - resource === - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text' && - method === 'GET' - ) { - return { - schema: { - fields: [ - { name: 'id', type: 'INT' }, - { name: 'test', type: 'STRING' }, - ], - }, - }; - } - if ( - resource === - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text/insertAll' && - method === 'POST' - ) { - return { kind: 'bigquery#tableDataInsertAllResponse' }; - } - }), - googleApiRequestAllItems: jest.fn(async () => {}), - }; -}); +jest.mock('jsonwebtoken', () => ({ + sign: jest.fn().mockReturnValue('signature'), +})); describe('Test Google BigQuery V2, insert auto map', () => { - const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://oauth2.googleapis.com') + .persist() + .post( + '/token', + 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=signature', + ) + .reply(200, { access_token: 'token' }); - const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { - const { result } = await executeWorkflow(testData, types); - - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(2); - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( - 'GET', - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text', - {}, - ); - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://bigquery.googleapis.com/bigquery') + .get('/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text') + .reply(200, { + schema: { + fields: [ + { name: 'id', type: 'INT' }, + { name: 'test', type: 'STRING' }, + ], + }, + }) + .post( '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text/insertAll', { rows: [ @@ -62,12 +35,13 @@ describe('Test Google BigQuery V2, insert auto map', () => { ], traceId: 'trace_id', }, - ); + ) + .reply(200, [ + { kind: 'bigquery#tableDataInsertAllResponse' }, + { kind: 'bigquery#tableDataInsertAllResponse' }, + { kind: 'bigquery#tableDataInsertAllResponse' }, + ]); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts index b9bf456526..91bead8485 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts @@ -1,70 +1,40 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../v2/transport'; - -jest.mock('../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../v2/transport'); - return { - ...originalModule, - googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { - if ( - resource === - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json' && - method === 'GET' - ) { - return { - schema: { - fields: [ - { name: 'json', type: 'JSON' }, - { name: 'name with space', type: 'STRING' }, - { name: 'active', type: 'BOOLEAN' }, - ], - }, - }; - } - if ( - resource === - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json/insertAll' && - method === 'POST' - ) { - return { kind: 'bigquery#tableDataInsertAllResponse' }; - } - }), - googleApiRequestAllItems: jest.fn(async () => {}), - }; -}); +jest.mock('jsonwebtoken', () => ({ + sign: jest.fn().mockReturnValue('signature'), +})); describe('Test Google BigQuery V2, insert define manually', () => { - const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.manualMode.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://oauth2.googleapis.com') + .persist() + .post( + '/token', + 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=signature', + ) + .reply(200, { access_token: 'token' }); - const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { - const { result } = await executeWorkflow(testData, types); - - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(2); - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( - 'GET', - '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json', - {}, - ); - expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://bigquery.googleapis.com/bigquery') + .get('/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json') + .reply(200, { + schema: { + fields: [ + { name: 'json', type: 'JSON' }, + { name: 'name with space', type: 'STRING' }, + { name: 'active', type: 'BOOLEAN' }, + ], + }, + }) + .post( '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json/insertAll', { rows: [{ json: { active: 'true', json: '{"test": 1}', 'name with space': 'some name' } }], traceId: 'trace_id', }, - ); + ) + .reply(200, [{ kind: 'bigquery#tableDataInsertAllResponse' }]); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.manualMode.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v1/GmailV1.node.test.ts b/packages/nodes-base/nodes/Google/Gmail/test/v1/GmailV1.node.test.ts index 7c9790a4c2..7a545400e4 100644 --- a/packages/nodes-base/nodes/Google/Gmail/test/v1/GmailV1.node.test.ts +++ b/packages/nodes-base/nodes/Google/Gmail/test/v1/GmailV1.node.test.ts @@ -12,12 +12,9 @@ describe('Test Gmail Node v1', () => { jest .useFakeTimers({ doNotFake: ['setImmediate', 'nextTick'] }) .setSystemTime(new Date('2024-12-16 12:34:56.789Z')); - - nock.disableNetConnect(); }); afterAll(() => { - nock.restore(); jest.resetAllMocks(); }); diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts b/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts index a6e6543dcb..1b8e384cc4 100644 --- a/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts @@ -14,8 +14,6 @@ describe('Test Gmail Node v2', () => { jest .useFakeTimers({ doNotFake: ['setImmediate', 'nextTick'] }) .setSystemTime(new Date('2024-12-16 12:34:56.789Z')); - - nock.disableNetConnect(); }); describe('Messages', () => { diff --git a/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts b/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts index 460e9ebcf8..8ed847d91d 100644 --- a/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts +++ b/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts @@ -1,18 +1,9 @@ /* eslint-disable n8n-nodes-base/node-filename-against-convention */ import nock from 'nock'; -import { - equalityTest, - getWorkflowFilenames, - initBinaryDataService, - setup, - workflowToTests, -} from '@test/nodes/Helpers'; +import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; describe('GraphQL Node', () => { - const workflows = getWorkflowFilenames(__dirname); - const workflowTests = workflowToTests(workflows); - const baseUrl = 'https://api.n8n.io/'; beforeAll(async () => { @@ -69,9 +60,6 @@ describe('GraphQL Node', () => { }); }); - const nodeTypes = setup(workflowTests); - - for (const workflow of workflowTests) { - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts b/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts index f7822250bf..6017c85fac 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts @@ -1,17 +1,8 @@ import nock from 'nock'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, - initBinaryDataService, -} from '@test/nodes/Helpers'; +import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; describe('Test Binary Data Download', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - const baseUrl = 'https://dummy.domain'; beforeAll(async () => { @@ -31,9 +22,7 @@ describe('Test Binary Data Download', () => { 'content-disposition': 'attachment; filename="testing.jpg"', }); }); - const nodeTypes = setup(tests); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts b/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts index d98a76029b..5b5a19fb64 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts @@ -1,17 +1,8 @@ import nock from 'nock'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, - initBinaryDataService, -} from '@test/nodes/Helpers'; +import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; describe('Test Response Encoding', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - const baseUrl = 'https://dummy.domain'; const payload = Buffer.from( 'El rápido zorro marrón salta sobre el perro perezoso. ¡Qué bello día en París! Árbol, cañón, façade.', @@ -26,9 +17,7 @@ describe('Test Response Encoding', () => { .get('/index.html') .reply(200, payload, { 'content-type': 'text/plain; charset=latin1' }); }); - const nodeTypes = setup(tests); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts b/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts index 0237a98836..e3cb2563f7 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts @@ -1,17 +1,8 @@ import nock from 'nock'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, - initBinaryDataService, -} from '@test/nodes/Helpers'; +import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; describe('Test Quoted Response Encoding', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - const baseUrl = 'https://dummy.domain'; const payload = Buffer.from( 'El rápido zorro marrón salta sobre el perro perezoso. ¡Qué bello día en París! Árbol, cañón, façade.', @@ -26,9 +17,7 @@ describe('Test Quoted Response Encoding', () => { .get('/index.html') .reply(200, payload, { 'content-type': 'text/plain; charset="latin1"' }); }); - const nodeTypes = setup(tests); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts b/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts index d25dd15f8f..cf429c7a3a 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts @@ -1,18 +1,9 @@ import nock from 'nock'; import { parse as parseUrl } from 'url'; -import { - initBinaryDataService, - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, -} from '@test/nodes/Helpers'; +import { initBinaryDataService, getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test HTTP Request Node', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - const baseUrl = 'https://dummyjson.com'; beforeAll(async () => { @@ -191,9 +182,7 @@ describe('Test HTTP Request Node', () => { return getPaginationReturnData.call(this, limit, skip); }); }); - const nodeTypes = setup(tests); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts b/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts index 353c0f278c..851c0abf08 100644 --- a/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts +++ b/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts @@ -1,12 +1,8 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; + import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { - getResultNodeData, - setup, - readJsonFileSync, - initBinaryDataService, -} from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { getResultNodeData, readJsonFileSync, initBinaryDataService } from '@test/nodes/Helpers'; describe('Execute iCalendar Node', () => { beforeEach(async () => { @@ -43,11 +39,10 @@ describe('Execute iCalendar Node', () => { }, }, ]; - const nodeTypes = setup(tests); for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { diff --git a/packages/nodes-base/nodes/MailerLite/tests/v1/MailerLite.v1.workflow.test.ts b/packages/nodes-base/nodes/MailerLite/tests/v1/MailerLite.v1.workflow.test.ts index 468a653d45..419eec40ea 100644 --- a/packages/nodes-base/nodes/MailerLite/tests/v1/MailerLite.v1.workflow.test.ts +++ b/packages/nodes-base/nodes/MailerLite/tests/v1/MailerLite.v1.workflow.test.ts @@ -1,6 +1,7 @@ import nock from 'nock'; -import { getWorkflowFilenames, testWorkflows } from '../../../../test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { getCreateResponseClassic, getSubscriberResponseClassic, diff --git a/packages/nodes-base/nodes/MailerLite/tests/v2/MailerLite.v2.workflow.test.ts b/packages/nodes-base/nodes/MailerLite/tests/v2/MailerLite.v2.workflow.test.ts index 9752eb3a44..2ec639b55f 100644 --- a/packages/nodes-base/nodes/MailerLite/tests/v2/MailerLite.v2.workflow.test.ts +++ b/packages/nodes-base/nodes/MailerLite/tests/v2/MailerLite.v2.workflow.test.ts @@ -1,6 +1,7 @@ import nock from 'nock'; -import { getWorkflowFilenames, testWorkflows } from '../../../../test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { getCreateResponseV2, getSubscriberResponseV2, diff --git a/packages/nodes-base/nodes/Merge/test/v3/operations.test.ts b/packages/nodes-base/nodes/Merge/test/v3/operations.test.ts index 21f97e0ee2..46598c7c09 100644 --- a/packages/nodes-base/nodes/Merge/test/v3/operations.test.ts +++ b/packages/nodes-base/nodes/Merge/test/v3/operations.test.ts @@ -1,6 +1,7 @@ import type { IDataObject, INode } from 'n8n-workflow'; -import { createMockExecuteFunction } from '../../../../test/nodes/Helpers'; +import { createMockExecuteFunction } from '@test/nodes/Helpers'; + import * as mode from '../../v3/actions/mode'; const node: INode = { diff --git a/packages/nodes-base/nodes/Microsoft/Entra/test/GroupDescription.test.ts b/packages/nodes-base/nodes/Microsoft/Entra/test/GroupDescription.test.ts index be27e9cf63..c82ff3011c 100644 --- a/packages/nodes-base/nodes/Microsoft/Entra/test/GroupDescription.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Entra/test/GroupDescription.test.ts @@ -1,22 +1,13 @@ -import { NodeConnectionTypes } from 'n8n-workflow'; -import nock from 'nock'; +import { NodeConnectionTypes, type WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks'; describe('Microsoft Entra Node', () => { const baseUrl = 'https://graph.microsoft.com/v1.0'; - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('Group description', () => { const tests: WorkflowTestData[] = [ { @@ -760,10 +751,8 @@ describe('Microsoft Entra Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/Microsoft/Entra/test/MicrosoftEntra.node.test.ts b/packages/nodes-base/nodes/Microsoft/Entra/test/MicrosoftEntra.node.test.ts index b81ab72d0b..b1504a0161 100644 --- a/packages/nodes-base/nodes/Microsoft/Entra/test/MicrosoftEntra.node.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Entra/test/MicrosoftEntra.node.test.ts @@ -3,28 +3,20 @@ import type { IDataObject, IHttpRequestOptions, ILoadOptionsFunctions, + WorkflowTestData, } from 'n8n-workflow'; import { NodeConnectionTypes } from 'n8n-workflow'; -import nock from 'nock'; +import { CredentialsHelper } from '@test/nodes/credentials-helper'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks'; -import { FAKE_CREDENTIALS_DATA } from '../../../../test/nodes/FakeCredentialsMap'; import { MicrosoftEntra } from '../MicrosoftEntra.node'; describe('Microsoft Entra Node', () => { const baseUrl = 'https://graph.microsoft.com/v1.0'; - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('Credentials', () => { const tests: WorkflowTestData[] = [ { @@ -87,12 +79,25 @@ describe('Microsoft Entra Node', () => { 'Micosoft Entra ID': [microsoftEntraNodeResponse.getGroup], }, }, + nock: { + baseUrl, + mocks: [ + { + method: 'get', + path: `/groups/${microsoftEntraApiResponse.getGroup.id}`, + statusCode: 200, + responseBody: { + ...microsoftEntraApiResponse.getGroup, + }, + }, + ], + }, }, ]; beforeAll(() => { jest - .spyOn(Helpers.CredentialsHelper.prototype, 'authenticate') + .spyOn(CredentialsHelper.prototype, 'authenticate') .mockImplementation( async ( credentials: ICredentialDataDecryptedObject, @@ -114,20 +119,8 @@ describe('Microsoft Entra Node', () => { ); }); - nock(baseUrl) - .get(`/groups/${microsoftEntraApiResponse.getGroup.id}`) - .matchHeader( - 'authorization', - 'bearer ' + FAKE_CREDENTIALS_DATA.microsoftEntraOAuth2Api.oauthTokenData.access_token, - ) - .reply(200, { - ...microsoftEntraApiResponse.getGroup, - }); - - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => expect(resultData).toEqual(testData.output.nodeData[nodeName]), diff --git a/packages/nodes-base/nodes/Microsoft/Entra/test/UserDescription.test.ts b/packages/nodes-base/nodes/Microsoft/Entra/test/UserDescription.test.ts index aa78cc5937..27fcca5101 100644 --- a/packages/nodes-base/nodes/Microsoft/Entra/test/UserDescription.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Entra/test/UserDescription.test.ts @@ -1,22 +1,13 @@ -import { NodeConnectionTypes } from 'n8n-workflow'; -import nock from 'nock'; +import { NodeConnectionTypes, type WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks'; describe('Microsoft Entra Node', () => { const baseUrl = 'https://graph.microsoft.com/v1.0'; - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('User description', () => { const tests: WorkflowTestData[] = [ { @@ -1146,10 +1137,8 @@ describe('Microsoft Entra Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/addTable.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/addTable.test.ts index 9f837faf9a..4f30c28971 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/addTable.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/addTable.test.ts @@ -1,60 +1,27 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return { - style: 'TableStyleMedium2', - name: 'Table3', - showFilterButton: true, - id: '{317CA469-7D1C-4A5D-9B0B-424444BF0336}', - highlightLastColumn: false, - highlightFirstColumn: false, - legacyId: '3', - showBandedColumns: false, - showBandedRows: true, - showHeaders: true, - showTotals: false, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => addTable', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/addTable.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .post( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/tables/add', + { address: 'A1:D4', hasHeaders: true }, + ) + .reply(200, { + style: 'TableStyleMedium2', + name: 'Table3', + showFilterButton: true, + id: '{317CA469-7D1C-4A5D-9B0B-424444BF0336}', + highlightLastColumn: false, + highlightFirstColumn: false, + legacyId: '3', + showBandedColumns: false, + showBandedRows: true, + showHeaders: true, + showTotals: false, }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/add', - { address: 'A1:D4', hasHeaders: true }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/addTable.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/append.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/append.test.ts index 4b85c99f91..42f9325b7b 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/append.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/append.test.ts @@ -1,81 +1,28 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - if (method === 'GET') { - return { - value: [ - { - name: 'id', - }, - { - name: 'name', - }, - { - name: 'age', - }, - { - name: 'data', - }, - ], - }; - } - if (method === 'POST' && resource.includes('createSession')) { - return { - id: 12345, - }; - } - if (method === 'POST' && resource.includes('add')) { - return { - index: 3, - values: [[3, 'Donald', 99, 'data 5']], - }; - } - if (method === 'POST' && resource.includes('closeSession')) { - return; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => append', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/append.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(4); - - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/{317CA469-7D1C-4A5D-9B0B-424444BF0336}/rows/add', + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/tables/%7B317CA469-7D1C-4A5D-9B0B-424444BF0336%7D/columns', + ) + .reply(200, { + value: [{ name: 'id' }, { name: 'name' }, { name: 'age' }, { name: 'data' }], + }) + .post( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/tables/%7B317CA469-7D1C-4A5D-9B0B-424444BF0336%7D/rows/add', { values: [['3', 'Donald', '99', 'data 5']] }, - {}, - '', - { 'workbook-session-id': 12345 }, - ); + ) + .reply(200, { + index: 3, + values: [[3, 'Donald', 99, 'data 5']], + }) + .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/createSession') + .reply(200, { id: 12345 }) + .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/closeSession') + .reply(200); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/append.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/convertToRange.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/convertToRange.test.ts index ce6fb50265..7a3a29cd34 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/convertToRange.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/convertToRange.test.ts @@ -1,56 +1,23 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return { - address: 'Sheet4!A1:D5', - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Sam', 34, 'data 4'], - [3, 'Donald', 99, 'data 5'], - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => convertToRange', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/convertToRange.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .post( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/tables/%7B6321EE4A-AC21-48AD-87D9-B527637D94B3%7D/convertToRange', + ) + .reply(200, { + address: 'Sheet4!A1:D5', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Sam', 34, 'data 4'], + [3, 'Donald', 99, 'data 5'], + ], }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/{6321EE4A-AC21-48AD-87D9-B527637D94B3}/convertToRange', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/convertToRange.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/deleteTable.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/deleteTable.test.ts index 5a85db9290..23fc5b8123 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/deleteTable.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/deleteTable.test.ts @@ -1,47 +1,14 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'DELETE') { - return; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => deleteTable', () => { + nock('https://graph.microsoft.com/v1.0/me') + .delete( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/tables/%7B92FBE3F5-3180-47EE-8549-40892C38DA7F%7D', + ) + .reply(200); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/deleteTable.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'DELETE', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{A0883CFE-D27E-4ECC-B94B-981830AAD55B}/tables/{92FBE3F5-3180-47EE-8549-40892C38DA7F}', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getColumns.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getColumns.test.ts index cb7f138441..8b4bb89964 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getColumns.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getColumns.test.ts @@ -1,61 +1,25 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequestAllItemsSkip: jest.fn(async function () { - return [ - { - name: 'country', - }, - { - name: 'browser', - }, - { - name: 'session_duration', - }, - { - name: 'visits', - }, - ]; - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => getColumns', () => { + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24top=100&%24skip=0', + ) + .reply(200, { + value: [ + { name: 'country' }, + { name: 'browser' }, + { name: 'session_duration' }, + { name: 'visits' }, + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24top=100&%24skip=100', + ) + .reply(200, { value: [] }); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/getColumns.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledWith( - 'value', - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{00000000-0001-0000-0000-000000000000}/tables/{613E8967-D581-44ED-81D3-82A01AA6A05C}/columns', - {}, - {}, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getRows.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getRows.test.ts index 2aba1e8c92..5f74d7ebe3 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getRows.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/getRows.test.ts @@ -1,85 +1,34 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return { - value: [ - { - index: 0, - values: [['uk', 'firefox', 1, 1]], - }, - { - index: 1, - values: [['us', 'chrome', 1, 12]], - }, - ], - }; - } - }), - microsoftApiRequestAllItemsSkip: jest.fn(async function () { - return [ - { - name: 'country', - }, - { - name: 'browser', - }, - { - name: 'session_duration', - }, - { - name: 'visits', - }, - ]; - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => getRows', () => { + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/rows?%24top=2', + ) + .reply(200, { + value: [ + { index: 0, values: [['uk', 'firefox', 1, 1]] }, + { index: 1, values: [['us', 'chrome', 1, 12]] }, + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24select=name&%24top=100&%24skip=0', + ) + .reply(200, { + value: [ + { name: 'country' }, + { name: 'browser' }, + { name: 'session_duration' }, + { name: 'visits' }, + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24select=name&%24top=100&%24skip=100', + ) + .reply(200, { value: [] }); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/getRows.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{00000000-0001-0000-0000-000000000000}/tables/{613E8967-D581-44ED-81D3-82A01AA6A05C}/rows', - {}, - { $top: 2 }, - ); - - expect(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledWith( - 'value', - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{00000000-0001-0000-0000-000000000000}/tables/{613E8967-D581-44ED-81D3-82A01AA6A05C}/columns', - {}, - { $select: 'name' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/lookup.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/lookup.test.ts index e50d155669..582d1b8df0 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/lookup.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/table/lookup.test.ts @@ -1,102 +1,42 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequestAllItemsSkip: jest.fn(async function ( - _property: string, - _method: IHttpRequestMethods, - endpoint: string, - ) { - if (endpoint.includes('columns')) { - return [ - { - name: 'country', - }, - { - name: 'browser', - }, - { - name: 'session_duration', - }, - { - name: 'visits', - }, - ]; - } - if (endpoint.includes('rows')) { - return [ - { - index: 0, - values: [['uk', 'firefox', 1, 1]], - }, - { - index: 1, - values: [['us', 'chrome', 1, 12]], - }, - { - index: 2, - values: [['test', 'test', 55, 123]], - }, - { - index: 3, - values: [['ua', 'chrome', 1, 3]], - }, - { - index: 4, - values: [['ua', 'firefox', 1, 4]], - }, - { - index: 5, - values: [['uk', 'chrome', 1, 55]], - }, - ]; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, table => lookup', () => { + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/rows?%24top=100&%24skip=0', + ) + .reply(200, { + value: [ + { index: 0, values: [['uk', 'firefox', 1, 1]] }, + { index: 1, values: [['us', 'chrome', 1, 12]] }, + { index: 2, values: [['test', 'test', 55, 123]] }, + { index: 3, values: [['ua', 'chrome', 1, 3]] }, + { index: 4, values: [['ua', 'firefox', 1, 4]] }, + { index: 5, values: [['uk', 'chrome', 1, 55]] }, + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/rows?%24top=100&%24skip=100', + ) + .reply(200, { value: [] }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24select=name&%24top=100&%24skip=0', + ) + .reply(200, { + value: [ + { name: 'country' }, + { name: 'browser' }, + { name: 'session_duration' }, + { name: 'visits' }, + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B00000000-0001-0000-0000-000000000000%7D/tables/%7B613E8967-D581-44ED-81D3-82A01AA6A05C%7D/columns?%24select=name&%24top=100&%24skip=100', + ) + .reply(200, { value: [] }); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/lookup.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledTimes(2); - expect(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledWith( - 'value', - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{00000000-0001-0000-0000-000000000000}/tables/{613E8967-D581-44ED-81D3-82A01AA6A05C}/rows', - {}, - {}, - ); - expect(transport.microsoftApiRequestAllItemsSkip).toHaveBeenCalledWith( - 'value', - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{00000000-0001-0000-0000-000000000000}/tables/{613E8967-D581-44ED-81D3-82A01AA6A05C}/columns', - {}, - { $select: 'name' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.test.ts index 6a38edd3b4..729b312984 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.test.ts @@ -1,77 +1,26 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - if (method === 'POST' && resource.includes('createSession')) { - return { - id: 12345, - }; - } - if (method === 'POST' && resource.includes('add')) { - return { - id: '{266ADAB7-25B6-4F28-A2D1-FD5BFBD7A4F0}', - name: 'Sheet42', - position: 8, - visibility: 'Visible', - }; - } - if (method === 'POST' && resource.includes('closeSession')) { - return; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, workbook => addWorksheet', () => { + nock('https://graph.microsoft.com/v1.0/me') + .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/createSession', { + persistChanges: true, + }) + .reply(200, { id: 12345 }) + .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/add', { + name: 'Sheet42', + }) + .matchHeader('workbook-session-id', '12345') + .reply(200, { + id: '{266ADAB7-25B6-4F28-A2D1-FD5BFBD7A4F0}', + name: 'Sheet42', + position: 8, + visibility: 'Visible', + }) + .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/closeSession') + .reply(200); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(3); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/createSession', - { persistChanges: true }, - ); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/add', - { name: 'Sheet42' }, - {}, - '', - { 'workbook-session-id': 12345 }, - ); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/closeSession', - {}, - {}, - '', - { 'workbook-session-id': 12345 }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/deleteWorkbook.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/deleteWorkbook.test.ts index 45a72c5e73..12c0ec8442 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/deleteWorkbook.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/deleteWorkbook.test.ts @@ -1,47 +1,12 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'DELETE') { - return; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, workbook => deleteWorkbook', () => { + nock('https://graph.microsoft.com/v1.0/me') + .delete('/drive/items/01FUWX3BXJLISGF2CFWBGYPHXFCXPXOJUK') + .reply(200); + const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/deleteWorkbook.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'DELETE', - '/drive/items/01FUWX3BXJLISGF2CFWBGYPHXFCXPXOJUK', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/getAll.test.ts index 8058511767..3b1b594945 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/workbook/getAll.test.ts @@ -1,62 +1,23 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return { - value: [ - { - '@odata.type': '#microsoft.graph.driveItem', - name: 'ПРРО копія.xlsx', - }, - , - { - '@odata.type': '#microsoft.graph.driveItem', - name: 'Book 3.xlsx', - }, - , - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, workbook => getAll', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .get("/drive/root/search(q='.xlsx')?%24select=name&%24top=2") + .reply(200, { + value: [ + { + '@odata.type': '#microsoft.graph.driveItem', + name: 'ПРРО копія.xlsx', + }, + { + '@odata.type': '#microsoft.graph.driveItem', + name: 'Book 3.xlsx', + }, + ], }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'GET', - "/drive/root/search(q='.xlsx')", - {}, - { $select: 'name', $top: 2 }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/append.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/append.test.ts index f9ce0f5995..d769967157 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/append.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/append.test.ts @@ -1,45 +1,42 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - if (method === 'GET' && resource.includes('usedRange')) { - return { - address: 'Sheet4!A1:D6', - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - ], - }; - } - - if (method === 'PATCH' && resource.includes('{A0883CFE-D27E-4ECC-B94B-981830AAD55B}')) { - return { - values: [[4, 'Sam', 34, 'data 4']], - }; - } - - if (method === 'PATCH' && resource.includes('{426949D7-797F-43A9-A8A4-8FE283495A82}')) { - return { - values: [[4, 'Don', 37, 'data 44']], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => append', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/append.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/range(address='A7:D7')", + ) + .reply(200, { values: [[4, 'Sam', 34, 'data 4']] }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/range(address='A7:D7')", + ) + .reply(200, { values: [[4, 'Don', 37, 'data 44']] }); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/append.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/clear.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/clear.test.ts index 14df918187..aac6c2bb8e 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/clear.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/clear.test.ts @@ -1,56 +1,17 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return { - values: [ - { - json: { - success: true, - }, - }, - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => clear', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/clear.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .post( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BF7AF92FE-D42D-452F-8E4A-901B1D1EBF3F%7D/range/clear', + { applyTo: 'All' }, + ) + .reply(200, { + values: [{ json: { success: true } }], }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{F7AF92FE-D42D-452F-8E4A-901B1D1EBF3F}/range/clear', - { applyTo: 'All' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/clear.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.test.ts index e38c43b60d..a2849aceac 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.test.ts @@ -1,55 +1,16 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'DELETE') { - return { - values: [ - { - json: { - success: true, - }, - }, - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => deleteWorksheet', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .delete( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B88D9C37A-4180-4B23-8996-BF11F32EB63C%7D', + ) + .reply(200, { + values: [{ json: { success: true } }], }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'DELETE', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/{88D9C37A-4180-4B23-8996-BF11F32EB63C}', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.test.ts index d17353817f..231c9bd5c5 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.test.ts @@ -1,64 +1,29 @@ -import type { IHttpRequestMethods, INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return { - value: [ - { - id: '{00000000-0001-0000-0000-000000000000}', - name: 'Sheet1', - }, - { - id: '{F7AF92FE-D42D-452F-8E4A-901B1D1EBF3F}', - name: 'Sheet2', - }, - { - id: '{BF7BD843-4912-4B81-A0AC-4FBBC2783E20}', - name: 'foo2', - }, - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => getAll', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets?%24select=name&%24top=3', + ) + .reply(200, { + value: [ + { + id: '{00000000-0001-0000-0000-000000000000}', + name: 'Sheet1', + }, + { + id: '{F7AF92FE-D42D-452F-8E4A-901B1D1EBF3F}', + name: 'Sheet2', + }, + { + id: '{BF7BD843-4912-4B81-A0AC-4FBBC2783E20}', + name: 'foo2', + }, + ], }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'GET', - '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets', - {}, - { $select: 'name', $top: 3 }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.test.ts index 8dbed77a6e..64535f2adf 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.test.ts @@ -1,42 +1,31 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - { - if (method === 'GET' && resource.includes('usedRange')) { - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - ], - }; - } - - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => readRows', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/usedRange', + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .get( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/range(address='A1:D3')", + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + ], + }); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/update.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/update.test.ts index f31047c37f..1d5c272bfa 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/update.test.ts @@ -1,55 +1,56 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - if (method === 'GET' && resource.includes('usedRange')) { - return { - address: 'Sheet4!A1:D6', - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - ], - }; - } - - if (method === 'PATCH' && resource.includes('{A0883CFE-D27E-4ECC-B94B-981830AAD55B}')) { - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Sam', 34, 'data 4'], - ], - }; - } - - if (method === 'PATCH' && resource.includes('{426949D7-797F-43A9-A8A4-8FE283495A82}')) { - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Don', 37, 'data 44'], - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => update', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/update.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/range(address='A1:D6')", + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Sam', 34, 'data 4'], + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/range(address='A1:D6')", + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Don', 37, 'data 44'], + ], + }); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/update.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.test.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.test.ts index 4299db5beb..51482fa172 100644 --- a/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.test.ts @@ -1,57 +1,58 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: IHttpRequestMethods, resource: string) { - if (method === 'GET' && resource.includes('usedRange')) { - return { - address: 'Sheet4!A1:D6', - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - ], - }; - } - - if (method === 'PATCH' && resource.includes('{A0883CFE-D27E-4ECC-B94B-981830AAD55B}')) { - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - [4, 'Sam', 34, 'data 4'], - ], - }; - } - - if (method === 'PATCH' && resource.includes('{426949D7-797F-43A9-A8A4-8FE283495A82}')) { - return { - values: [ - ['id', 'name', 'age', 'data'], - [1, 'Sam', 33, 'data 1'], - [2, 'Jon', 44, 'data 2'], - [3, 'Ron', 55, 'data 3'], - [4, 'Don', 37, 'data 44'], - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftExcelV2, worksheet => upsert', () => { - const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7BA0883CFE-D27E-4ECC-B94B-981830AAD55B%7D/range(address='A1:D7')", + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + [4, 'Sam', 34, 'data 4'], + ], + }) + .get( + '/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/usedRange', + ) + .reply(200, { + address: 'Sheet4!A1:D6', + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + ], + }) + .patch( + "/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/worksheets/%7B426949D7-797F-43A9-A8A4-8FE283495A82%7D/range(address='A1:D7')", + ) + .reply(200, { + values: [ + ['id', 'name', 'age', 'data'], + [1, 'Sam', 33, 'data 1'], + [2, 'Jon', 44, 'data 2'], + [3, 'Ron', 55, 'data 3'], + [4, 'Don', 37, 'data 44'], + ], + }); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/create.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/create.test.ts index 93b5269fb8..6005ad57dd 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/create.test.ts @@ -1,68 +1,35 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendarGroups('AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRu_AAA%3D')/calendars/$entity", - id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAFXBBZ_AAA=', - name: 'New Calendar', - color: 'lightOrange', - hexColor: '#fcab73', - isDefaultCalendar: false, - changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwWTA==', - canShare: true, - canViewPrivateItems: true, - canEdit: true, - allowedOnlineMeetingProviders: ['teamsForBusiness'], - defaultOnlineMeetingProvider: 'teamsForBusiness', - isTallyingResponses: false, - isRemovable: true, - owner: { - name: 'User Name', - address: 'test@mail.com', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, calendar => create', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/create.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://graph.microsoft.com/v1.0/me') + .post( '/calendarGroups/AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRu_AAA=/calendars', { color: 'lightOrange', name: 'New Calendar' }, - ); + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendarGroups('AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRu_AAA%3D')/calendars/$entity", + id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAFXBBZ_AAA=', + name: 'New Calendar', + color: 'lightOrange', + hexColor: '#fcab73', + isDefaultCalendar: false, + changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwWTA==', + canShare: true, + canViewPrivateItems: true, + canEdit: true, + allowedOnlineMeetingProviders: ['teamsForBusiness'], + defaultOnlineMeetingProvider: 'teamsForBusiness', + isTallyingResponses: false, + isRemovable: true, + owner: { + name: 'User Name', + address: 'test@mail.com', + }, + }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/delete.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/delete.test.ts index 7e3f368939..f795dba338 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/delete.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/delete.test.ts @@ -1,47 +1,14 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'DELETE') { - return {}; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, calendar => delete', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/delete.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'DELETE', + nock('https://graph.microsoft.com/v1.0/me') + .delete( '/calendars/AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvIAAA=', - ); + ) + .reply(200); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/delete.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/get.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/get.test.ts index a8b5908d6f..627cf72466 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/get.test.ts @@ -1,69 +1,34 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'GET') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars/$entity", - id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', - name: 'Foo Calendar', - color: 'lightGreen', - hexColor: '#87d28e', - isDefaultCalendar: false, - changeKey: 'WX+A3vy5K0qqTyPHso1JgAAAi67hiw==', - canShare: true, - canViewPrivateItems: true, - canEdit: true, - allowedOnlineMeetingProviders: ['teamsForBusiness'], - defaultOnlineMeetingProvider: 'teamsForBusiness', - isTallyingResponses: false, - isRemovable: true, - owner: { - name: 'User Name', - address: 'test@mail.com', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, calendar => get', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/get.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/calendars/AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars/$entity", + id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', + name: 'Foo Calendar', + color: 'lightGreen', + hexColor: '#87d28e', + isDefaultCalendar: false, + changeKey: 'WX+A3vy5K0qqTyPHso1JgAAAi67hiw==', + canShare: true, + canViewPrivateItems: true, + canEdit: true, + allowedOnlineMeetingProviders: ['teamsForBusiness'], + defaultOnlineMeetingProvider: 'teamsForBusiness', + isTallyingResponses: false, + isRemovable: true, + owner: { + name: 'User Name', + address: 'test@mail.com', + }, }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'GET', - '/calendars/AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', - undefined, - {}, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/getAll.test.ts index f994d55e3e..115530a286 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/getAll.test.ts @@ -1,88 +1,53 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'GET') { - return { - value: [ - { - id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAAJ9-JDAAA=', - name: 'Calendar', - color: 'auto', - hexColor: '', - isDefaultCalendar: true, - changeKey: 'WX+A3vy5K0qqTyPHso1JgAAACfdHfw==', - canShare: true, - canViewPrivateItems: true, - canEdit: true, - allowedOnlineMeetingProviders: ['teamsForBusiness'], - defaultOnlineMeetingProvider: 'teamsForBusiness', - isTallyingResponses: true, - isRemovable: false, - owner: { - name: 'User Name', - address: 'test@mail.com', - }, - }, - { - id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvBAAA=', - name: 'Third calendar', - color: 'lightYellow', - hexColor: '#fde300', - isDefaultCalendar: false, - changeKey: 'WX+A3vy5K0qqTyPHso1JgAAAi67hIw==', - canShare: true, - canViewPrivateItems: true, - canEdit: true, - allowedOnlineMeetingProviders: ['teamsForBusiness'], - defaultOnlineMeetingProvider: 'teamsForBusiness', - isTallyingResponses: false, - isRemovable: true, - owner: { - name: 'User Name', - address: 'test@mail.com', - }, - }, - ], - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, calendar => getAll', () => { + nock('https://graph.microsoft.com/v1.0/me') + .get('/calendars?%24filter=canEdit%20eq%20true&%24top=2') + .reply(200, { + value: [ + { + id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAAJ9-JDAAA=', + name: 'Calendar', + color: 'auto', + hexColor: '', + isDefaultCalendar: true, + changeKey: 'WX+A3vy5K0qqTyPHso1JgAAACfdHfw==', + canShare: true, + canViewPrivateItems: true, + canEdit: true, + allowedOnlineMeetingProviders: ['teamsForBusiness'], + defaultOnlineMeetingProvider: 'teamsForBusiness', + isTallyingResponses: true, + isRemovable: false, + owner: { + name: 'User Name', + address: 'test@mail.com', + }, + }, + { + id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvBAAA=', + name: 'Third calendar', + color: 'lightYellow', + hexColor: '#fde300', + isDefaultCalendar: false, + changeKey: 'WX+A3vy5K0qqTyPHso1JgAAAi67hIw==', + canShare: true, + canViewPrivateItems: true, + canEdit: true, + allowedOnlineMeetingProviders: ['teamsForBusiness'], + defaultOnlineMeetingProvider: 'teamsForBusiness', + isTallyingResponses: false, + isRemovable: true, + owner: { + name: 'User Name', + address: 'test@mail.com', + }, + }, + ], + }); + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith('GET', '/calendars', undefined, { - $filter: 'canEdit eq true', - $top: 2, - }); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/update.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/update.test.ts index 18d05f7e44..f71cf076c7 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/calendar/update.test.ts @@ -1,68 +1,35 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'PATCH') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars/$entity", - id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', - name: 'Foo', - color: 'lightOrange', - hexColor: '#fcab73', - isDefaultCalendar: false, - changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwYKA==', - canShare: true, - canViewPrivateItems: true, - canEdit: true, - allowedOnlineMeetingProviders: ['teamsForBusiness'], - defaultOnlineMeetingProvider: 'teamsForBusiness', - isTallyingResponses: false, - isRemovable: true, - owner: { - name: 'User Name', - address: 'test@mail.com', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, calendar => update', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/update.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'PATCH', + nock('https://graph.microsoft.com/v1.0/me') + .patch( '/calendars/AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', { color: 'lightOrange', isDefaultCalendar: false, name: 'Foo' }, - ); + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars/$entity", + id: 'AAAXXXYYYnnnT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAACLtRvGAAA=', + name: 'Foo', + color: 'lightOrange', + hexColor: '#fcab73', + isDefaultCalendar: false, + changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwYKA==', + canShare: true, + canViewPrivateItems: true, + canEdit: true, + allowedOnlineMeetingProviders: ['teamsForBusiness'], + defaultOnlineMeetingProvider: 'teamsForBusiness', + isTallyingResponses: false, + isRemovable: true, + owner: { + name: 'User Name', + address: 'test@mail.com', + }, + }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/calendar/update.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/create.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/create.test.ts index 20fb9abfd3..348efbcb4f 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/create.test.ts @@ -1,82 +1,10 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/contacts/$entity", - '@odata.etag': 'W/"EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bob"', - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAABZf4De-LkrSqpPI8eyjUmAAAFXBCQuAAA=', - createdDateTime: '2023-09-04T08:48:39Z', - lastModifiedDateTime: '2023-09-04T08:48:39Z', - changeKey: 'EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bob', - categories: ['blue', 'green'], - parentFolderId: - 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAAA=', - birthday: '1991-09-19T11:59:00Z', - fileAs: '', - displayName: 'User Name', - givenName: 'User', - initials: null, - middleName: null, - nickName: null, - surname: 'Name', - title: 'Title', - yomiGivenName: null, - yomiSurname: null, - yomiCompanyName: null, - generation: null, - imAddresses: [], - jobTitle: null, - companyName: 'Company', - department: 'IT', - officeLocation: null, - profession: null, - businessHomePage: null, - assistantName: 'Assistant', - manager: null, - homePhones: [], - mobilePhone: null, - businessPhones: [], - spouseName: null, - personalNotes: '', - children: [], - emailAddresses: [], - homeAddress: {}, - businessAddress: {}, - otherAddress: {}, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, contact => create', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/contact/create.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith('POST', '/contacts', { + nock('https://graph.microsoft.com/v1.0/me') + .post('/contacts', { assistantName: 'Assistant', birthday: '1991-09-19T21:00:00.000Z', categories: ['blue', 'green'], @@ -86,12 +14,52 @@ describe('Test MicrosoftOutlookV2, contact => create', () => { givenName: 'User', surname: 'Name', title: 'Title', + }) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/contacts/$entity", + '@odata.etag': 'W/"EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bob"', + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAABZf4De-LkrSqpPI8eyjUmAAAFXBCQuAAA=', + createdDateTime: '2023-09-04T08:48:39Z', + lastModifiedDateTime: '2023-09-04T08:48:39Z', + changeKey: 'EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bob', + categories: ['blue', 'green'], + parentFolderId: + 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAAA=', + birthday: '1991-09-19T11:59:00Z', + fileAs: '', + displayName: 'User Name', + givenName: 'User', + initials: null, + middleName: null, + nickName: null, + surname: 'Name', + title: 'Title', + yomiGivenName: null, + yomiSurname: null, + yomiCompanyName: null, + generation: null, + imAddresses: [], + jobTitle: null, + companyName: 'Company', + department: 'IT', + officeLocation: null, + profession: null, + businessHomePage: null, + assistantName: 'Assistant', + manager: null, + homePhones: [], + mobilePhone: null, + businessPhones: [], + spouseName: null, + personalNotes: '', + children: [], + emailAddresses: [], + homeAddress: {}, + businessAddress: {}, + otherAddress: {}, }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/contact/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/update.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/update.test.ts index 85c54fce2e..8d5096b5c7 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/contact/update.test.ts @@ -1,89 +1,10 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'PATCH') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/contacts/$entity", - '@odata.etag': 'W/"EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bou"', - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAABZf4De-LkrSqpPI8eyjUmAAAFXBCQuAAA=', - createdDateTime: '2023-09-04T08:48:39Z', - lastModifiedDateTime: '2023-09-04T09:06:21Z', - changeKey: 'EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bou', - categories: ['blue', 'green'], - parentFolderId: - 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAAA=', - birthday: '1991-09-19T11:59:00Z', - fileAs: '', - displayName: 'Username', - givenName: 'User', - initials: null, - middleName: null, - nickName: null, - surname: 'Name', - title: 'Title', - yomiGivenName: null, - yomiSurname: null, - yomiCompanyName: null, - generation: null, - imAddresses: [], - jobTitle: null, - companyName: 'Company', - department: 'IT', - officeLocation: null, - profession: null, - businessHomePage: null, - assistantName: 'Assistant', - manager: 'Manager', - homePhones: [], - mobilePhone: '', - businessPhones: ['999000555777'], - spouseName: '', - personalNotes: '', - children: [], - emailAddresses: [], - homeAddress: {}, - businessAddress: { - street: 'Street', - city: 'City', - state: 'State', - countryOrRegion: 'Country', - postalCode: '777777', - }, - otherAddress: {}, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, contact => update', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/contact/update.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'PATCH', + nock('https://graph.microsoft.com/v1.0/me') + .patch( '/contacts/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAABZf4De-LkrSqpPI8eyjUmAAAFXBCQuAAA=', { businessAddress: { @@ -97,12 +18,58 @@ describe('Test MicrosoftOutlookV2, contact => update', () => { displayName: 'Username', manager: 'Manager', }, - ); + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/contacts/$entity", + '@odata.etag': 'W/"EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bou"', + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAABZf4De-LkrSqpPI8eyjUmAAAFXBCQuAAA=', + createdDateTime: '2023-09-04T08:48:39Z', + lastModifiedDateTime: '2023-09-04T09:06:21Z', + changeKey: 'EQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bou', + categories: ['blue', 'green'], + parentFolderId: + 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEOAAA=', + birthday: '1991-09-19T11:59:00Z', + fileAs: '', + displayName: 'Username', + givenName: 'User', + initials: null, + middleName: null, + nickName: null, + surname: 'Name', + title: 'Title', + yomiGivenName: null, + yomiSurname: null, + yomiCompanyName: null, + generation: null, + imAddresses: [], + jobTitle: null, + companyName: 'Company', + department: 'IT', + officeLocation: null, + profession: null, + businessHomePage: null, + assistantName: 'Assistant', + manager: 'Manager', + homePhones: [], + mobilePhone: '', + businessPhones: ['999000555777'], + spouseName: '', + personalNotes: '', + children: [], + emailAddresses: [], + homeAddress: {}, + businessAddress: { + street: 'Street', + city: 'City', + state: 'State', + countryOrRegion: 'Country', + postalCode: '777777', + }, + otherAddress: {}, + }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/contact/update.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/create.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/create.test.ts index d92bb1d5ed..ab7e5a35ca 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/create.test.ts @@ -1,137 +1,100 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/messages/$entity", - '@odata.etag': 'W/"CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bo2"', - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDupAAA=', - createdDateTime: '2023-09-04T09:18:35Z', - lastModifiedDateTime: '2023-09-04T09:18:35Z', - changeKey: 'CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bo2', - categories: [ - 'd10cd8f9-14ac-460e-a6ec-c40dd1876ea2', - '6844a34e-4d23-4805-9fec-38b7f6e1a780', - 'fbf44fcd-7689-43a0-99c8-2c9faf6d825a', - ], - receivedDateTime: '2023-09-04T09:18:35Z', - sentDateTime: '2023-09-04T09:18:35Z', - hasAttachments: false, - internetMessageId: - '', - subject: 'New Draft', - bodyPreview: 'draft message', - importance: 'normal', - parentFolderId: - 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAAA=', - conversationId: - 'AAQkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAQAKELKTNBg5JJuTnBGaTDyl0=', - conversationIndex: 'AQHZ3xDIoQspM0GDkkm5OcEZpMPKXQ==', - isDeliveryReceiptRequested: false, - isReadReceiptRequested: true, - isRead: true, - isDraft: true, - webLink: - 'https://outlook.office365.com/owa/?ItemID=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAEPAABZf4De%2FLkrSqpPI8eyjUmAAAFXBDupAAA%3D&exvsurl=1&viewmodel=ReadMessageItem', - inferenceClassification: 'focused', - body: { - contentType: 'text', - content: 'draft message', - }, - toRecipients: [ - { - emailAddress: { - name: 'some@mail.com', - address: 'some@mail.com', - }, - }, - ], - ccRecipients: [], - bccRecipients: [ - { - emailAddress: { - name: 'name1@mail.com', - address: 'name1@mail.com', - }, - }, - { - emailAddress: { - name: 'name2@mail.com', - address: 'name2@mail.com', - }, - }, - ], - replyTo: [ - { - emailAddress: { - name: 'reply@mail.com', - address: 'reply@mail.com', - }, - }, - ], - flag: { - flagStatus: 'notFlagged', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, draft => create', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/draft/create.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com/v1.0/me') + .post('/messages', { + bccRecipients: [ + { emailAddress: { address: 'name1@mail.com' } }, + { emailAddress: { address: 'name2@mail.com' } }, + ], + body: { content: 'draft message', contentType: 'Text' }, + categories: [ + 'd10cd8f9-14ac-460e-a6ec-c40dd1876ea2', + '6844a34e-4d23-4805-9fec-38b7f6e1a780', + 'fbf44fcd-7689-43a0-99c8-2c9faf6d825a', + ], + importance: 'Normal', + internetMessageHeaders: [{ name: 'x-my-header', value: 'header value' }], + isReadReceiptRequested: true, + replyTo: [{ emailAddress: { address: 'reply@mail.com' } }], + subject: 'New Draft', + toRecipients: [{ emailAddress: { address: 'some@mail.com' } }], + }) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/messages/$entity", + '@odata.etag': 'W/"CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bo2"', + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDupAAA=', + createdDateTime: '2023-09-04T09:18:35Z', + lastModifiedDateTime: '2023-09-04T09:18:35Z', + changeKey: 'CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3Bo2', + categories: [ + 'd10cd8f9-14ac-460e-a6ec-c40dd1876ea2', + '6844a34e-4d23-4805-9fec-38b7f6e1a780', + 'fbf44fcd-7689-43a0-99c8-2c9faf6d825a', + ], + receivedDateTime: '2023-09-04T09:18:35Z', + sentDateTime: '2023-09-04T09:18:35Z', + hasAttachments: false, + internetMessageId: + '', + subject: 'New Draft', + bodyPreview: 'draft message', + importance: 'normal', + parentFolderId: + 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAAA=', + conversationId: + 'AAQkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAQAKELKTNBg5JJuTnBGaTDyl0=', + conversationIndex: 'AQHZ3xDIoQspM0GDkkm5OcEZpMPKXQ==', + isDeliveryReceiptRequested: false, + isReadReceiptRequested: true, + isRead: true, + isDraft: true, + webLink: + 'https://outlook.office365.com/owa/?ItemID=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAEPAABZf4De%2FLkrSqpPI8eyjUmAAAFXBDupAAA%3D&exvsurl=1&viewmodel=ReadMessageItem', + inferenceClassification: 'focused', + body: { + contentType: 'text', + content: 'draft message', + }, + toRecipients: [ + { + emailAddress: { + name: 'some@mail.com', + address: 'some@mail.com', + }, + }, + ], + ccRecipients: [], + bccRecipients: [ + { + emailAddress: { + name: 'name1@mail.com', + address: 'name1@mail.com', + }, + }, + { + emailAddress: { + name: 'name2@mail.com', + address: 'name2@mail.com', + }, + }, + ], + replyTo: [ + { + emailAddress: { + name: 'reply@mail.com', + address: 'reply@mail.com', + }, + }, + ], + flag: { + flagStatus: 'notFlagged', + }, }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/messages', - { - bccRecipients: [ - { emailAddress: { address: 'name1@mail.com' } }, - { emailAddress: { address: 'name2@mail.com' } }, - ], - body: { content: 'draft message', contentType: 'Text' }, - categories: [ - 'd10cd8f9-14ac-460e-a6ec-c40dd1876ea2', - '6844a34e-4d23-4805-9fec-38b7f6e1a780', - 'fbf44fcd-7689-43a0-99c8-2c9faf6d825a', - ], - importance: 'Normal', - internetMessageHeaders: [{ name: 'x-my-header', value: 'header value' }], - isReadReceiptRequested: true, - replyTo: [{ emailAddress: { address: 'reply@mail.com' } }], - subject: 'New Draft', - toRecipients: [{ emailAddress: { address: 'some@mail.com' } }], - }, - {}, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/draft/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/send.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/send.test.ts index d04b7ebbee..67d2e10b97 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/send.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/draft/send.test.ts @@ -1,52 +1,19 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return {}; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, draft => send', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/draft/send.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(2); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'PATCH', + nock('https://graph.microsoft.com/v1.0/me') + .post( + '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDupAAA=/send', + ) + .reply(200) + .patch( '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDupAAA=', { toRecipients: [{ emailAddress: { address: 'michael.k@radency.com' } }] }, - ); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDupAAA=/send', - ); + ) + .reply(200); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/draft/send.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/event/create.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/event/create.test.ts index 460982cc95..1f880cec75 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/event/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/event/create.test.ts @@ -1,121 +1,10 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars('AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAAJ9-JDAAA%3D')/events/$entity", - '@odata.etag': 'W/"WX+A3vy5K0qqTyPHso1JgAABVtwgEQ=="', - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAENAABZf4De-LkrSqpPI8eyjUmAAAFXBFUSAAA=', - createdDateTime: '2023-09-04T10:12:47.1985121Z', - lastModifiedDateTime: '2023-09-04T10:12:48.2173253Z', - changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwgEQ==', - categories: ['Yellow category', 'Orange category'], - transactionId: null, - originalStartTimeZone: 'UTC', - originalEndTimeZone: 'UTC', - iCalUId: - '040000008200E00074C5B7101A82E0080000000062DD545A18DFD90100000000000000001000000004C50947C7B42140B29018ABAB42C965', - reminderMinutesBeforeStart: 15, - isReminderOn: true, - hasAttachments: false, - subject: 'New Event', - bodyPreview: - 'event description\r\n________________________________________________________________________________\r\nMicrosoft Teams meeting\r\nJoin on your computer, mobile app or room device\r\nClick here to join the meeting\r\nMeeting ID: 355 132 640 047\r\nPasscode: xgUo7v', - importance: 'normal', - sensitivity: 'personal', - isAllDay: false, - isCancelled: false, - isOrganizer: true, - responseRequested: true, - seriesMasterId: null, - showAs: 'busy', - type: 'singleInstance', - webLink: - 'https://outlook.office365.com/owa/?itemid=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAENAABZf4De%2FLkrSqpPI8eyjUmAAAFXBFUSAAA%3D&exvsurl=1&path=/calendar/item', - onlineMeetingUrl: null, - isOnlineMeeting: true, - onlineMeetingProvider: 'teamsForBusiness', - allowNewTimeProposals: true, - occurrenceId: null, - isDraft: false, - hideAttendees: true, - responseStatus: { - response: 'organizer', - time: '0001-01-01T00:00:00Z', - }, - body: { - contentType: 'html', - content: - '\r\n\r\n\r\n\r\n\r\nevent description
\r\n
________________________________________________________________________________\r\n
\r\n
\r\n
Microsoft Teams meeting\r\n
\r\n
\r\n
Join on your computer, mobile app or room device\r\n
\r\nClick\r\n here to join the meeting
\r\n
\r\n
Meeting ID:\r\n355 132 640 047
\r\nPasscode: xgUo7v\r\n\r\n\r\n
\r\n
\r\n\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
________________________________________________________________________________\r\n
\r\n\r\n\r\n', - }, - start: { - dateTime: '2023-09-05T07:26:47.0000000', - timeZone: 'UTC', - }, - end: { - dateTime: '2023-09-06T07:56:47.0000000', - timeZone: 'UTC', - }, - location: { - displayName: 'Microsoft Teams Meeting', - locationType: 'default', - uniqueId: 'Microsoft Teams Meeting', - uniqueIdType: 'private', - }, - locations: [ - { - displayName: 'Microsoft Teams Meeting', - locationType: 'default', - uniqueId: 'Microsoft Teams Meeting', - uniqueIdType: 'private', - }, - ], - recurrence: null, - attendees: [], - organizer: { - emailAddress: { - name: 'Michael Kret', - address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', - }, - }, - onlineMeeting: { - joinUrl: - 'https://teams.microsoft.com/l/meetup-join/19%3ameeting_MDZmMzZmYzYtMDc4Yi00NTA2LWE3MTMtZDc5ZDI1M2JmY2M3%40thread.v2/0?context=%7b%22Tid%22%3a%2223786ca6-7ff2-4672-87d0-5c649ee0a337%22%2c%22Oid%22%3a%22b834447b-6848-4af9-8390-d2259ce46b74%22%7d', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, contact => event', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/event/create.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://graph.microsoft.com/v1.0/me') + .post( '/calendars/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAAJ9-JDAAA=/events', { body: { content: 'event description', contentType: 'html' }, @@ -134,12 +23,90 @@ describe('Test MicrosoftOutlookV2, contact => event', () => { subject: 'New Event', type: 'occurrence', }, - ); + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/calendars('AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEGAABZf4De-LkrSqpPI8eyjUmAAAAJ9-JDAAA%3D')/events/$entity", + '@odata.etag': 'W/"WX+A3vy5K0qqTyPHso1JgAABVtwgEQ=="', + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAENAABZf4De-LkrSqpPI8eyjUmAAAFXBFUSAAA=', + createdDateTime: '2023-09-04T10:12:47.1985121Z', + lastModifiedDateTime: '2023-09-04T10:12:48.2173253Z', + changeKey: 'WX+A3vy5K0qqTyPHso1JgAABVtwgEQ==', + categories: ['Yellow category', 'Orange category'], + transactionId: null, + originalStartTimeZone: 'UTC', + originalEndTimeZone: 'UTC', + iCalUId: + '040000008200E00074C5B7101A82E0080000000062DD545A18DFD90100000000000000001000000004C50947C7B42140B29018ABAB42C965', + reminderMinutesBeforeStart: 15, + isReminderOn: true, + hasAttachments: false, + subject: 'New Event', + bodyPreview: + 'event description\r\n________________________________________________________________________________\r\nMicrosoft Teams meeting\r\nJoin on your computer, mobile app or room device\r\nClick here to join the meeting\r\nMeeting ID: 355 132 640 047\r\nPasscode: xgUo7v', + importance: 'normal', + sensitivity: 'personal', + isAllDay: false, + isCancelled: false, + isOrganizer: true, + responseRequested: true, + seriesMasterId: null, + showAs: 'busy', + type: 'singleInstance', + webLink: + 'https://outlook.office365.com/owa/?itemid=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAENAABZf4De%2FLkrSqpPI8eyjUmAAAFXBFUSAAA%3D&exvsurl=1&path=/calendar/item', + onlineMeetingUrl: null, + isOnlineMeeting: true, + onlineMeetingProvider: 'teamsForBusiness', + allowNewTimeProposals: true, + occurrenceId: null, + isDraft: false, + hideAttendees: true, + responseStatus: { + response: 'organizer', + time: '0001-01-01T00:00:00Z', + }, + body: { + contentType: 'html', + content: + '\r\n\r\n\r\n\r\n\r\nevent description
\r\n
________________________________________________________________________________\r\n
\r\n
\r\n
Microsoft Teams meeting\r\n
\r\n
\r\n
Join on your computer, mobile app or room device\r\n
\r\nClick\r\n here to join the meeting
\r\n
\r\n
Meeting ID:\r\n355 132 640 047
\r\nPasscode: xgUo7v\r\n\r\n\r\n
\r\n
\r\n\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
________________________________________________________________________________\r\n
\r\n\r\n\r\n', + }, + start: { + dateTime: '2023-09-05T07:26:47.0000000', + timeZone: 'UTC', + }, + end: { + dateTime: '2023-09-06T07:56:47.0000000', + timeZone: 'UTC', + }, + location: { + displayName: 'Microsoft Teams Meeting', + locationType: 'default', + uniqueId: 'Microsoft Teams Meeting', + uniqueIdType: 'private', + }, + locations: [ + { + displayName: 'Microsoft Teams Meeting', + locationType: 'default', + uniqueId: 'Microsoft Teams Meeting', + uniqueIdType: 'private', + }, + ], + recurrence: null, + attendees: [], + organizer: { + emailAddress: { + name: 'Michael Kret', + address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', + }, + }, + onlineMeeting: { + joinUrl: + 'https://teams.microsoft.com/l/meetup-join/19%3ameeting_MDZmMzZmYzYtMDc4Yi00NTA2LWE3MTMtZDc5ZDI1M2JmY2M3%40thread.v2/0?context=%7b%22Tid%22%3a%2223786ca6-7ff2-4672-87d0-5c649ee0a337%22%2c%22Oid%22%3a%22b834447b-6848-4af9-8390-d2259ce46b74%22%7d', + }, + }); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/event/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folder/create.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folder/create.test.ts index 783ead7821..0eeeb2358b 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folder/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folder/create.test.ts @@ -1,60 +1,27 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/mailFolders('AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA%3D')/childFolders/$entity", - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAAA=', - displayName: 'Folder 42', - parentFolderId: - 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA=', - childFolderCount: 0, - unreadItemCount: 0, - totalItemCount: 0, - sizeInBytes: 0, - isHidden: false, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, contact => folder', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/folder/create.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com') + .post( + '/v1.0/me/mailFolders/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA=/childFolders', + { displayName: 'Folder 42' }, + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/mailFolders('AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA%3D')/childFolders/$entity", + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAAA=', + displayName: 'Folder 42', + parentFolderId: + 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA=', + childFolderCount: 0, + unreadItemCount: 0, + totalItemCount: 0, + sizeInBytes: 0, + isHidden: false, }); - expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/mailFolders/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEGAAA=/childFolders', - { displayName: 'Folder 42' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/folder/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.test.ts index b38daa72b9..3cd2be5f9e 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.test.ts @@ -1,55 +1,23 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequestAllItems: jest.fn(async function () { - return [ +describe('Test MicrosoftOutlookV2, folderMessage => getAll', () => { + nock('https://graph.microsoft.com/v1.0/me') + .get( + '/mailFolders/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAAA=/messages?%24select=bodyPreview%2Csubject&%24top=100', + ) + .reply(200, { + value: [ { '@odata.etag': 'W/"CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3CAj"', id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAABZf4De-LkrSqpPI8eyjUmAAAFXBGDUAAA=', subject: 'XXXX', bodyPreview: 'test', }, - ]; - }), - }; -}); - -describe('Test MicrosoftOutlookV2, folderMessage => getAll', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequestAllItems).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequestAllItems).toHaveBeenCalledWith( - 'value', - 'GET', - '/mailFolders/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAAA=/messages', - undefined, - { $select: 'bodyPreview,subject' }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/folderMessage/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/move.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/move.test.ts index 71070c7e9f..f65ee8a5de 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/move.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/move.test.ts @@ -1,51 +1,18 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return {}; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, message => move', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/move.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://graph.microsoft.com/v1.0/me') + .post( '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEJAABZf4De-LkrSqpPI8eyjUmAAAFXBEVwAAA=/move', { destinationId: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAFXBAEHAAA=', }, - ); + ) + .reply(200); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/move.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/reply.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/reply.test.ts index e5cf588fc8..3217b99adf 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/reply.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/reply.test.ts @@ -1,100 +1,10 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return { - '@odata.context': - "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/messages/$entity", - '@odata.etag': 'W/"CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3CX+"', - id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDurAAA=', - createdDateTime: '2023-09-04T12:29:59Z', - lastModifiedDateTime: '2023-09-04T12:29:59Z', - changeKey: 'CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3CX+', - categories: [], - receivedDateTime: '2023-09-04T12:29:59Z', - sentDateTime: '2023-09-04T12:29:59Z', - hasAttachments: false, - internetMessageId: - '', - subject: 'Reply Subject', - bodyPreview: 'Reply message', - importance: 'high', - parentFolderId: - 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAAA=', - conversationId: - 'AAQkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAQAKwkQLinj69KtoFOxMG2lVY=', - conversationIndex: 'AQHZ3yq3rCRAuKePr0q2gU7EwbaVVrAKmLQ4', - isDeliveryReceiptRequested: false, - isReadReceiptRequested: false, - isRead: true, - isDraft: true, - webLink: - 'https://outlook.office365.com/owa/?ItemID=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAEPAABZf4De%2FLkrSqpPI8eyjUmAAAFXBDurAAA%3D&exvsurl=1&viewmodel=ReadMessageItem', - inferenceClassification: 'focused', - body: { - contentType: 'html', - content: - '\r\nReply message ', - }, - sender: { - emailAddress: { - name: 'Michael Kret', - address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', - }, - }, - from: { - emailAddress: { - name: 'Michael Kret', - address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', - }, - }, - toRecipients: [ - { - emailAddress: { - name: 'reply@mail.com', - address: 'reply@mail.com', - }, - }, - ], - ccRecipients: [], - bccRecipients: [], - replyTo: [], - flag: { - flagStatus: 'notFlagged', - }, - }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, message => reply', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/reply.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(2); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', + nock('https://graph.microsoft.com/v1.0/me') + .post( '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEJAABZf4De-LkrSqpPI8eyjUmAAAFXBEVwAAA=/createReply', { message: { @@ -103,16 +13,73 @@ describe('Test MicrosoftOutlookV2, message => reply', () => { subject: 'Reply Subject', }, }, - ); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', + ) + .reply(200, { + '@odata.context': + "https://graph.microsoft.com/v1.0/$metadata#users('b834447b-6848-4af9-8390-d2259ce46b74')/messages/$entity", + '@odata.etag': 'W/"CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3CX+"', + id: 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDurAAA=', + createdDateTime: '2023-09-04T12:29:59Z', + lastModifiedDateTime: '2023-09-04T12:29:59Z', + changeKey: 'CQAAABYAAABZf4De/LkrSqpPI8eyjUmAAAFW3CX+', + categories: [], + receivedDateTime: '2023-09-04T12:29:59Z', + sentDateTime: '2023-09-04T12:29:59Z', + hasAttachments: false, + internetMessageId: + '', + subject: 'Reply Subject', + bodyPreview: 'Reply message', + importance: 'high', + parentFolderId: + 'AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAuAAAAAABPLqzvT6b9RLP0CKzHiJrRAQBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAAA=', + conversationId: + 'AAQkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OAAQAKwkQLinj69KtoFOxMG2lVY=', + conversationIndex: 'AQHZ3yq3rCRAuKePr0q2gU7EwbaVVrAKmLQ4', + isDeliveryReceiptRequested: false, + isReadReceiptRequested: false, + isRead: true, + isDraft: true, + webLink: + 'https://outlook.office365.com/owa/?ItemID=AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De%2FLkrSqpPI8eyjUmAAAAAAAEPAABZf4De%2FLkrSqpPI8eyjUmAAAFXBDurAAA%3D&exvsurl=1&viewmodel=ReadMessageItem', + inferenceClassification: 'focused', + body: { + contentType: 'html', + content: + '\r\nReply message ', + }, + sender: { + emailAddress: { + name: 'Michael Kret', + address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', + }, + }, + from: { + emailAddress: { + name: 'Michael Kret', + address: 'MichaelDevSandbox@5w1hb7.onmicrosoft.com', + }, + }, + toRecipients: [ + { + emailAddress: { + name: 'reply@mail.com', + address: 'reply@mail.com', + }, + }, + ], + ccRecipients: [], + bccRecipients: [], + replyTo: [], + flag: { + flagStatus: 'notFlagged', + }, + }) + .post( '/messages/AAMkADlhOTA0MTc5LWUwOTMtNDRkZS05NzE0LTNlYmI0ZWM5OWI5OABGAAAAAABPLqzvT6b9RLP0CKzHiJrRBwBZf4De-LkrSqpPI8eyjUmAAAAAAAEPAABZf4De-LkrSqpPI8eyjUmAAAFXBDurAAA=/send', - ); + ) + .reply(200); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/reply.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/send.test.ts b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/send.test.ts index cb494ed1fa..c6037bf244 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/send.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/send.test.ts @@ -1,57 +1,20 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -jest.mock('../../../../v2/transport', () => { - const originalModule = jest.requireActual('../../../../v2/transport'); - return { - ...originalModule, - microsoftApiRequest: jest.fn(async function (method: string) { - if (method === 'POST') { - return {}; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftOutlookV2, message => send', () => { - const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/send.workflow.json']; - const tests = workflowToTests(workflows); - 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(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); - expect(transport.microsoftApiRequest).toHaveBeenCalledWith( - 'POST', - '/sendMail', - { - message: { - body: { content: 'message description', contentType: 'Text' }, - replyTo: [{ emailAddress: { address: 'reply@mail.com' } }], - subject: 'Hello', - toRecipients: [{ emailAddress: { address: 'to@mail.com' } }], - }, - saveToSentItems: true, + nock('https://graph.microsoft.com') + .post('/v1.0/me/sendMail', { + message: { + body: { content: 'message description', contentType: 'Text' }, + replyTo: [{ emailAddress: { address: 'reply@mail.com' } }], + subject: 'Hello', + toRecipients: [{ emailAddress: { address: 'to@mail.com' } }], }, - {}, - ); + saveToSentItems: true, + }) + .reply(200, {}); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Outlook/test/v2/node/message/send.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/create.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/create.test.ts index 1475749e52..a0ddb0cbde 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/create.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_create.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should create blob', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -66,7 +55,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/delete.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/delete.test.ts index 05f79edbb9..be3d050c22 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/delete.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/delete.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_delete.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should delete blob', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -35,7 +24,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/get.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/get.test.ts index d4e8f09b07..fb7ccb3970 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/get.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_get.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get blob', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -87,7 +76,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAll.test.ts index 9825dc79cf..518b2cb3cb 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAll.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_getAll.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get all blobs', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -36,7 +25,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAllLimitOptions.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAllLimitOptions.test.ts index a151a04285..73379146e8 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAllLimitOptions.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/blob/getAllLimitOptions.test.ts @@ -1,6 +1,4 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = [ @@ -8,16 +6,7 @@ describe('Azure Storage Node', () => { ]; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get all blobs with limit and options', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -31,7 +20,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/container/create.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/container/create.test.ts index 5cbca9859d..fdaeb52852 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/container/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/container/create.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_create.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should create container', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -38,7 +27,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/container/delete.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/container/delete.test.ts index 3c24f07480..24b8d69f81 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/container/delete.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/container/delete.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_delete.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should delete container', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -35,7 +24,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/container/get.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/container/get.test.ts index 50248d8fc2..8e7bb36902 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/container/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/container/get.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_get.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get container', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -44,7 +33,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAll.test.ts index 3b6ea5ceaf..409cc9b507 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAll.test.ts @@ -1,21 +1,10 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_getAll.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get all containers', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -36,7 +25,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAllLimitOptions.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAllLimitOptions.test.ts index d859f16cc7..1cbd1252f3 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAllLimitOptions.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/container/getAllLimitOptions.test.ts @@ -1,6 +1,4 @@ -import nock from 'nock'; - -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = [ @@ -8,16 +6,7 @@ describe('Azure Storage Node', () => { ]; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should get all containers with limit and options', () => { - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -31,7 +20,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/oauth2.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/oauth2.test.ts index 2e78af10fd..9eaafeb4ff 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/oauth2.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/oauth2.test.ts @@ -3,25 +3,16 @@ import type { IDataObject, IHttpRequestOptions, } from 'n8n-workflow'; -import nock from 'nock'; -import { CredentialsHelper, equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { CredentialsHelper } from '@test/nodes/credentials-helper'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_oauth2.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should use correct oauth2 credentials', () => { beforeAll(() => { - nock.disableNetConnect(); - jest .spyOn(CredentialsHelper.prototype, 'authenticate') .mockImplementation( @@ -45,12 +36,9 @@ describe('Azure Storage Node', () => { }); afterAll(() => { - nock.restore(); jest.restoreAllMocks(); }); - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { baseUrl: 'https://myaccount.blob.core.windows.net', @@ -59,7 +47,6 @@ describe('Azure Storage Node', () => { method: 'get', path: '/mycontainer?restype=container', statusCode: 200, - requestHeaders: { authorization: 'bearer ACCESSTOKEN' }, responseBody: '', responseHeaders: { 'content-length': '0', @@ -80,7 +67,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/sharedKey.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/sharedKey.test.ts index 7804c226de..cc5d7689c7 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/sharedKey.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials/sharedKey.test.ts @@ -1,26 +1,18 @@ import type { ICredentialDataDecryptedObject, IHttpRequestOptions } from 'n8n-workflow'; -import nock from 'nock'; -import { CredentialsHelper, equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { CredentialsHelper } from '@test/nodes/credentials-helper'; +import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; +import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; import { AzureStorageSharedKeyApi } from '../../../../../credentials/AzureStorageSharedKeyApi.credentials'; -import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap'; describe('Azure Storage Node', () => { + const { account, baseUrl, key } = FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi; const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_sharedKey.workflow.json']; const workflowTests = workflowToTests(workflows); - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('should use correct shared key credentials', () => { beforeAll(() => { - nock.disableNetConnect(); - jest .spyOn(CredentialsHelper.prototype, 'authenticate') .mockImplementation( @@ -45,24 +37,17 @@ describe('Azure Storage Node', () => { }); afterAll(() => { - nock.restore(); jest.restoreAllMocks(); }); - const nodeTypes = setup(workflowTests); - for (const workflow of workflowTests) { workflow.nock = { - baseUrl: 'https://myaccount.blob.core.windows.net', + baseUrl, mocks: [ { method: 'get', path: '/mycontainer?restype=container', statusCode: 200, - requestHeaders: { - authorization: - 'SharedKey Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', - }, responseBody: '', responseHeaders: { 'content-length': '0', @@ -83,7 +68,7 @@ describe('Azure Storage Node', () => { }, ], }; - test(workflow.description, async () => await equalityTest(workflow, nodeTypes)); + test(workflow.description, async () => await equalityTest(workflow)); } }); @@ -92,11 +77,11 @@ describe('Azure Storage Node', () => { it('should remove undefined query parameters and headers', async () => { const credentials: ICredentialDataDecryptedObject = { - account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account, - key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key, + account, + key, }; const requestOptions: IHttpRequestOptions = { - url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer`, + url: `${baseUrl}/mycontainer`, qs: { restype: 'container', query1: undefined }, headers: { 'Content-Length': undefined, @@ -112,11 +97,11 @@ describe('Azure Storage Node', () => { it('should default method to GET if not provided', async () => { const credentials: ICredentialDataDecryptedObject = { - account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account, - key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key, + account, + key, }; const requestOptions: IHttpRequestOptions = { - url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer`, + url: `${baseUrl}/mycontainer`, qs: { restype: 'container' }, headers: { 'Content-Length': undefined, @@ -129,11 +114,11 @@ describe('Azure Storage Node', () => { it('should generate a valid authorization header', async () => { const credentials: ICredentialDataDecryptedObject = { - account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account, - key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key, + account, + key, }; const requestOptions: IHttpRequestOptions = { - url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer/myblob`, + url: `${baseUrl}/mycontainer/myblob`, qs: { param1: 'value1' }, headers: { 'x-ms-date': 'Thu, 27 Feb 2025 11:05:49 GMT', diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/listSearch/listSearch.test.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/listSearch/listSearch.test.ts index 8e4688d00f..fe4d2da7a9 100644 --- a/packages/nodes-base/nodes/Microsoft/Storage/test/listSearch/listSearch.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/listSearch/listSearch.test.ts @@ -1,18 +1,11 @@ import type { ILoadOptionsFunctions, INodeParameterResourceLocator } from 'n8n-workflow'; -import nock from 'nock'; -import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap'; +import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; + import { AzureStorage } from '../../AzureStorage.node'; import { XMsVersion } from '../../GenericFunctions'; describe('Azure Storage Node', () => { - beforeEach(() => { - // https://github.com/nock/nock/issues/2057#issuecomment-663665683 - if (!nock.isActive()) { - nock.activate(); - } - }); - describe('List search', () => { it('should list search blobs', async () => { const mockResponse = diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.test.ts index 6e5eef1b7f..52357f1fb3 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/create.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test MicrosoftTeamsV2, channel => create', () => { + nock('https://graph.microsoft.com') + .post('/v1.0/teams/1644e7fe-547e-4223-a24f-922395865343/channels') + .reply(200, { '@odata.context': "https://graph.microsoft.com/v1.0/$metadata#teams('1644e7fe-547e-4223-a24f-922395865343')/channels/$entity", id: '19:16259efabba44a66916d91dd91862a6f@thread.tacv2', @@ -22,39 +17,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { 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); - 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)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.test.ts index 6ffe72bbe4..2285408b17 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.test.ts @@ -1,43 +1,14 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'DELETE') { - return {}; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, channel => deleteChannel', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.workflow.json']; - const tests = workflowToTests(workflows); - 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', + nock('https://graph.microsoft.com') + .delete( '/v1.0/teams/1644e7fe-547e-4223-a24f-922395865343/channels/19:16259efabba44a66916d91dd91862a6f@thread.tacv2', - ); + ) + .reply(200, {}); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/get.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/get.test.ts index 6d46fa9e69..e816dd86a3 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/get.test.ts @@ -1,16 +1,13 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return { +describe('Test MicrosoftTeamsV2, channel => get', () => { + nock('https://graph.microsoft.com') + .get( + '/v1.0/teams/e25bae35-7bcc-4fb7-b4f2-0d5caef251fd/channels/19:dff84a49e5124cc89dff0192c621ea0f@thread.tacv2', + ) + .reply(200, { '@odata.context': "https://graph.microsoft.com/v1.0/$metadata#teams('e25bae35-7bcc-4fb7-b4f2-0d5caef251fd')/channels/$entity", id: '19:dff84a49e5124cc89dff0192c621ea0f@thread.tacv2', @@ -23,34 +20,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { webUrl: 'https://teams.microsoft.com/l/channel/19%3Adff84a49e5124cc89dff0192c621ea0f%40thread.tacv2/General?groupId=e25bae35-7bcc-4fb7-b4f2-0d5caef251fd&tenantId=tenantId-111-222-333&allowXTenantAccess=True', membershipType: 'standard', - }; - } -}); - -describe('Test MicrosoftTeamsV2, channel => get', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/get.workflow.json']; - const tests = workflowToTests(workflows); - 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/teams/e25bae35-7bcc-4fb7-b4f2-0d5caef251fd/channels/19:dff84a49e5124cc89dff0192c621ea0f@thread.tacv2', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/getAll.test.ts index ed462d0d2c..57db7670e3 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/getAll.test.ts @@ -1,82 +1,51 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequestAllItems'); - -microsoftApiRequestSpy.mockImplementation(async (_, method: string) => { - if (method === 'GET') { - return [ - { - id: '42:aaabbbccc.tacv2', - createdDateTime: '2022-03-26T17:18:33Z', - displayName: 'Sales West', - description: 'Description of Sales West', - isFavoriteByDefault: null, - email: null, - tenantId: 'tenantId-111-222-333', - webUrl: - 'https://teams.microsoft.com/l/channel/threadId/Sales%20West?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', - membershipType: 'standard', - }, - { - id: '19:8662cdf2d8ff49eabdcf6364bc0fe3a2@thread.tacv2', - createdDateTime: '2022-03-26T17:18:30Z', - displayName: 'Sales East', - description: 'Description of Sales West', - isFavoriteByDefault: null, - email: null, - tenantId: 'tenantId-111-222-333', - webUrl: - 'https://teams.microsoft.com/l/channel/19%3A8662cdf2d8ff49eabdcf6364bc0fe3a2%40thread.tacv2/Sales%20East?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', - membershipType: 'standard', - }, - { - id: '19:a95209ede91f4d5595ac944aeb172124@thread.tacv2', - createdDateTime: '2022-03-26T17:18:16Z', - displayName: 'General', - description: 'Description of U.S. Sales', - isFavoriteByDefault: null, - email: 'U.S.Sales@5w1hb7.onmicrosoft.com', - tenantId: 'tenantId-111-222-333', - webUrl: - 'https://teams.microsoft.com/l/channel/19%3Aa95209ede91f4d5595ac944aeb172124%40thread.tacv2/U.S.%20Sales?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', - membershipType: 'standard', - }, - ]; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, channel => getAll', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com') + .get('/v1.0/teams/1111-2222-3333/channels') + .reply(200, { + value: [ + { + id: '42:aaabbbccc.tacv2', + createdDateTime: '2022-03-26T17:18:33Z', + displayName: 'Sales West', + description: 'Description of Sales West', + isFavoriteByDefault: null, + email: null, + tenantId: 'tenantId-111-222-333', + webUrl: + 'https://teams.microsoft.com/l/channel/threadId/Sales%20West?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', + membershipType: 'standard', + }, + { + id: '19:8662cdf2d8ff49eabdcf6364bc0fe3a2@thread.tacv2', + createdDateTime: '2022-03-26T17:18:30Z', + displayName: 'Sales East', + description: 'Description of Sales West', + isFavoriteByDefault: null, + email: null, + tenantId: 'tenantId-111-222-333', + webUrl: + 'https://teams.microsoft.com/l/channel/19%3A8662cdf2d8ff49eabdcf6364bc0fe3a2%40thread.tacv2/Sales%20East?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', + membershipType: 'standard', + }, + { + id: '19:a95209ede91f4d5595ac944aeb172124@thread.tacv2', + createdDateTime: '2022-03-26T17:18:16Z', + displayName: 'General', + description: 'Description of U.S. Sales', + isFavoriteByDefault: null, + email: 'U.S.Sales@5w1hb7.onmicrosoft.com', + tenantId: 'tenantId-111-222-333', + webUrl: + 'https://teams.microsoft.com/l/channel/19%3Aa95209ede91f4d5595ac944aeb172124%40thread.tacv2/U.S.%20Sales?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&allowXTenantAccess=False', + membershipType: 'standard', + }, + ], }); - expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1); - expect(microsoftApiRequestSpy).toHaveBeenCalledWith( - 'value', - 'GET', - '/v1.0/teams/1111-2222-3333/channels', - {}, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/update.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/update.test.ts index c1868a2eac..adb615621b 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channel/update.test.ts @@ -1,44 +1,15 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'PATCH') { - return {}; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, channel => update', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/update.workflow.json']; - const tests = workflowToTests(workflows); - 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( - 'PATCH', + nock('https://graph.microsoft.com') + .patch( '/v1.0/teams/e25bae35-7bcc-4fb7-b4f2-0d5caef251fd/channels/19:b9daa3647ff8450bacaf39490d3e05e2@thread.tacv2', { description: 'new channel description', displayName: 'New Deals' }, - ); + ) + .reply(200, {}); - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/update.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/create.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/create.test.ts index 6e1659c2bd..f62194fa8c 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/create.test.ts @@ -1,16 +1,13 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test MicrosoftTeamsV2, channelMessage => create', () => { + nock('https://graph.microsoft.com') + .post('/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages', { + body: { content: 'new sale', contentType: 'html' }, + }) + .reply(200, { '@odata.context': "https://graph.microsoft.com/beta/$metadata#teams('1111-2222-3333')/channels('threadId')/messages/$entity", id: '1698324478896', @@ -52,35 +49,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { attachments: [], mentions: [], reactions: [], - }; - } -}); - -describe('Test MicrosoftTeamsV2, channelMessage => create', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/create.workflow.json']; - const tests = workflowToTests(workflows); - 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', - '/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages', - { body: { content: 'new sale', contentType: 'html' } }, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.test.ts index 5c5a86085f..958f7d19e7 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.test.ts @@ -1,98 +1,68 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequestAllItems'); - -microsoftApiRequestSpy.mockImplementation(async (_, method: string) => { - if (method === 'GET') { - return [ - { - id: '1698130964682', - replyToId: null, - etag: '1698130964682', - messageType: 'message', - createdDateTime: '2023-10-24T07:02:44.682Z', - lastModifiedDateTime: '2023-10-24T07:02:44.682Z', - lastEditedDateTime: null, - deletedDateTime: null, - subject: '', - summary: null, - chatId: null, - importance: 'normal', - locale: 'en-us', - webUrl: - 'https://teams.microsoft.com/l/message/threadId/1698130964682?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&createdTime=1698130964682&parentMessageId=1698130964682', - onBehalfOf: null, - policyViolation: null, - eventDetail: null, - from: { - application: null, - device: null, - user: { - '@odata.type': '#microsoft.graph.teamworkUserIdentity', - id: '11111-2222-3333', - displayName: 'My Name', - userIdentityType: 'aadUser', - tenantId: 'tenantId-111-222-333', - }, - }, - body: { - contentType: 'html', - content: - '
I added a tab at the top of this channel. Check it out!
', - }, - channelIdentity: { - teamId: '1111-2222-3333', - channelId: '42:aaabbbccc.tacv2', - }, - attachments: [ - { - id: 'tab::f22a0494-6f7c-4512-85c5-e4ce72ce142a', - contentType: 'tabReference', - contentUrl: null, - content: null, - name: 'Tasks', - thumbnailUrl: null, - teamsAppId: null, - }, - ], - mentions: [], - reactions: [], - }, - ]; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, channelMessage => getAll', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com') + .get('/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages') + .reply(200, { + value: [ + { + id: '1698130964682', + replyToId: null, + etag: '1698130964682', + messageType: 'message', + createdDateTime: '2023-10-24T07:02:44.682Z', + lastModifiedDateTime: '2023-10-24T07:02:44.682Z', + lastEditedDateTime: null, + deletedDateTime: null, + subject: '', + summary: null, + chatId: null, + importance: 'normal', + locale: 'en-us', + webUrl: + 'https://teams.microsoft.com/l/message/threadId/1698130964682?groupId=1111-2222-3333&tenantId=tenantId-111-222-333&createdTime=1698130964682&parentMessageId=1698130964682', + onBehalfOf: null, + policyViolation: null, + eventDetail: null, + from: { + application: null, + device: null, + user: { + '@odata.type': '#microsoft.graph.teamworkUserIdentity', + id: '11111-2222-3333', + displayName: 'My Name', + userIdentityType: 'aadUser', + tenantId: 'tenantId-111-222-333', + }, + }, + body: { + contentType: 'html', + content: + '
I added a tab at the top of this channel. Check it out!
', + }, + channelIdentity: { + teamId: '1111-2222-3333', + channelId: '42:aaabbbccc.tacv2', + }, + attachments: [ + { + id: 'tab::f22a0494-6f7c-4512-85c5-e4ce72ce142a', + contentType: 'tabReference', + contentUrl: null, + content: null, + name: 'Tasks', + thumbnailUrl: null, + teamsAppId: null, + }, + ], + mentions: [], + reactions: [], + }, + ], }); - expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1); - expect(microsoftApiRequestSpy).toHaveBeenCalledWith( - 'value', - 'GET', - '/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/create.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/create.test.ts index 1954ecd77a..d448575074 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/create.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test MicrosoftTeamsV2, chatMessage => create', () => { + nock('https://graph.microsoft.com') + .post('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages') + .reply(200, { '@odata.context': "https://graph.microsoft.com/v1.0/$metadata#chats('19%3Aebed9ad42c904d6c83adf0db360053ec%40thread.v2')/messages/$entity", id: '1698378560692', @@ -48,35 +43,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { attachments: [], mentions: [], reactions: [], - }; - } -}); - -describe('Test MicrosoftTeamsV2, chatMessage => create', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/create.workflow.json']; - const tests = workflowToTests(workflows); - 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/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages', - expect.anything(), - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/get.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/get.test.ts index 62e7ae485b..0218981ecc 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/get.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return { +describe('Test MicrosoftTeamsV2, chatMessage => get', () => { + nock('https://graph.microsoft.com') + .get('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages/1698378560692') + .reply(200, { '@odata.context': "https://graph.microsoft.com/v1.0/$metadata#chats('19%3Aebed9ad42c904d6c83adf0db360053ec%40thread.v2')/messages/$entity", id: '1698378560692', @@ -49,34 +44,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { attachments: [], mentions: [], reactions: [], - }; - } -}); - -describe('Test MicrosoftTeamsV2, chatMessage => get', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/get.workflow.json']; - const tests = workflowToTests(workflows); - 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/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages/1698378560692', - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.test.ts index 1ac2774de3..00f3fa1c6d 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.test.ts @@ -1,122 +1,91 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequestAllItems'); - -microsoftApiRequestSpy.mockImplementation(async (_, method: string) => { - if (method === 'GET') { - return [ - { - id: '1698378560692', - replyToId: null, - etag: '1698378560692', - messageType: 'message', - createdDateTime: '2023-10-27T03:49:20.692Z', - lastModifiedDateTime: '2023-10-27T03:49:20.692Z', - lastEditedDateTime: null, - deletedDateTime: null, - subject: null, - summary: null, - chatId: '19:ebed9ad42c904d6c83adf0db360053ec@thread.v2', - importance: 'normal', - locale: 'en-us', - webUrl: null, - channelIdentity: null, - policyViolation: null, - eventDetail: null, - from: { - application: null, - device: null, - user: { - '@odata.type': '#microsoft.graph.teamworkUserIdentity', - id: '11111-2222-3333', - displayName: 'Michael Kret', - userIdentityType: 'aadUser', - tenantId: '23786ca6-7ff2-4672-87d0-5c649ee0a337', - }, - }, - body: { - contentType: 'html', - content: - 'Hello!
\n
\n Powered by this n8n workflow ', - }, - attachments: [], - mentions: [], - reactions: [], - }, - { - id: '1698129297101', - replyToId: null, - etag: '1698129297101', - messageType: 'message', - createdDateTime: '2023-10-24T06:34:57.101Z', - lastModifiedDateTime: '2023-10-24T06:34:57.101Z', - lastEditedDateTime: null, - deletedDateTime: null, - subject: null, - summary: null, - chatId: '19:ebed9ad42c904d6c83adf0db360053ec@thread.v2', - importance: 'normal', - locale: 'en-us', - webUrl: null, - channelIdentity: null, - policyViolation: null, - eventDetail: null, - from: { - application: null, - device: null, - user: { - '@odata.type': '#microsoft.graph.teamworkUserIdentity', - id: '11111-2222-3333', - displayName: 'Michael Kret', - userIdentityType: 'aadUser', - tenantId: '23786ca6-7ff2-4672-87d0-5c649ee0a337', - }, - }, - body: { - contentType: 'html', - content: - 'tada
\n
\n Powered by this n8n workflow ', - }, - attachments: [], - mentions: [], - reactions: [], - }, - ]; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, chatMessage => getAll', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com') + .get('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages') + .reply(200, { + value: [ + { + id: '1698378560692', + replyToId: null, + etag: '1698378560692', + messageType: 'message', + createdDateTime: '2023-10-27T03:49:20.692Z', + lastModifiedDateTime: '2023-10-27T03:49:20.692Z', + lastEditedDateTime: null, + deletedDateTime: null, + subject: null, + summary: null, + chatId: '19:ebed9ad42c904d6c83adf0db360053ec@thread.v2', + importance: 'normal', + locale: 'en-us', + webUrl: null, + channelIdentity: null, + policyViolation: null, + eventDetail: null, + from: { + application: null, + device: null, + user: { + '@odata.type': '#microsoft.graph.teamworkUserIdentity', + id: '11111-2222-3333', + displayName: 'Michael Kret', + userIdentityType: 'aadUser', + tenantId: '23786ca6-7ff2-4672-87d0-5c649ee0a337', + }, + }, + body: { + contentType: 'html', + content: + 'Hello!
\n
\n Powered by this n8n workflow ', + }, + attachments: [], + mentions: [], + reactions: [], + }, + { + id: '1698129297101', + replyToId: null, + etag: '1698129297101', + messageType: 'message', + createdDateTime: '2023-10-24T06:34:57.101Z', + lastModifiedDateTime: '2023-10-24T06:34:57.101Z', + lastEditedDateTime: null, + deletedDateTime: null, + subject: null, + summary: null, + chatId: '19:ebed9ad42c904d6c83adf0db360053ec@thread.v2', + importance: 'normal', + locale: 'en-us', + webUrl: null, + channelIdentity: null, + policyViolation: null, + eventDetail: null, + from: { + application: null, + device: null, + user: { + '@odata.type': '#microsoft.graph.teamworkUserIdentity', + id: '11111-2222-3333', + displayName: 'Michael Kret', + userIdentityType: 'aadUser', + tenantId: '23786ca6-7ff2-4672-87d0-5c649ee0a337', + }, + }, + body: { + contentType: 'html', + content: + 'tada
\n
\n Powered by this n8n workflow ', + }, + attachments: [], + mentions: [], + reactions: [], + }, + ], }); - expect(microsoftApiRequestSpy).toHaveBeenCalledTimes(1); - expect(microsoftApiRequestSpy).toHaveBeenCalledWith( - 'value', - 'GET', - '/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages', - {}, - ); - - expect(result.finished).toEqual(true); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/create.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/create.test.ts index 60635dd0dc..d4a2ce1f8f 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/create.test.ts @@ -1,16 +1,23 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'POST') { - return { +describe('Test MicrosoftTeamsV2, task => create', () => { + nock('https://graph.microsoft.com') + .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', + }) + .reply(200, { '@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity', '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="', planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf', @@ -60,43 +67,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { }, }, }, - }; - } -}); + }); -describe('Test MicrosoftTeamsV2, task => create', () => { const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/create.workflow.json']; - const tests = workflowToTests(workflows); - 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)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/deleteTask.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/deleteTask.test.ts index f3442cb31d..745a564609 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/deleteTask.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/deleteTask.test.ts @@ -1,56 +1,15 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'DELETE') { - return {}; - } - if (method === 'GET') { - return { - '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="', - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, task => deleteTask', () => { + nock('https://graph.microsoft.com') + .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') + .reply(200, { '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="' }) + .delete('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') + .matchHeader('If-Match', 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="') + .reply(200, {}); + const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/deleteTask.workflow.json']; - const tests = workflowToTests(workflows); - 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)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/get.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/get.test.ts index 7f41b6e471..1b97df264d 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/get.test.ts @@ -1,16 +1,11 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { testWorkflows } from '@test/nodes/Helpers'; -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'GET') { - return { +describe('Test MicrosoftTeamsV2, task => get', () => { + nock('https://graph.microsoft.com') + .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') + .reply(200, { '@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity', '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="', planId: 'THwgIivuyU26ki8qS7ufcJgAB6zf', @@ -60,34 +55,8 @@ microsoftApiRequestSpy.mockImplementation(async (method: string) => { }, }, }, - }; - } -}); - -describe('Test MicrosoftTeamsV2, task => get', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/get.workflow.json']; - const tests = workflowToTests(workflows); - 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)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/getAll.test.ts index 177d34e938..680a38236a 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/getAll.test.ts @@ -1,192 +1,151 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -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', - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, task => getAll', () => { - const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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]); + nock('https://graph.microsoft.com') + .get('/v1.0/me') + .reply(200, { id: '123456789' }) + .get('/v1.0/users/123456789/planner/tasks') + .reply(200, { + value: [ + { + '@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', + }, + }, + }, + }, + }, + ], }); - 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)); - } + const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/update.test.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/update.test.ts index a48fc67b20..b320ab729e 100644 --- a/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/v2/node/task/update.test.ts @@ -1,56 +1,19 @@ -import type { INodeTypes } from 'n8n-workflow'; +import nock from 'nock'; -import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; - -import * as transport from '../../../../v2/transport'; - -const microsoftApiRequestSpy = jest.spyOn(transport, 'microsoftApiRequest'); - -microsoftApiRequestSpy.mockImplementation(async (method: string) => { - if (method === 'PATCH') { - return {}; - } - if (method === 'GET') { - return { - '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="', - }; - } -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test MicrosoftTeamsV2, task => update', () => { + nock('https://graph.microsoft.com') + .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') + .reply(200, { '@odata.etag': 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="' }) + .patch('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD', { + dueDateTime: '2023-10-24T21:00:00.000Z', + percentComplete: 78, + title: 'do that', + }) + .matchHeader('If-Match', 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="') + .reply(200); + const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/update.workflow.json']; - const tests = workflowToTests(workflows); - 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)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts b/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts index 087c1f461c..f2a77fc5e6 100644 --- a/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts +++ b/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test Move Binary Data Node', () => { beforeEach(async () => { @@ -116,11 +116,9 @@ describe('Test Move Binary Data Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts b/packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts index b31cd493f7..f2f50bde9f 100644 --- a/packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts +++ b/packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts @@ -1,33 +1,22 @@ -import type { INodeTypes } from 'n8n-workflow'; +import { mock } from 'jest-mock-extended'; +import type { Connection, QueryResult } from 'mysql2/promise'; +import type { WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { getResultNodeData, workflowToTests } from '@test/nodes/Helpers'; -const queryMock = jest.fn(async function () { - return [{ success: true }]; -}); - -jest.mock('../../v1/GenericFunctions', () => { - const originalModule = jest.requireActual('../../v1/GenericFunctions'); - return { - ...originalModule, - createConnection: jest.fn(async function () { - return { - query: queryMock, - end: jest.fn(), - }; - }), - }; -}); +const mockConnection = mock(); +const createConnection = jest.fn().mockReturnValue(mockConnection); +jest.mock('mysql2/promise', () => ({ createConnection })); describe('Test MySqlV1, executeQuery', () => { + mockConnection.query.mockResolvedValue([{ success: true } as unknown as QueryResult, []]); + const workflows = ['nodes/MySql/test/v1/executeQuery.workflow.json']; const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); - const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { - const { result } = await executeWorkflow(testData, types); + const testNode = async (testData: WorkflowTestData) => { + const { result } = await executeWorkflow(testData); const resultNodeData = getResultNodeData(result, testData); @@ -35,8 +24,8 @@ describe('Test MySqlV1, executeQuery', () => { return expect(resultData).toEqual(testData.output.nodeData[nodeName]); }); - expect(queryMock).toHaveBeenCalledTimes(1); - expect(queryMock).toHaveBeenCalledWith( + expect(mockConnection.query).toHaveBeenCalledTimes(1); + expect(mockConnection.query).toHaveBeenCalledWith( "select * from family_parents where (parent_email = 'parent1@mail.com' or parent_email = 'parent2@mail.com') and parent_email <> '';", ); @@ -44,6 +33,6 @@ describe('Test MySqlV1, executeQuery', () => { }; for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); + test(testData.description, async () => await testNode(testData)); } }); diff --git a/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts b/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts index 75b5bff71a..b38860f0ec 100644 --- a/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts +++ b/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts @@ -1,9 +1,8 @@ -import type { INodeTypes } from 'n8n-workflow'; +import type { WorkflowTestData } from 'n8n-workflow'; import nock from 'nock'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { setup, workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; +import { workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; describe('Test N8n Node, expect base_url to be received from credentials', () => { const workflows = getWorkflowFilenames(__dirname); @@ -14,15 +13,14 @@ describe('Test N8n Node, expect base_url to be received from credentials', () => const baseUrl = 'https://test.app.n8n.cloud/api/v1'; nock(baseUrl).get('/workflows?tags=n8n-test').reply(200, {}); }); - const nodeTypes = setup(tests); - const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { - const { result } = await executeWorkflow(testData, types); + const testNode = async (testData: WorkflowTestData) => { + const { result } = await executeWorkflow(testData); expect(result.finished).toEqual(true); }; for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); + test(testData.description, async () => await testNode(testData)); } }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts index cd9de28fa5..205664cc9b 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/append.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'list', @@ -411,24 +411,11 @@ const API_RESPONSE = { request_id: '33358f1b-fc4d-4387-8d95-43c7d03519a5', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'PATCH') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, block => append', () => { - const workflows = ['nodes/Notion/test/node/v2/block/append.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .patch('/v1/blocks/90e03468f8aa457695da02ccad963040/children') + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/block/append.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts index 44d1490cd5..c5c887b185 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/block/getAll.test.ts @@ -1,230 +1,220 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'block', - id: 'b14bdaaf-b7e9-48c9-a7fa-1b9e1e2092ae', - parent: { - type: 'block_id', - block_id: '90e03468-f8aa-4576-95da-02ccad963040', - }, - created_time: '2023-11-23T10:42:00.000Z', - last_edited_time: '2024-12-13T03:35:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - has_children: true, - archived: false, - in_trash: false, - type: 'toggle', - toggle: { - color: 'default', - text: [ - { - type: 'text', - text: { - content: 'Drop down First', - link: null, +const API_RESPONSE = { + results: [ + { + object: 'block', + id: 'b14bdaaf-b7e9-48c9-a7fa-1b9e1e2092ae', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2024-12-13T03:35:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: true, + archived: false, + in_trash: false, + type: 'toggle', + toggle: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Drop down First', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Drop down First', + href: null, }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', + ], + }, + }, + { + object: 'block', + id: 'de572f5d-ff5c-4c13-a879-efc20fe47db0', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2024-03-11T12:39:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + has_children: true, + archived: false, + in_trash: false, + type: 'bulleted_list_item', + bulleted_list_item: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Bullet Point Second', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Bullet Point Second', + href: null, }, - plain_text: 'Drop down First', - href: null, - }, - ], + ], + }, }, - }, - { - object: 'block', - id: 'de572f5d-ff5c-4c13-a879-efc20fe47db0', - parent: { - type: 'block_id', - block_id: '90e03468-f8aa-4576-95da-02ccad963040', - }, - created_time: '2023-11-23T10:42:00.000Z', - last_edited_time: '2024-03-11T12:39:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - has_children: true, - archived: false, - in_trash: false, - type: 'bulleted_list_item', - bulleted_list_item: { - color: 'default', - text: [ - { - type: 'text', - text: { - content: 'Bullet Point Second', - link: null, + { + object: 'block', + id: 'c98cf981-c967-47f5-9948-4aa1be9ce9d0', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-24T04:41:00.000Z', + last_edited_time: '2024-12-13T03:35:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'heading_2', + heading_2: { + is_toggleable: false, + color: 'default', + text: [ + { + type: 'text', + text: { + content: 'Hello World', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Hello World', + href: null, }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', + ], + }, + }, + { + object: 'block', + id: '527a0555-a486-401e-93a8-19819615c132', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2023-11-23T10:42:00.000Z', + last_edited_time: '2023-11-23T10:43:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'child_page', + child_page: { + title: 'Page Third', + }, + }, + { + object: 'block', + id: '15bfb9cb-4cf0-81b1-a6f1-eac377c4d163', + parent: { + type: 'block_id', + block_id: '90e03468-f8aa-4576-95da-02ccad963040', + }, + created_time: '2024-12-13T03:40:00.000Z', + last_edited_time: '2024-12-13T06:15:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + has_children: false, + archived: false, + in_trash: false, + type: 'paragraph', + paragraph: { + color: 'default', + text: [ + { + type: 'text', + text: { + content: '', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: '', + href: null, }, - plain_text: 'Bullet Point Second', - href: null, - }, - ], + ], + }, }, - }, - { - object: 'block', - id: 'c98cf981-c967-47f5-9948-4aa1be9ce9d0', - parent: { - type: 'block_id', - block_id: '90e03468-f8aa-4576-95da-02ccad963040', - }, - created_time: '2023-11-24T04:41:00.000Z', - last_edited_time: '2024-12-13T03:35:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - has_children: false, - archived: false, - in_trash: false, - type: 'heading_2', - heading_2: { - is_toggleable: false, - color: 'default', - text: [ - { - type: 'text', - text: { - content: 'Hello World', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'Hello World', - href: null, - }, - ], - }, - }, - { - object: 'block', - id: '527a0555-a486-401e-93a8-19819615c132', - parent: { - type: 'block_id', - block_id: '90e03468-f8aa-4576-95da-02ccad963040', - }, - created_time: '2023-11-23T10:42:00.000Z', - last_edited_time: '2023-11-23T10:43:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - has_children: false, - archived: false, - in_trash: false, - type: 'child_page', - child_page: { - title: 'Page Third', - }, - }, - { - object: 'block', - id: '15bfb9cb-4cf0-81b1-a6f1-eac377c4d163', - parent: { - type: 'block_id', - block_id: '90e03468-f8aa-4576-95da-02ccad963040', - }, - created_time: '2024-12-13T03:40:00.000Z', - last_edited_time: '2024-12-13T06:15:00.000Z', - created_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - has_children: false, - archived: false, - in_trash: false, - type: 'paragraph', - paragraph: { - color: 'default', - text: [ - { - type: 'text', - text: { - content: '', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: '', - href: null, - }, - ], - }, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); + ], + has_more: false, +}; describe('Test NotionV2, block => getAll', () => { - const workflows = ['nodes/Notion/test/node/v2/block/getAll.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .get('/v1/blocks/90e03468f8aa457695da02ccad963040/children') + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/block/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts index 44b12ea385..bcb91a6b58 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/get.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'database', @@ -65,24 +65,11 @@ const API_RESPONSE = { request_id: 'd22a9046-be0d-4ef5-b551-8691da552d47', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, database => get', () => { - const workflows = ['nodes/Notion/test/node/v2/database/get.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .get('/v1/databases/138fb9cb-4cf0-804c-8663-d8ecdd5e692f') + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/database/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts index de5ebcb33c..99e1c4fde4 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/getAll.test.ts @@ -1,329 +1,319 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'database', - id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', - cover: null, - icon: null, - created_time: '2024-11-08T07:59:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', +const API_RESPONSE = { + results: [ + { + object: 'database', + id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + cover: null, + icon: null, + created_time: '2024-11-08T07:59:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:59:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'TEST_DB', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'TEST_DB', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', + public_url: null, + archived: false, + in_trash: false, }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + { + object: 'database', + id: 'f7216195-e0d4-46cd-a2d3-587a05baf472', + cover: null, + icon: null, + created_time: '2022-03-07T11:25:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:54:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'ListDatabase', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'ListDatabase', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Email: { + id: 'Fitu', + name: 'Email', + type: 'email', + email: {}, + }, + 'Last edited by': { + id: 'XZ~H', + name: 'Last edited by', + type: 'last_edited_by', + last_edited_by: {}, + }, + Tags: { + id: 'a%7BRG', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Created: { + id: 'eqq~', + name: 'Created', + type: 'created_time', + created_time: {}, + }, + Status: { + id: 'nZEQ', + name: 'Status', + type: 'status', + status: { + options: [ + { + id: '70312bf9-84d5-40e6-b1eb-d71798ee556f', + name: 'Not started', + color: 'default', + description: null, + }, + { + id: '02a6bb40-3f4b-47d6-818d-6a4129cc6091', + name: 'In progress', + color: 'gray', + description: null, + }, + { + id: 'a3c13d01-63b2-4571-8a02-8c1801649af7', + name: 'Done', + color: 'green', + description: null, + }, + ], + groups: [ + { + id: '82e2022c-001d-47ac-a8b8-243ef7fac352', + name: 'To-do', + color: 'gray', + option_ids: ['70312bf9-84d5-40e6-b1eb-d71798ee556f'], + }, + { + id: '296000d7-287e-4121-9445-98fa8f7de298', + name: 'In progress', + color: 'blue', + option_ids: ['02a6bb40-3f4b-47d6-818d-6a4129cc6091'], + }, + { + id: 'db7689ae-127d-4218-8b3c-306e59e02070', + name: 'Complete', + color: 'green', + option_ids: ['a3c13d01-63b2-4571-8a02-8c1801649af7'], + }, + ], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/f7216195e0d446cda2d3587a05baf472', + public_url: 'https://pleasant-halloumi-63e.notion.site/f7216195e0d446cda2d3587a05baf472', + archived: false, + in_trash: false, }, - last_edited_time: '2024-11-08T07:59:00.000Z', - title: [ - { - type: 'text', - text: { - content: 'TEST_DB', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'TEST_DB', - href: null, + { + object: 'database', + id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', + cover: null, + icon: null, + created_time: '2022-03-07T11:05:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', }, - ], - description: [], - is_inline: false, - properties: { - Tags: { - id: '%40~Tp', - name: 'Tags', - type: 'multi_select', - multi_select: { - options: [], + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2023-09-29T08:00:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'n8n-trigger', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'n8n-trigger', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Total: { + id: 'A%3DdW', + name: 'Total', + type: 'formula', + formula: { + expression: + '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', + }, + }, + 'Total Incomes': { + id: 'MH~%3B', + name: 'Total Incomes', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Expenses': { + id: 'MwMd', + name: 'Total Expenses', + type: 'number', + number: { + format: 'number', + }, + }, + 'Created time': { + id: 'Z%3BGM', + name: 'Created time', + type: 'created_time', + created_time: {}, + }, + 'Last edited time': { + id: '%60%5ElG', + name: 'Last edited time', + type: 'last_edited_time', + last_edited_time: {}, + }, + 'Total Transfer-In': { + id: 'fJea', + name: 'Total Transfer-In', + type: 'number', + number: { + format: 'number', + }, + }, + 'Starting Balance': { + id: 'n%7DI%5E', + name: 'Starting Balance', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Transfer-Out': { + id: 'rSrM', + name: 'Total Transfer-Out', + type: 'number', + number: { + format: 'number', + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, }, }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', }, + url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', + public_url: null, + archived: false, + in_trash: false, }, - parent: { - type: 'page_id', - page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', - }, - url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', - public_url: null, - archived: false, - in_trash: false, - }, - { - object: 'database', - id: 'f7216195-e0d4-46cd-a2d3-587a05baf472', - cover: null, - icon: null, - created_time: '2022-03-07T11:25:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_time: '2024-11-08T07:54:00.000Z', - title: [ - { - type: 'text', - text: { - content: 'ListDatabase', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'ListDatabase', - href: null, - }, - ], - description: [], - is_inline: false, - properties: { - Email: { - id: 'Fitu', - name: 'Email', - type: 'email', - email: {}, - }, - 'Last edited by': { - id: 'XZ~H', - name: 'Last edited by', - type: 'last_edited_by', - last_edited_by: {}, - }, - Tags: { - id: 'a%7BRG', - name: 'Tags', - type: 'multi_select', - multi_select: { - options: [], - }, - }, - Created: { - id: 'eqq~', - name: 'Created', - type: 'created_time', - created_time: {}, - }, - Status: { - id: 'nZEQ', - name: 'Status', - type: 'status', - status: { - options: [ - { - id: '70312bf9-84d5-40e6-b1eb-d71798ee556f', - name: 'Not started', - color: 'default', - description: null, - }, - { - id: '02a6bb40-3f4b-47d6-818d-6a4129cc6091', - name: 'In progress', - color: 'gray', - description: null, - }, - { - id: 'a3c13d01-63b2-4571-8a02-8c1801649af7', - name: 'Done', - color: 'green', - description: null, - }, - ], - groups: [ - { - id: '82e2022c-001d-47ac-a8b8-243ef7fac352', - name: 'To-do', - color: 'gray', - option_ids: ['70312bf9-84d5-40e6-b1eb-d71798ee556f'], - }, - { - id: '296000d7-287e-4121-9445-98fa8f7de298', - name: 'In progress', - color: 'blue', - option_ids: ['02a6bb40-3f4b-47d6-818d-6a4129cc6091'], - }, - { - id: 'db7689ae-127d-4218-8b3c-306e59e02070', - name: 'Complete', - color: 'green', - option_ids: ['a3c13d01-63b2-4571-8a02-8c1801649af7'], - }, - ], - }, - }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, - }, - }, - parent: { - type: 'page_id', - page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', - }, - url: 'https://www.notion.so/f7216195e0d446cda2d3587a05baf472', - public_url: 'https://pleasant-halloumi-63e.notion.site/f7216195e0d446cda2d3587a05baf472', - archived: false, - in_trash: false, - }, - { - object: 'database', - id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', - cover: null, - icon: null, - created_time: '2022-03-07T11:05:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_time: '2023-09-29T08:00:00.000Z', - title: [ - { - type: 'text', - text: { - content: 'n8n-trigger', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'n8n-trigger', - href: null, - }, - ], - description: [], - is_inline: false, - properties: { - Total: { - id: 'A%3DdW', - name: 'Total', - type: 'formula', - formula: { - expression: - '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', - }, - }, - 'Total Incomes': { - id: 'MH~%3B', - name: 'Total Incomes', - type: 'number', - number: { - format: 'number', - }, - }, - 'Total Expenses': { - id: 'MwMd', - name: 'Total Expenses', - type: 'number', - number: { - format: 'number', - }, - }, - 'Created time': { - id: 'Z%3BGM', - name: 'Created time', - type: 'created_time', - created_time: {}, - }, - 'Last edited time': { - id: '%60%5ElG', - name: 'Last edited time', - type: 'last_edited_time', - last_edited_time: {}, - }, - 'Total Transfer-In': { - id: 'fJea', - name: 'Total Transfer-In', - type: 'number', - number: { - format: 'number', - }, - }, - 'Starting Balance': { - id: 'n%7DI%5E', - name: 'Starting Balance', - type: 'number', - number: { - format: 'number', - }, - }, - 'Total Transfer-Out': { - id: 'rSrM', - name: 'Total Transfer-Out', - type: 'number', - number: { - format: 'number', - }, - }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, - }, - }, - parent: { - type: 'page_id', - page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', - }, - url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', - public_url: null, - archived: false, - in_trash: false, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); + ], + has_more: false, +}; describe('Test NotionV2, database => getAll', () => { - const workflows = ['nodes/Notion/test/node/v2/database/getAll.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .post('/v1/search', { filter: { property: 'object', value: 'database' } }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/database/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts index 1aeb937f19..74cfc44eab 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/database/search.test.ts @@ -1,203 +1,197 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'database', - id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', - cover: null, - icon: null, - created_time: '2022-03-07T11:05:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', +const API_RESPONSE = { + results: [ + { + object: 'database', + id: 'e9c354e3-e506-4c42-83e2-d9c81a083f05', + cover: null, + icon: null, + created_time: '2022-03-07T11:05:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2023-09-29T08:00:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'n8n-trigger', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'n8n-trigger', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Total: { + id: 'A%3DdW', + name: 'Total', + type: 'formula', + formula: { + expression: + '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', + }, + }, + 'Total Incomes': { + id: 'MH~%3B', + name: 'Total Incomes', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Expenses': { + id: 'MwMd', + name: 'Total Expenses', + type: 'number', + number: { + format: 'number', + }, + }, + 'Created time': { + id: 'Z%3BGM', + name: 'Created time', + type: 'created_time', + created_time: {}, + }, + 'Last edited time': { + id: '%60%5ElG', + name: 'Last edited time', + type: 'last_edited_time', + last_edited_time: {}, + }, + 'Total Transfer-In': { + id: 'fJea', + name: 'Total Transfer-In', + type: 'number', + number: { + format: 'number', + }, + }, + 'Starting Balance': { + id: 'n%7DI%5E', + name: 'Starting Balance', + type: 'number', + number: { + format: 'number', + }, + }, + 'Total Transfer-Out': { + id: 'rSrM', + name: 'Total Transfer-Out', + type: 'number', + number: { + format: 'number', + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', + public_url: null, + archived: false, + in_trash: false, }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + { + object: 'database', + id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + cover: null, + icon: null, + created_time: '2024-11-08T07:59:00.000Z', + created_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_by: { + object: 'user', + id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', + }, + last_edited_time: '2024-11-08T07:59:00.000Z', + title: [ + { + type: 'text', + text: { + content: 'TEST_DB', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'TEST_DB', + href: null, + }, + ], + description: [], + is_inline: false, + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + parent: { + type: 'page_id', + page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', + }, + url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', + public_url: null, + archived: false, + in_trash: false, }, - last_edited_time: '2023-09-29T08:00:00.000Z', - title: [ - { - type: 'text', - text: { - content: 'n8n-trigger', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'n8n-trigger', - href: null, - }, - ], - description: [], - is_inline: false, - properties: { - Total: { - id: 'A%3DdW', - name: 'Total', - type: 'formula', - formula: { - expression: - '((({{notion:block_property:n%7DI%5E:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}} + {{notion:block_property:MH~%3B:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:MwMd:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) + {{notion:block_property:fJea:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}) - {{notion:block_property:rSrM:00000000-0000-0000-0000-000000000000:fe91914e-2dc5-4510-82f8-399dd9b2daf8}}', - }, - }, - 'Total Incomes': { - id: 'MH~%3B', - name: 'Total Incomes', - type: 'number', - number: { - format: 'number', - }, - }, - 'Total Expenses': { - id: 'MwMd', - name: 'Total Expenses', - type: 'number', - number: { - format: 'number', - }, - }, - 'Created time': { - id: 'Z%3BGM', - name: 'Created time', - type: 'created_time', - created_time: {}, - }, - 'Last edited time': { - id: '%60%5ElG', - name: 'Last edited time', - type: 'last_edited_time', - last_edited_time: {}, - }, - 'Total Transfer-In': { - id: 'fJea', - name: 'Total Transfer-In', - type: 'number', - number: { - format: 'number', - }, - }, - 'Starting Balance': { - id: 'n%7DI%5E', - name: 'Starting Balance', - type: 'number', - number: { - format: 'number', - }, - }, - 'Total Transfer-Out': { - id: 'rSrM', - name: 'Total Transfer-Out', - type: 'number', - number: { - format: 'number', - }, - }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, - }, - }, - parent: { - type: 'page_id', - page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', - }, - url: 'https://www.notion.so/e9c354e3e5064c4283e2d9c81a083f05', - public_url: null, - archived: false, - in_trash: false, - }, - { - object: 'database', - id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', - cover: null, - icon: null, - created_time: '2024-11-08T07:59:00.000Z', - created_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_by: { - object: 'user', - id: '88f72c1a-07ed-4bae-9fa0-231365d813d9', - }, - last_edited_time: '2024-11-08T07:59:00.000Z', - title: [ - { - type: 'text', - text: { - content: 'TEST_DB', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'TEST_DB', - href: null, - }, - ], - description: [], - is_inline: false, - properties: { - Tags: { - id: '%40~Tp', - name: 'Tags', - type: 'multi_select', - multi_select: { - options: [], - }, - }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, - }, - }, - parent: { - type: 'page_id', - page_id: 'cc3d2b3c-f31a-4773-ab39-17a60c54567a', - }, - url: 'https://www.notion.so/138fb9cb4cf0804c8663d8ecdd5e692f', - public_url: null, - archived: false, - in_trash: false, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); + ], + has_more: false, +}; describe('Test NotionV2, database => search', () => { - const workflows = ['nodes/Notion/test/node/v2/database/search.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .post('/v1/search', { + filter: { property: 'object', value: 'database' }, + query: 't', + sort: { direction: 'ascending', timestamp: 'last_edited_time' }, + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/database/search.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts index 0cf2222ee3..4820339649 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/create.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'page', @@ -61,44 +61,46 @@ const API_RESPONSE = { request_id: '1416702d-daa8-4f8d-9be3-c55fe52486b5', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return { - properties: { - Tags: { - id: '%40~Tp', - name: 'Tags', - type: 'multi_select', - multi_select: { - options: [], - }, - }, - Name: { - id: 'title', - name: 'Name', - type: 'title', - title: {}, - }, - }, - }; - } - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, databasePage => create', () => { - const workflows = ['nodes/Notion/test/node/v2/databasePage/create.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .get('/v1/databases/138fb9cb-4cf0-804c-8663-d8ecdd5e692f') + .reply(200, { + properties: { + Tags: { + id: '%40~Tp', + name: 'Tags', + type: 'multi_select', + multi_select: { + options: [], + }, + }, + Name: { + id: 'title', + name: 'Name', + type: 'title', + title: {}, + }, + }, + }) + .post('/v1/pages', { + parent: { database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f' }, + properties: { Name: { title: [{ text: { content: 'new name 1' } }] } }, + children: [ + { + object: 'block', + type: 'paragraph', + paragraph: { text: [{ text: { content: 'new text' } }] }, + }, + { + object: 'block', + type: 'toggle', + toggle: { text: [{ text: { content: 'new toggle' } }] }, + }, + ], + icon: { emoji: '😗' }, + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/databasePage/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts index b6164ddd11..cfdd875161 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/get.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'page', @@ -61,24 +61,11 @@ const API_RESPONSE = { request_id: 'c01d3a3e-d9c3-4e48-8d73-077a8503c3ba', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, databasePage => get', () => { - const workflows = ['nodes/Notion/test/node/v2/databasePage/get.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .get('/v1/pages/15bfb9cb4cf081c7aab4c5855b8cb6c3') + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/databasePage/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts index 07e20be464..64571a5bf2 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/getAll.test.ts @@ -1,85 +1,78 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'page', - id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', - created_time: '2024-12-13T04:45:00.000Z', - last_edited_time: '2024-12-13T04:45:00.000Z', - created_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - last_edited_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - cover: null, - icon: { - type: 'emoji', - emoji: '😗', - }, - parent: { - type: 'database_id', - database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', - }, - archived: false, - in_trash: false, - properties: { - Tags: { - id: '%40~Tp', - type: 'multi_select', - multi_select: [], +const API_RESPONSE = { + results: [ + { + object: 'page', + id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + created_time: '2024-12-13T04:45:00.000Z', + last_edited_time: '2024-12-13T04:45:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', }, - Name: { - id: 'title', - type: 'title', - title: [ - { - type: 'text', - text: { - content: 'new name 1', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'new name 1', - href: null, - }, - ], + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', }, + cover: null, + icon: { + type: 'emoji', + emoji: '😗', + }, + parent: { + type: 'database_id', + database_id: '138fb9cb-4cf0-804c-8663-d8ecdd5e692f', + }, + archived: false, + in_trash: false, + properties: { + Tags: { + id: '%40~Tp', + type: 'multi_select', + multi_select: [], + }, + Name: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'new name 1', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'new name 1', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3', + public_url: null, }, - url: 'https://www.notion.so/new-name-1-15bfb9cb4cf081c7aab4c5855b8cb6c3', - public_url: null, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); + ], + has_more: false, +}; describe('Test NotionV2, databasePage => getAll', () => { - const workflows = ['nodes/Notion/test/node/v2/databasePage/getAll.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .post('/v1/databases/138fb9cb-4cf0-804c-8663-d8ecdd5e692f/query', { + filter: { or: [{ property: 'Name', title: { contains: 'new' } }] }, + sorts: [{ direction: 'ascending', property: 'Name' }], + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/databasePage/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts index 964525e571..b7f3ae3440 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/databasePage/update.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'page', @@ -61,24 +61,13 @@ const API_RESPONSE = { request_id: 'a4683091-f165-4f10-92b4-a629b8b1266e', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'PATCH') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, databasePage => update', () => { - const workflows = ['nodes/Notion/test/node/v2/databasePage/update.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .patch('/v1/pages/15bfb9cb4cf081c7aab4c5855b8cb6c3', { + properties: { Name: { title: [{ text: { content: 'Updated Name' } }] } }, + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/databasePage/update.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts index e4d75c7089..9d8a004fcd 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/archive.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'page', @@ -61,24 +61,11 @@ const API_RESPONSE = { request_id: 'ce91abaa-261f-43c3-9237-57c0f28af682', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'PATCH') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, page => archive', () => { - const workflows = ['nodes/Notion/test/node/v2/page/archive.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .patch('/v1/pages/15bfb9cb4cf081c7aab4c5855b8cb6c3', { archived: true }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/page/archive.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts index 3f8373d023..2f1101d008 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/create.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'page', @@ -56,24 +56,27 @@ const API_RESPONSE = { request_id: 'df28ec00-4361-46af-a3b6-add18c8d1295', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, page => create', () => { - const workflows = ['nodes/Notion/test/node/v2/page/create.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .post('/v1/pages', { + parent: { page_id: '15bfb9cb4cf081c7aab4c5855b8cb6c3' }, + properties: { title: [{ text: { content: 'Child page' } }] }, + children: [ + { + object: 'block', + type: 'heading_1', + heading_1: { text: [{ type: 'text', text: { content: 'Title' }, annotations: {} }] }, + }, + { + object: 'block', + type: 'paragraph', + paragraph: { text: [{ text: { content: 'text' } }] }, + }, + ], + icon: { emoji: '😊' }, + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/page/create.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts index 7ec0dceb79..ad359d039a 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/page/search.test.ts @@ -1,80 +1,74 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'page', - id: '15bfb9cb-4cf0-812b-b4bc-c85cd00727f8', - created_time: '2024-12-13T06:01:00.000Z', - last_edited_time: '2024-12-13T06:01:00.000Z', - created_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - last_edited_by: { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - }, - cover: null, - icon: { - type: 'emoji', - emoji: '😊', - }, - parent: { - type: 'page_id', - page_id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', - }, - archived: false, - in_trash: false, - properties: { - title: { - id: 'title', - type: 'title', - title: [ - { - type: 'text', - text: { - content: 'Child page', - link: null, - }, - annotations: { - bold: false, - italic: false, - strikethrough: false, - underline: false, - code: false, - color: 'default', - }, - plain_text: 'Child page', - href: null, - }, - ], +const API_RESPONSE = { + results: [ + { + object: 'page', + id: '15bfb9cb-4cf0-812b-b4bc-c85cd00727f8', + created_time: '2024-12-13T06:01:00.000Z', + last_edited_time: '2024-12-13T06:01:00.000Z', + created_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', }, + last_edited_by: { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + }, + cover: null, + icon: { + type: 'emoji', + emoji: '😊', + }, + parent: { + type: 'page_id', + page_id: '15bfb9cb-4cf0-81c7-aab4-c5855b8cb6c3', + }, + archived: false, + in_trash: false, + properties: { + title: { + id: 'title', + type: 'title', + title: [ + { + type: 'text', + text: { + content: 'Child page', + link: null, + }, + annotations: { + bold: false, + italic: false, + strikethrough: false, + underline: false, + code: false, + color: 'default', + }, + plain_text: 'Child page', + href: null, + }, + ], + }, + }, + url: 'https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8', + public_url: null, }, - url: 'https://www.notion.so/Child-page-15bfb9cb4cf0812bb4bcc85cd00727f8', - public_url: null, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); + ], + has_more: false, +}; describe('Test NotionV2, page => search', () => { - const workflows = ['nodes/Notion/test/node/v2/page/search.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .post('/v1/search', { + query: 'child', + filter: { property: 'object', value: 'page' }, + sort: { direction: 'ascending', timestamp: 'last_edited_time' }, + }) + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/page/search.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts index a8c971ef2e..695f9d07e0 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/get.test.ts @@ -1,6 +1,6 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { object: 'user', @@ -12,24 +12,11 @@ const API_RESPONSE = { request_id: 'ad2a00c0-fa6a-4a14-bf9a-68e1715b51a1', }; -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test NotionV2, user => get', () => { - const workflows = ['nodes/Notion/test/node/v2/user/get.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com') + .get('/v1/users/34a945c6-de97-4efc-90d6-6d7cc14a6583') + .reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/user/get.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts index 44a5138704..3182dd49e0 100644 --- a/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts +++ b/packages/nodes-base/nodes/Notion/test/node/v2/user/getAll.test.ts @@ -1,59 +1,47 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -const API_RESPONSE = [ - { - object: 'user', - id: 'f215e49c-4677-40c0-9adc-87440d341324', - name: 'n8n-test', - avatar_url: null, - type: 'bot', - bot: { - owner: { - type: 'workspace', - workspace: true, +const API_RESPONSE = { + results: [ + { + object: 'user', + id: 'f215e49c-4677-40c0-9adc-87440d341324', + name: 'n8n-test', + avatar_url: null, + type: 'bot', + bot: { + owner: { + type: 'workspace', + workspace: true, + }, + workspace_name: "Michael Kret's Notion", }, - workspace_name: "Michael Kret's Notion", }, - }, - { - object: 'user', - id: '34a945c6-de97-4efc-90d6-6d7cc14a6583', - name: 'second', - avatar_url: null, - type: 'bot', - bot: {}, - }, - { - object: 'user', - id: '2598a5de-49b3-4acd-adad-20f6b18c9fbe', - name: 'DryMerge', - avatar_url: - 'https://s3-us-west-2.amazonaws.com/public.notion-static.com/e67863a3-a867-4355-a602-c9830dbb1828/Primary_(recommended).jpg', - type: 'bot', - bot: {}, - }, -]; - -jest.mock('../../../../shared/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../shared/GenericFunctions'); - return { - ...originalModule, - notionApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); + { + object: 'user', + id: '34a945c6-de97-4efc-90d6-6d7cc14a6583', + name: 'second', + avatar_url: null, + type: 'bot', + bot: {}, + }, + { + object: 'user', + id: '2598a5de-49b3-4acd-adad-20f6b18c9fbe', + name: 'DryMerge', + avatar_url: + 'https://s3-us-west-2.amazonaws.com/public.notion-static.com/e67863a3-a867-4355-a602-c9830dbb1828/Primary_(recommended).jpg', + type: 'bot', + bot: {}, + }, + ], + has_more: false, +}; describe('Test NotionV2, user => getAll', () => { - const workflows = ['nodes/Notion/test/node/v2/user/getAll.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://api.notion.com').get('/v1/users').reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Notion/test/node/v2/user/getAll.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/OpenWeatherMap/test/OpenWeatherMap.test.ts b/packages/nodes-base/nodes/OpenWeatherMap/test/OpenWeatherMap.test.ts index 45079bbc8a..d9ad280b34 100644 --- a/packages/nodes-base/nodes/OpenWeatherMap/test/OpenWeatherMap.test.ts +++ b/packages/nodes-base/nodes/OpenWeatherMap/test/OpenWeatherMap.test.ts @@ -1,14 +1,11 @@ import nock from 'nock'; -import { setup, equalityTest, workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { currentWeatherResponse } from './apiResponses'; describe('OpenWeatherMap', () => { describe('Run OpenWeatherMap workflow', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { nock('https://api.openweathermap.org') .get('/data/2.5/weather') @@ -16,10 +13,7 @@ describe('OpenWeatherMap', () => { .reply(200, currentWeatherResponse); }); - const nodeTypes = setup(tests); - - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/nodes/Oura/test/oura.node.test.ts b/packages/nodes-base/nodes/Oura/test/oura.node.test.ts index 5e4a1ad45c..a010b97884 100644 --- a/packages/nodes-base/nodes/Oura/test/oura.node.test.ts +++ b/packages/nodes-base/nodes/Oura/test/oura.node.test.ts @@ -7,7 +7,7 @@ import type { } from 'n8n-workflow'; import nock from 'nock'; -import { setup, equalityTest, workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { profileResponse } from './apiResponses'; import { ouraApiRequest } from '../GenericFunctions'; @@ -52,19 +52,13 @@ describe('Oura', () => { }); }); describe('Run Oura workflow', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { nock('https://api.ouraring.com/v2') .get('/usercollection/personal_info') .reply(200, profileResponse); }); - const nodeTypes = setup(tests); - - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/nodes/Peekalink/test/Peekalink.node.test.ts b/packages/nodes-base/nodes/Peekalink/test/Peekalink.node.test.ts index d0ce8775c1..2827260e65 100644 --- a/packages/nodes-base/nodes/Peekalink/test/Peekalink.node.test.ts +++ b/packages/nodes-base/nodes/Peekalink/test/Peekalink.node.test.ts @@ -1,8 +1,7 @@ -import { NodeConnectionTypes } from 'n8n-workflow'; +import { NodeConnectionTypes, type WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; import { apiUrl } from '../Peekalink.node'; @@ -167,10 +166,8 @@ describe('Peekalink Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - test.each(tests)('$description', async (testData) => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => expect(resultData).toEqual(testData.output.nodeData[nodeName]), diff --git a/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts b/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts index 4608552137..75e16d6754 100644 --- a/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts +++ b/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts @@ -1,23 +1,16 @@ import nock from 'nock'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { deleteLightResponse, getLightsResponse, getConfigResponse, updateLightResponse, } from './apiResponses'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, -} from '../../../test/nodes/Helpers'; describe('PhilipsHue', () => { describe('Run workflow', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { const mock = nock('https://api.meethue.com/route'); mock.persist().get('/api/0/config').reply(200, getConfigResponse); @@ -26,10 +19,7 @@ describe('PhilipsHue', () => { mock.delete('/api/pAtwdCV8NZId25Gk/lights/1').reply(200, deleteLightResponse); }); - const nodeTypes = setup(tests); - - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/test/nodes/Postgres/Postgres.node.functions.test.ts b/packages/nodes-base/nodes/Postgres/test/Postgres.node.functions.test.ts similarity index 85% rename from packages/nodes-base/test/nodes/Postgres/Postgres.node.functions.test.ts rename to packages/nodes-base/nodes/Postgres/test/Postgres.node.functions.test.ts index 42b88b7338..811b94ca1b 100644 --- a/packages/nodes-base/test/nodes/Postgres/Postgres.node.functions.test.ts +++ b/packages/nodes-base/nodes/Postgres/test/Postgres.node.functions.test.ts @@ -1,9 +1,14 @@ -const pgPromise = require('pg-promise'); +import { mock } from 'jest-mock-extended'; +import pgPromise from 'pg-promise'; -const PostgresFun = require('../../../nodes/Postgres/v1/genericFunctions'); +import * as PostgresFun from '../v1/genericFunctions'; +import type { PgpDatabase } from '../v2/helpers/interfaces'; type NodeParams = Record; +const pgp = pgPromise(); +const db = mock(); + describe('pgUpdate', () => { it('runs query to update db', async () => { const updateItem = { id: 1234, name: 'test' }; @@ -16,9 +21,6 @@ describe('pgUpdate', () => { returnFields: '*', }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -44,9 +46,6 @@ describe('pgUpdate', () => { returnFields: '*', }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -72,9 +71,6 @@ describe('pgUpdate', () => { returnFields: '*', }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -100,9 +96,6 @@ describe('pgUpdate', () => { returnFields: '*', }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -129,9 +122,6 @@ describe('pgInsert', () => { additionalFields: {}, }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -139,7 +129,7 @@ describe('pgInsert', () => { }, ]; - await PostgresFun.pgInsert(getNodeParam, pgp, db, items); + await PostgresFun.pgInsert(getNodeParam, pgp, db, items, false); expect(db.any).toHaveBeenCalledWith( 'insert into "myschema"."mytable"("id","name","age") values(1234,\'test\',34) RETURNING *', @@ -156,9 +146,6 @@ describe('pgInsert', () => { additionalFields: {}, }; const getNodeParam = (key: string) => nodeParams[key]; - const pgp = pgPromise(); - const any = jest.fn(); - const db = { any }; const items = [ { @@ -166,7 +153,7 @@ describe('pgInsert', () => { }, ]; - await PostgresFun.pgInsert(getNodeParam, pgp, db, items); + await PostgresFun.pgInsert(getNodeParam, pgp, db, items, false); expect(db.any).toHaveBeenCalledWith( 'insert into "myschema"."mytable"("id","name","age") values(1234::int,\'test\'::text,34) RETURNING *', diff --git a/packages/nodes-base/nodes/Postgres/v1/genericFunctions.ts b/packages/nodes-base/nodes/Postgres/v1/genericFunctions.ts index 3fb2982a6a..36a7dd9aae 100644 --- a/packages/nodes-base/nodes/Postgres/v1/genericFunctions.ts +++ b/packages/nodes-base/nodes/Postgres/v1/genericFunctions.ts @@ -5,6 +5,8 @@ import type pg from 'pg-promise/typescript/pg-subset'; import { getResolvables } from '@utils/utilities'; +import type { PgpDatabase } from '../v2/helpers/interfaces'; + /** * Returns of a shallow copy of the items which only contains the json data and * of that only the define properties @@ -87,14 +89,14 @@ export function wrapData(data: IDataObject[]): INodeExecutionData[] { * * @param {Function} getNodeParam The getter for the Node's parameters * @param {pgPromise.IMain<{}, pg.IClient>} pgp The pgPromise instance - * @param {pgPromise.IDatabase<{}, pg.IClient>} db The pgPromise database connection + * @param {PgpDatabase} db The pgPromise database connection * @param {input[]} input The Node's input data */ export async function pgQuery( // eslint-disable-next-line @typescript-eslint/ban-types getNodeParam: Function, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail: boolean, overrideMode?: string, @@ -170,7 +172,7 @@ export async function pgQuery( export async function pgQueryV2( this: IExecuteFunctions, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail: boolean, options?: { @@ -273,14 +275,14 @@ export async function pgQueryV2( * * @param {Function} getNodeParam The getter for the Node's parameters * @param {pgPromise.IMain<{}, pg.IClient>} pgp The pgPromise instance - * @param {pgPromise.IDatabase<{}, pg.IClient>} db The pgPromise database connection + * @param {PgpDatabase} db The pgPromise database connection * @param {INodeExecutionData[]} items The items to be inserted */ export async function pgInsert( // eslint-disable-next-line @typescript-eslint/ban-types getNodeParam: Function, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail: boolean, overrideMode?: string, @@ -364,13 +366,13 @@ export async function pgInsert( * * @param {Function} getNodeParam The getter for the Node's parameters * @param {pgPromise.IMain<{}, pg.IClient>} pgp The pgPromise instance - * @param {pgPromise.IDatabase<{}, pg.IClient>} db`` The pgPromise database connection + * @param {PgpDatabase} db`` The pgPromise database connection * @param {INodeExecutionData[]} items The items to be inserted */ export async function pgInsertV2( this: IExecuteFunctions, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail: boolean, overrideMode?: string, @@ -474,14 +476,14 @@ export async function pgInsertV2( * * @param {Function} getNodeParam The getter for the Node's parameters * @param {pgPromise.IMain<{}, pg.IClient>} pgp The pgPromise instance - * @param {pgPromise.IDatabase<{}, pg.IClient>} db The pgPromise database connection + * @param {PgpDatabase} db The pgPromise database connection * @param {INodeExecutionData[]} items The items to be updated */ export async function pgUpdate( // eslint-disable-next-line @typescript-eslint/ban-types getNodeParam: Function, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail = false, ): Promise { @@ -604,13 +606,13 @@ export async function pgUpdate( * * @param {Function} getNodeParam The getter for the Node's parameters * @param {pgPromise.IMain<{}, pg.IClient>} pgp The pgPromise instance - * @param {pgPromise.IDatabase<{}, pg.IClient>} db The pgPromise database connection + * @param {PgpDatabase} db The pgPromise database connection * @param {INodeExecutionData[]} items The items to be updated */ export async function pgUpdateV2( this: IExecuteFunctions, pgp: pgPromise.IMain<{}, pg.IClient>, - db: pgPromise.IDatabase<{}, pg.IClient>, + db: PgpDatabase, items: INodeExecutionData[], continueOnFail = false, ): Promise { diff --git a/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts b/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts index 6a271d8722..e6689182bf 100644 --- a/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts +++ b/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; import nock from 'nock'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test QuickChart Node', () => { beforeEach(async () => { @@ -89,11 +89,9 @@ describe('Test QuickChart Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { diff --git a/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts b/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts index 4f7a8e7846..2549134bbf 100644 --- a/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts +++ b/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test Read Binary File Node', () => { beforeEach(async () => { @@ -47,11 +47,9 @@ describe('Test Read Binary File Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts index ae76d88185..9c8e43c5c3 100644 --- a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test Read Binary Files Node', () => { beforeEach(async () => { @@ -62,11 +62,9 @@ describe('Test Read Binary Files Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/RssFeedRead/test/node/RssFeedRead.test.ts b/packages/nodes-base/nodes/RssFeedRead/test/node/RssFeedRead.test.ts index 451ab65bef..a5d99fad49 100644 --- a/packages/nodes-base/nodes/RssFeedRead/test/node/RssFeedRead.test.ts +++ b/packages/nodes-base/nodes/RssFeedRead/test/node/RssFeedRead.test.ts @@ -1,20 +1,15 @@ import nock from 'nock'; -import { setup, equalityTest, workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; // eslint-disable-next-line n8n-local-rules/no-unneeded-backticks const feed = `<![CDATA[Lorem ipsum feed for an interval of 1 minutes with 3 item(s)]]>http://example.com/RSS for NodeThu, 09 Feb 2023 13:40:32 GMTThu, 09 Feb 2023 13:40:00 GMT1<![CDATA[Lorem ipsum 2023-02-09T13:40:00Z]]>http://example.com/test/1675950000http://example.com/test/1675950000Thu, 09 Feb 2023 13:40:00 GMT<![CDATA[Lorem ipsum 2023-02-09T13:39:00Z]]>http://example.com/test/1675949940http://example.com/test/1675949940Thu, 09 Feb 2023 13:39:00 GMT<![CDATA[Lorem ipsum 2023-02-09T13:38:00Z]]>http://example.com/test/1675949880http://example.com/test/1675949880Thu, 09 Feb 2023 13:38:00 GMT`; describe('Test RSS Feed Trigger Node', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { nock('https://lorem-rss.herokuapp.com').get('/feed?length=3').reply(200, feed); }); - const nodeTypes = setup(tests); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts b/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts index bfb39136a8..dafa67a49f 100644 --- a/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts +++ b/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts @@ -4,22 +4,14 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; describe('Test SendGrid Node', () => { - beforeAll(() => { - nock.disableNetConnect(); - }); - describe('Mail', () => { - const sendgridNock = nock('https://api.sendgrid.com/v3'); - - beforeAll(() => { - sendgridNock - .post( - '/mail/send', - (body: { reply_to_list?: [{ email: string }] }) => - body?.reply_to_list?.[0]?.email === 'test-reply-to@n8n.io', - ) - .reply(202); - }); + const sendgridNock = nock('https://api.sendgrid.com/v3') + .post( + '/mail/send', + (body: { reply_to_list?: [{ email: string }] }) => + body?.reply_to_list?.[0]?.email === 'test-reply-to@n8n.io', + ) + .reply(202); testWorkflows(['nodes/SendGrid/test/mail.workflow.json']); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/channel/archive.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/channel/archive.test.ts index 8ad2fee93d..2eef606aa1 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/channel/archive.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/channel/archive.test.ts @@ -1,29 +1,14 @@ -import type { IHttpRequestMethods } from 'n8n-workflow'; +import nock from 'nock'; -import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, channel => append', () => { - const workflows = ['nodes/Slack/test/v2/node/channel/archive.workflow.json']; - const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); + nock('https://slack.com').post('/api/conversations.archive').reply(200, API_RESPONSE); - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = ['nodes/Slack/test/v2/node/channel/archive.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/channel/create.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/channel/create.test.ts index 239c5d611a..8719913051 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/channel/create.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/channel/create.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -48,42 +45,9 @@ const API_RESPONSE = { }, }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, channel => create', () => { + nock('https://slack.com').post('/api/conversations.create').reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/channel/create.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/conversations.create', - { is_private: false, name: 'test-003' }, - {}, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/channel/get.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/channel/get.test.ts index 87759f2e44..a53a17e876 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/channel/get.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/channel/get.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -47,42 +44,11 @@ const API_RESPONSE = { }, }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, channel => get', () => { + nock('https://slack.com') + .post('/api/conversations.info?channel=C085WNEHP4Y') + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/channel/get.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/conversations.info', - {}, - { channel: 'C085WNEHP4Y' }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/channel/getAll.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/channel/getAll.test.ts index 5d93684dca..68f7f15c59 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/channel/getAll.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/channel/getAll.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -110,42 +107,13 @@ const API_RESPONSE = { }, }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, channel => getAll', () => { + nock('https://slack.com') + .get( + '/api/conversations.list?types=public_channel%2Cprivate_channel%2Cim%2Cmpim&exclude_archived=true&limit=2', + ) + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/channel/getAll.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'GET', - '/conversations.list', - {}, - { exclude_archived: true, limit: 2, types: 'public_channel,private_channel,im,mpim' }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/channel/history.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/channel/history.test.ts index 9d371ecb34..31d44c6eef 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/channel/history.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/channel/history.test.ts @@ -1,208 +1,176 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; +import { testWorkflows } from '@test/nodes/Helpers'; -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; - -const API_RESPONSE = [ - { - user: 'U0362BXQYJW', - type: 'message', - ts: '1734322597.935429', - bot_id: 'B0382SHFM46', - app_id: 'A037UTP0Z39', - text: 'test message\n_Automated with this _', - team: 'T0364MSFHV2', - bot_profile: { - id: 'B0382SHFM46', - deleted: false, - name: 'blocks-test', - updated: 1648028754, +const API_RESPONSE = { + ok: true, + messages: [ + { + user: 'U0362BXQYJW', + type: 'message', + ts: '1734322597.935429', + bot_id: 'B0382SHFM46', app_id: 'A037UTP0Z39', - icons: { - image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', - image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', - image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + text: 'test message\n_Automated with this _', + team: 'T0364MSFHV2', + bot_profile: { + id: 'B0382SHFM46', + deleted: false, + name: 'blocks-test', + updated: 1648028754, + app_id: 'A037UTP0Z39', + icons: { + image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', + image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', + image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + }, + team_id: 'T0364MSFHV2', }, - team_id: 'T0364MSFHV2', + blocks: [ + { + type: 'rich_text', + block_id: 'piR', + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: 'test message\n', + }, + { + type: 'text', + text: 'Automated with this ', + style: { + italic: true, + }, + }, + { + type: 'link', + url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd', + text: 'n8n workflow', + style: { + italic: true, + }, + }, + ], + }, + ], + }, + ], }, - blocks: [ - { - type: 'rich_text', - block_id: 'piR', - elements: [ - { - type: 'rich_text_section', - elements: [ - { - type: 'text', - text: 'test message\n', - }, - { - type: 'text', - text: 'Automated with this ', - style: { - italic: true, - }, - }, - { - type: 'link', - url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd', - text: 'n8n workflow', - style: { - italic: true, - }, - }, - ], - }, - ], - }, - ], - }, - { - user: 'U0362BXQYJW', - type: 'message', - ts: '1734322341.161179', - bot_id: 'B0382SHFM46', - app_id: 'A037UTP0Z39', - text: 'test message\n_Automated with this _', - team: 'T0364MSFHV2', - bot_profile: { - id: 'B0382SHFM46', + { + user: 'U0362BXQYJW', + type: 'message', + ts: '1734322341.161179', + bot_id: 'B0382SHFM46', app_id: 'A037UTP0Z39', - name: 'blocks-test', - icons: { - image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', - image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', - image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + text: 'test message\n_Automated with this _', + team: 'T0364MSFHV2', + bot_profile: { + id: 'B0382SHFM46', + app_id: 'A037UTP0Z39', + name: 'blocks-test', + icons: { + image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', + image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', + image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + }, + deleted: false, + updated: 1648028754, + team_id: 'T0364MSFHV2', }, - deleted: false, - updated: 1648028754, - team_id: 'T0364MSFHV2', + blocks: [ + { + type: 'rich_text', + block_id: '2BN', + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: 'test message\n', + }, + { + type: 'text', + text: 'Automated with this ', + style: { + italic: true, + }, + }, + { + type: 'link', + url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd', + text: 'n8n workflow', + style: { + italic: true, + }, + }, + ], + }, + ], + }, + ], }, - blocks: [ - { - type: 'rich_text', - block_id: '2BN', - elements: [ - { - type: 'rich_text_section', - elements: [ - { - type: 'text', - text: 'test message\n', - }, - { - type: 'text', - text: 'Automated with this ', - style: { - italic: true, - }, - }, - { - type: 'link', - url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd', - text: 'n8n workflow', - style: { - italic: true, - }, - }, - ], - }, - ], + { + user: 'U0362BXQYJW', + type: 'message', + ts: '1734321960.507649', + edited: { + user: 'B0382SHFM46', + ts: '1734324905.000000', }, - ], - }, - { - user: 'U0362BXQYJW', - type: 'message', - ts: '1734321960.507649', - edited: { - user: 'B0382SHFM46', - ts: '1734324905.000000', - }, - bot_id: 'B0382SHFM46', - app_id: 'A037UTP0Z39', - text: 'updated message', - team: 'T0364MSFHV2', - bot_profile: { - id: 'B0382SHFM46', + bot_id: 'B0382SHFM46', app_id: 'A037UTP0Z39', - name: 'blocks-test', - icons: { - image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', - image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', - image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + text: 'updated message', + team: 'T0364MSFHV2', + bot_profile: { + id: 'B0382SHFM46', + app_id: 'A037UTP0Z39', + name: 'blocks-test', + icons: { + image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png', + image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png', + image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png', + }, + deleted: false, + updated: 1648028754, + team_id: 'T0364MSFHV2', }, - deleted: false, - updated: 1648028754, - team_id: 'T0364MSFHV2', + blocks: [ + { + type: 'rich_text', + block_id: 'wR+', + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: 'updated message', + }, + ], + }, + ], + }, + ], }, - blocks: [ - { - type: 'rich_text', - block_id: 'wR+', - elements: [ - { - type: 'rich_text_section', - elements: [ - { - type: 'text', - text: 'updated message', - }, - ], - }, - ], - }, - ], - }, - { - subtype: 'channel_join', - user: 'U0362BXQYJW', - text: '<@U0362BXQYJW> has joined the channel', - type: 'message', - ts: '1734321942.689159', - }, -]; - -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); + { + subtype: 'channel_join', + user: 'U0362BXQYJW', + text: '<@U0362BXQYJW> has joined the channel', + type: 'message', + ts: '1734321942.689159', + }, + ], +}; describe('Test SlackV2, channel => history', () => { + nock('https://slack.com') + .get('/api/conversations.history?channel=C08514ZPKB8&inclusive=true&page=1&limit=100') + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/channel/history.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequestAllItems).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequestAllItems).toHaveBeenCalledWith( - 'messages', - 'GET', - '/conversations.history', - {}, - { channel: 'C08514ZPKB8', inclusive: true }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.test.ts index 6ad731e710..61832a8390 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.test.ts @@ -1,72 +1,16 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; - -const API_RESPONSE = { files: { test: 'OK' } }; - -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - if (method === 'GET') { - return { upload_url: 'https://slack.com/api/files.upload' }; - } - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test SlackV2, file => upload', () => { + nock('https://slack.com') + .get('/api/files.getUploadURLExternal?filename=test%20_name.txt&length=25') + .reply(200, { ok: true, upload_url: 'https://slack.com/api/files.upload' }) + .post('/api/files.upload', () => true) + .reply(200, { ok: true, file: { id: 'file_id' } }) + .post('/api/files.completeUploadExternal') + .reply(200, { ok: true, files: [{ id: 'file_id' }] }); + const workflows = ['nodes/Slack/test/v2/node/file/upload.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(3); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'GET', - '/files.getUploadURLExternal', - {}, - { filename: 'test _name.txt', length: 25 }, - ); - - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - 'https://slack.com/api/files.upload', - {}, - {}, - { 'Content-Type': 'multipart/form-data' }, - expect.objectContaining({ - formData: expect.any(Object), - }), - ); - - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/files.completeUploadExternal', - { - files: [{ id: undefined, title: 'Test Title' }], - initial_comment: 'test inline', - thread_ts: '1734322671.726339', - }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.workflow.json b/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.workflow.json index b22096a310..32c99185be 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.workflow.json +++ b/packages/nodes-base/nodes/Slack/test/v2/node/file/upload.workflow.json @@ -82,7 +82,7 @@ "No Operation, do nothing": [ { "json": { - "test": "OK" + "id": "file_id" } } ] diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/message/delete.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/message/delete.test.ts index 1e75a1ae9c..00aa3c56ea 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/message/delete.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/message/delete.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -11,42 +8,9 @@ const API_RESPONSE = { message_timestamp: '1734322671.726339', }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, message => delete', () => { + nock('https://slack.com').post('/api/chat.delete').reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/message/delete.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/chat.delete', - { channel: 'C08514ZPKB8', ts: '1734322671.726339' }, - {}, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/message/getPermalink.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/message/getPermalink.test.ts index a16003cdc3..868d040343 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/message/getPermalink.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/message/getPermalink.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -11,42 +8,11 @@ const API_RESPONSE = { channel: 'C08514ZPKB8', }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'GET') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, message => getPermalink', () => { + nock('https://slack.com') + .get('/api/chat.getPermalink?channel=C08514ZPKB8&message_ts=1734322671.726339') + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/message/getPermalink.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'GET', - '/chat.getPermalink', - {}, - { channel: 'C08514ZPKB8', message_ts: '1734322671.726339' }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/message/post.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/message/post.test.ts index e5f4216946..988f3821d1 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/message/post.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/message/post.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -50,51 +47,20 @@ const API_RESPONSE = { message_timestamp: '1734322671.726339', }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, message => post', () => { + nock('https://slack.com') + .post('/api/chat.postMessage', { + channel: 'C08514ZPKB8', + icon_emoji: '😁', + includeLinkToWorkflow: false, + link_names: true, + mrkdwn: true, + text: 'test message', + unfurl_links: true, + unfurl_media: true, + }) + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/message/post.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/chat.postMessage', - { - channel: 'C08514ZPKB8', - icon_emoji: '😁', - includeLinkToWorkflow: false, - link_names: true, - mrkdwn: true, - text: 'test message', - unfurl_links: true, - unfurl_media: true, - }, - {}, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/message/search.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/message/search.test.ts index a8d0426e57..da0977dec1 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/message/search.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/message/search.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -203,42 +200,11 @@ const API_RESPONSE = { }, }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, message => search', () => { + nock('https://slack.com') + .post('/api/search.messages?query=test%20in%3Atest-002&sort=timestamp&sort_dir=desc&count=2') + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/message/search.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/search.messages', - {}, - { count: 2, query: 'test in:test-002', sort: 'timestamp', sort_dir: 'desc' }, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/message/update.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/message/update.test.ts index c6484c4e5c..b79130f93f 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/message/update.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/message/update.test.ts @@ -1,9 +1,6 @@ -import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; +import { testWorkflows } from '@test/nodes/Helpers'; const API_RESPONSE = { ok: true, @@ -54,48 +51,17 @@ const API_RESPONSE = { message_timestamp: '1734321960.507649', }; -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) { - if (method === 'POST') { - return API_RESPONSE; - } - }), - }; -}); - describe('Test SlackV2, message => update', () => { + nock('https://slack.com') + .post('/api/chat.update', { + channel: 'C08514ZPKB8', + link_names: true, + parse: 'none', + text: 'updated message', + ts: '1734321960.507649', + }) + .reply(200, API_RESPONSE); + const workflows = ['nodes/Slack/test/v2/node/message/update.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/chat.update', - { - channel: 'C08514ZPKB8', - link_names: true, - parse: 'none', - text: 'updated message', - ts: '1734321960.507649', - }, - {}, - ); - }; - - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Slack/test/v2/node/user/updateProfile.test.ts b/packages/nodes-base/nodes/Slack/test/v2/node/user/updateProfile.test.ts index 19820cedb6..54482a714b 100644 --- a/packages/nodes-base/nodes/Slack/test/v2/node/user/updateProfile.test.ts +++ b/packages/nodes-base/nodes/Slack/test/v2/node/user/updateProfile.test.ts @@ -1,60 +1,26 @@ -import type { INodeTypes, WorkflowTestData } from 'n8n-workflow'; +import nock from 'nock'; -import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers'; - -import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow'; -import * as genericFunctions from '../../../../V2/GenericFunctions'; - -const API_RESPONSE = { profile: { test: 'OK' } }; - -jest.mock('../../../../V2/GenericFunctions', () => { - const originalModule = jest.requireActual('../../../../V2/GenericFunctions'); - return { - ...originalModule, - slackApiRequest: jest.fn(async function () { - return API_RESPONSE; - }), - }; -}); +import { testWorkflows } from '@test/nodes/Helpers'; describe('Test SlackV2, user => updateProfile', () => { - const workflows = ['nodes/Slack/test/v2/node/user/updateProfile.workflow.json']; - const tests = workflowToTests(workflows); - 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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1); - expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith( - 'POST', - '/users.profile.set', - { - profile: { - customFieldUi: { - customFieldValues: [{ alt: '', id: 'Xf05SGHVUDKM', value: 'TEST title' }], - }, - email: 'some@email.com', - fields: { Xf05SGHVUDKM: { alt: '', value: 'TEST title' } }, - first_name: 'first', - last_name: 'last', - status_emoji: '👶', - status_expiration: 1734670800, - status_text: 'test status', + nock('https://slack.com') + .post('/api/users.profile.set', { + profile: { + customFieldUi: { + customFieldValues: [{ alt: '', id: 'Xf05SGHVUDKM', value: 'TEST title' }], }, - user: 'id-new', + email: 'some@email.com', + fields: { Xf05SGHVUDKM: { alt: '', value: 'TEST title' } }, + first_name: 'first', + last_name: 'last', + status_emoji: '👶', + status_expiration: 1734670800, + status_text: 'test status', }, - {}, - ); - }; + user: 'id-new', + }) + .reply(200, { profile: { test: 'OK' } }); - for (const testData of tests) { - test(testData.description, async () => await testNode(testData, nodeTypes)); - } + const workflows = ['nodes/Slack/test/v2/node/user/updateProfile.workflow.json']; + testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Spotify/__tests__/workflow/workflow.test.ts b/packages/nodes-base/nodes/Spotify/__tests__/workflow/workflow.test.ts index 0ce85b7d5d..7743b9ba35 100644 --- a/packages/nodes-base/nodes/Spotify/__tests__/workflow/workflow.test.ts +++ b/packages/nodes-base/nodes/Spotify/__tests__/workflow/workflow.test.ts @@ -1,5 +1,7 @@ import nock from 'nock'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { getAlbum, getAlbumTracks, @@ -7,18 +9,9 @@ import { getNewReleases, searchForAlbum, } from './apiResponses'; -import { - setup, - equalityTest, - workflowToTests, - getWorkflowFilenames, -} from '../../../../test/nodes/Helpers'; describe('Spotify', () => { describe('Run workflow', () => { - const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); - beforeAll(() => { const mock = nock('https://api.spotify.com/v1'); mock @@ -31,10 +24,7 @@ describe('Spotify', () => { mock.get('/artists/12Chz98pHFMPJEknJQMWvI').reply(200, getArtist); }); - const nodeTypes = setup(tests); - - for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); - } + const workflows = getWorkflowFilenames(__dirname); + testWorkflows(workflows); }); }); diff --git a/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts b/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts index e599515315..11f55bcfa1 100644 --- a/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts +++ b/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts @@ -1,10 +1,9 @@ import { readFileSync } from 'fs'; -import type { IWorkflowBase } from 'n8n-workflow'; +import type { IWorkflowBase, WorkflowTestData } from 'n8n-workflow'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Execute Spreadsheet File Node', () => { beforeEach(async () => { @@ -201,13 +200,11 @@ describe('Execute Spreadsheet File Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { // eslint-disable-next-line @typescript-eslint/no-loop-func test(testData.description, async () => { // execute workflow - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); // check if result node data matches expected test data const resultNodeData = Helpers.getResultNodeData(result, testData); diff --git a/packages/nodes-base/test/nodes/Start/StartNode.test.ts b/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts similarity index 82% rename from packages/nodes-base/test/nodes/Start/StartNode.test.ts rename to packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts index f56806b8b4..ee2b22bc5d 100644 --- a/packages/nodes-base/test/nodes/Start/StartNode.test.ts +++ b/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts @@ -1,6 +1,6 @@ -import { executeWorkflow } from '../ExecuteWorkflow'; -import * as Helpers from '../Helpers'; -import type { WorkflowTestData } from '../types'; +import type { WorkflowTestData } from 'n8n-workflow'; + +import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; describe('Execute Start Node', () => { const tests: WorkflowTestData[] = [ @@ -28,12 +28,10 @@ describe('Execute Start Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { // execute workflow - const { result, nodeExecutionOrder } = await executeWorkflow(testData, nodeTypes); + const { result, nodeExecutionOrder } = await executeWorkflow(testData); // Check if the nodes did execute in the correct order expect(nodeExecutionOrder).toEqual(testData.output.nodeExecutionOrder); // Check if other data has correct value diff --git a/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts b/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts index e77e7317be..4b518b1afa 100644 --- a/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts +++ b/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts @@ -1,9 +1,7 @@ /* eslint-disable @typescript-eslint/no-loop-func */ -import { NodeConnectionTypes, type IDataObject } from 'n8n-workflow'; +import { NodeConnectionTypes, type IDataObject, type WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Execute Stop and Error Node', () => { const tests: WorkflowTestData[] = [ @@ -71,11 +69,9 @@ describe('Execute Stop and Error Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); expect(result.finished).toBeUndefined(); diff --git a/packages/nodes-base/test/nodes/Stripe/helpers.test.ts b/packages/nodes-base/nodes/Stripe/__tests__/helpers.test.ts similarity index 90% rename from packages/nodes-base/test/nodes/Stripe/helpers.test.ts rename to packages/nodes-base/nodes/Stripe/__tests__/helpers.test.ts index 099d460722..de7644ec7e 100644 --- a/packages/nodes-base/test/nodes/Stripe/helpers.test.ts +++ b/packages/nodes-base/nodes/Stripe/__tests__/helpers.test.ts @@ -1,4 +1,4 @@ -const helpers = require('../../../nodes/Stripe/helpers'); +import * as helpers from '../helpers'; describe('adjustMetadata', () => { it('it should adjust multiple metadata values', async () => { diff --git a/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts b/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts index c752eba158..ebb84ac705 100644 --- a/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts +++ b/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts @@ -1,5 +1,8 @@ import nock from 'nock'; +import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + import { getChatResponse, sendMediaGroupResponse, @@ -13,8 +16,6 @@ import { sendAudioResponse, getMemberResponse, } from './apiResponses'; -import { FAKE_CREDENTIALS_DATA } from '../../../../test/nodes/FakeCredentialsMap'; -import { getWorkflowFilenames, testWorkflows } from '../../../../test/nodes/Helpers'; describe('Telegram', () => { describe('Run Telegram workflow', () => { diff --git a/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts b/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts index f3ada2fa36..ca9afe45ee 100644 --- a/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts +++ b/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts @@ -1,6 +1,7 @@ +import type { WorkflowTestData } from 'n8n-workflow'; + import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; jest.mock('otpauth', () => { return { @@ -27,12 +28,10 @@ describe('Execute TOTP node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { // eslint-disable-next-line @typescript-eslint/no-loop-func test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); Helpers.getResultNodeData(result, testData).forEach(({ nodeName, resultData }) => { const expected = testData.output.nodeData[nodeName][0][0].json; diff --git a/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts b/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts index 1e5ac8e6c2..f85a8d3994 100644 --- a/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts +++ b/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-loop-func */ +import type { WorkflowTestData } from 'n8n-workflow'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; -import type { WorkflowTestData } from '@test/nodes/types'; describe('Test Write Binary File Node', () => { beforeEach(async () => { @@ -54,11 +54,9 @@ describe('Test Write Binary File Node', () => { }, ]; - const nodeTypes = Helpers.setup(tests); - for (const testData of tests) { test(testData.description, async () => { - const { result } = await executeWorkflow(testData, nodeTypes); + const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/test/nodes/ExecuteWorkflow.ts b/packages/nodes-base/test/nodes/ExecuteWorkflow.ts index 2b114798bf..c5b1e5ec6b 100644 --- a/packages/nodes-base/test/nodes/ExecuteWorkflow.ts +++ b/packages/nodes-base/test/nodes/ExecuteWorkflow.ts @@ -1,12 +1,24 @@ -import { WorkflowExecute } from 'n8n-core'; -import type { INodeTypes, IRun, IRunExecutionData } from 'n8n-workflow'; +import { Container } from '@n8n/di'; +import { mock } from 'jest-mock-extended'; +import { ExecutionLifecycleHooks, WorkflowExecute } from 'n8n-core'; +import type { + IRun, + IRunExecutionData, + IWorkflowExecuteAdditionalData, + WorkflowTestData, +} from 'n8n-workflow'; import { createDeferredPromise, Workflow } from 'n8n-workflow'; import nock from 'nock'; -import * as Helpers from './Helpers'; -import type { WorkflowTestData } from './types'; +import { CredentialsHelper } from './credentials-helper'; +import { NodeTypes } from './node-types'; + +// This is (temporarily) needed to setup LoadNodesAndCredentials +import './Helpers'; + +export async function executeWorkflow(testData: WorkflowTestData) { + const nodeTypes = Container.get(NodeTypes); -export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INodeTypes) { if (testData.nock) { const { baseUrl, mocks } = testData.nock; const agent = nock(baseUrl); @@ -46,7 +58,18 @@ export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INo }); const waitPromise = createDeferredPromise(); const nodeExecutionOrder: string[] = []; - const additionalData = Helpers.WorkflowExecuteAdditionalData(waitPromise, nodeExecutionOrder); + + const hooks = new ExecutionLifecycleHooks('trigger', '1', mock()); + hooks.addHandler('nodeExecuteAfter', (nodeName) => { + nodeExecutionOrder.push(nodeName); + }); + hooks.addHandler('workflowExecuteAfter', (fullRunData) => waitPromise.resolve(fullRunData)); + const additionalData = mock({ + credentialsHelper: Container.get(CredentialsHelper), + hooks, + // Get from node.parameters + currentNodeParameters: undefined, + }); let executionData: IRun; const runExecutionData: IRunExecutionData = { diff --git a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts index 9a00879bb3..c1088f1403 100644 --- a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts +++ b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts @@ -131,6 +131,18 @@ BQIDAQAB }, }, }, + microsoftExcelOAuth2Api: { + scope: 'openid', + oauthTokenData: { + access_token: 'token', + }, + }, + microsoftTeamsOAuth2Api: { + scope: 'openid', + oauthTokenData: { + access_token: 'token', + }, + }, n8nApi: { apiKey: 'key123', baseUrl: 'https://test.app.n8n.cloud/api/v1', @@ -239,4 +251,7 @@ BQIDAQAB username: 'nathan@n8n.io', password: 'fake-password', }, + discordWebhookApi: { + webhookUri: 'https://discord.com/webhook', + }, } as const; diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 99fd2fcde3..6046616729 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -1,256 +1,50 @@ import { Container } from '@n8n/di'; import { readFileSync, readdirSync, mkdtempSync } from 'fs'; -import { mock } from 'jest-mock-extended'; import { get } from 'lodash'; import { isEmpty } from 'lodash'; -import { - BinaryDataService, - Credentials, - UnrecognizedNodeTypeError, - constructExecutionMetaData, - ExecutionLifecycleHooks, -} from 'n8n-core'; +import { BinaryDataService, constructExecutionMetaData } from 'n8n-core'; import type { - CredentialLoadingDetails, - ICredentialDataDecryptedObject, - ICredentialType, - ICredentialTypeData, - ICredentialTypes, IDataObject, - IDeferredPromise, IExecuteFunctions, IGetNodeParameterOptions, - IHttpRequestHelper, - IHttpRequestOptions, INode, - INodeCredentials, - INodeCredentialsDetails, - INodeType, - INodeTypeData, - INodeTypes, IRun, - IVersionedNodeType, IWorkflowBase, - IWorkflowExecuteAdditionalData, - NodeLoadingDetails, WorkflowTestData, } from 'n8n-workflow'; -import { ApplicationError, ICredentialsHelper, NodeHelpers } from 'n8n-workflow'; +import { ApplicationError } from 'n8n-workflow'; +import nock from 'nock'; import { tmpdir } from 'os'; import path from 'path'; import { executeWorkflow } from './ExecuteWorkflow'; -import { FAKE_CREDENTIALS_DATA } from './FakeCredentialsMap'; +import { LoadNodesAndCredentials } from './load-nodes-and-credentials'; const baseDir = path.resolve(__dirname, '../..'); -const getFakeDecryptedCredentials = ( - nodeCredentials: INodeCredentialsDetails, - type: string, - fakeCredentialsMap: IDataObject, -) => { - if (nodeCredentials && fakeCredentialsMap[JSON.stringify(nodeCredentials)]) { - return fakeCredentialsMap[JSON.stringify(nodeCredentials)] as ICredentialDataDecryptedObject; - } - - if (type && fakeCredentialsMap[type]) { - return fakeCredentialsMap[type] as ICredentialDataDecryptedObject; - } - - return {}; -}; - export const readJsonFileSync = (filePath: string) => JSON.parse(readFileSync(path.join(baseDir, filePath), 'utf-8')) as T; -const knownCredentials = readJsonFileSync>( - 'dist/known/credentials.json', -); +const loadNodesAndCredentials = new LoadNodesAndCredentials(baseDir); +Container.set(LoadNodesAndCredentials, loadNodesAndCredentials); -const knownNodes = readJsonFileSync>('dist/known/nodes.json'); - -class CredentialType implements ICredentialTypes { - credentialTypes: ICredentialTypeData = {}; - - addCredential(credentialTypeName: string, credentialType: ICredentialType) { - this.credentialTypes[credentialTypeName] = { - sourcePath: '', - type: credentialType, - }; - } - - recognizes(credentialType: string): boolean { - return credentialType in this.credentialTypes; - } - - getByName(credentialType: string): ICredentialType { - return this.credentialTypes[credentialType].type; - } - - getSupportedNodes(type: string): string[] { - return knownCredentials[type]?.supportedNodes ?? []; - } - - getParentTypes(_typeName: string): string[] { - return []; - } -} - -const credentialTypes = new CredentialType(); - -export class CredentialsHelper extends ICredentialsHelper { - getCredentialsProperties() { - return []; - } - - async authenticate( - credentials: ICredentialDataDecryptedObject, - typeName: string, - requestParams: IHttpRequestOptions, - ): Promise { - const credentialType = credentialTypes.getByName(typeName); - if (typeof credentialType.authenticate === 'function') { - return await credentialType.authenticate(credentials, requestParams); - } - return requestParams; - } - - async preAuthentication( - _helpers: IHttpRequestHelper, - _credentials: ICredentialDataDecryptedObject, - _typeName: string, - _node: INode, - _credentialsExpired: boolean, - ): Promise { - return undefined; - } - - getParentTypes(_name: string): string[] { - return []; - } - - async getDecrypted( - _additionalData: IWorkflowExecuteAdditionalData, - nodeCredentials: INodeCredentialsDetails, - type: string, - ): Promise { - return getFakeDecryptedCredentials(nodeCredentials, type, FAKE_CREDENTIALS_DATA); - } - - async getCredentials( - _nodeCredentials: INodeCredentialsDetails, - _type: string, - ): Promise { - return new Credentials({ id: null, name: '' }, '', ''); - } - - async updateCredentials( - _nodeCredentials: INodeCredentialsDetails, - _type: string, - _data: ICredentialDataDecryptedObject, - ): Promise {} -} - -export function WorkflowExecuteAdditionalData( - waitPromise: IDeferredPromise, - nodeExecutionOrder: string[], -): IWorkflowExecuteAdditionalData { - const hooks = new ExecutionLifecycleHooks('trigger', '1', mock()); - hooks.addHandler('nodeExecuteAfter', (nodeName) => { - nodeExecutionOrder.push(nodeName); - }); - hooks.addHandler('workflowExecuteAfter', (fullRunData) => waitPromise.resolve(fullRunData)); - - return mock({ - credentialsHelper: new CredentialsHelper(), - hooks, - // Get from node.parameters - currentNodeParameters: undefined, - }); -} - -class NodeTypes implements INodeTypes { - nodeTypes: INodeTypeData = {}; - - getByName(nodeType: string): INodeType | IVersionedNodeType { - return this.nodeTypes[nodeType].type; - } - - addNode(nodeTypeName: string, nodeType: INodeType | IVersionedNodeType) { - const loadedNode = { - [nodeTypeName]: { - sourcePath: '', - type: nodeType, - }, - }; - this.nodeTypes = { - ...this.nodeTypes, - ...loadedNode, - }; - } - - getByNameAndVersion(nodeType: string, version?: number): INodeType { - return NodeHelpers.getVersionedNodeType(this.nodeTypes[nodeType].type, version); - } - - getKnownTypes(): IDataObject { - throw new Error('Method not implemented.'); - } -} +beforeAll(async () => await loadNodesAndCredentials.init()); +beforeEach(() => nock.disableNetConnect()); export function createTemporaryDir(prefix = 'n8n') { return mkdtempSync(path.join(tmpdir(), prefix)); } -export async function initBinaryDataService(mode: 'default' | 'filesystem' = 'default') { +export async function initBinaryDataService() { const binaryDataService = new BinaryDataService(); await binaryDataService.init({ mode: 'default', - availableModes: [mode], + availableModes: ['default'], localStoragePath: createTemporaryDir(), }); Container.set(BinaryDataService, binaryDataService); } -export function setup(testData: WorkflowTestData[] | WorkflowTestData) { - if (!Array.isArray(testData)) { - testData = [testData]; - } - - const nodeTypes = new NodeTypes(); - - const nodes = [...new Set(testData.flatMap((data) => data.input.workflowData.nodes))]; - const credentialNames = nodes - .filter((n) => n.credentials) - .flatMap(({ credentials }) => Object.keys(credentials as INodeCredentials)); - for (const credentialName of credentialNames) { - const loadInfo = knownCredentials[credentialName]; - if (!loadInfo) { - throw new ApplicationError(`Unknown credential type: ${credentialName}`, { - level: 'warning', - }); - } - const sourcePath = loadInfo.sourcePath.replace(/^dist\//, './').replace(/\.js$/, '.ts'); - const nodeSourcePath = path.join(baseDir, sourcePath); - const credential = new (require(nodeSourcePath)[loadInfo.className])() as ICredentialType; - credentialTypes.addCredential(credentialName, credential); - } - - const nodeNames = nodes.map((n) => n.type); - for (const nodeName of nodeNames) { - const loadInfo = knownNodes[nodeName.replace('n8n-nodes-base.', '')]; - if (!loadInfo) { - throw new UnrecognizedNodeTypeError('n8n-nodes-base', nodeName); - } - const sourcePath = loadInfo.sourcePath.replace(/^dist\//, './').replace(/\.js$/, '.ts'); - const nodeSourcePath = path.join(baseDir, sourcePath); - const node = new (require(nodeSourcePath)[loadInfo.className])() as INodeType; - nodeTypes.addNode(nodeName, node); - } - - return nodeTypes; -} - export function getResultNodeData(result: IRun, testData: WorkflowTestData) { return Object.keys(testData.output.nodeData).map((nodeName) => { const error = result.data.resultData.error; @@ -287,9 +81,9 @@ export function getResultNodeData(result: IRun, testData: WorkflowTestData) { }); } -export const equalityTest = async (testData: WorkflowTestData, types: INodeTypes) => { +export const equalityTest = async (testData: WorkflowTestData) => { // execute workflow - const { result } = await executeWorkflow(testData, types); + const { result } = await executeWorkflow(testData); // check if result node data matches expected test data const resultNodeData = getResultNodeData(result, testData); @@ -330,6 +124,7 @@ const preparePinData = (pinData: IDataObject) => { ); return returnData; }; + export const workflowToTests = (workflowFiles: string[]) => { const testCases: WorkflowTestData[] = []; for (const filePath of workflowFiles) { @@ -365,10 +160,9 @@ export const workflowToTests = (workflowFiles: string[]) => { export const testWorkflows = (workflows: string[]) => { const tests = workflowToTests(workflows); - const nodeTypes = setup(tests); for (const testData of tests) { - test(testData.description, async () => await equalityTest(testData, nodeTypes)); + test(testData.description, async () => await equalityTest(testData)); } }; diff --git a/packages/nodes-base/test/nodes/credential-types.ts b/packages/nodes-base/test/nodes/credential-types.ts new file mode 100644 index 0000000000..146f4db47c --- /dev/null +++ b/packages/nodes-base/test/nodes/credential-types.ts @@ -0,0 +1,25 @@ +import { Service } from '@n8n/di'; +import type { ICredentialType, ICredentialTypes } from 'n8n-workflow'; + +import { LoadNodesAndCredentials } from './load-nodes-and-credentials'; + +@Service() +export class CredentialTypes implements ICredentialTypes { + constructor(private readonly loadNodesAndCredentials: LoadNodesAndCredentials) {} + + recognizes(type: string): boolean { + return this.loadNodesAndCredentials.recognizesCredential(type); + } + + getByName(type: string): ICredentialType { + return this.loadNodesAndCredentials.getCredential(type).type; + } + + getSupportedNodes(type: string): string[] { + return this.loadNodesAndCredentials.known.credentials[type]?.supportedNodes ?? []; + } + + getParentTypes(_type: string): string[] { + return []; + } +} diff --git a/packages/nodes-base/test/nodes/credentials-helper.ts b/packages/nodes-base/test/nodes/credentials-helper.ts new file mode 100644 index 0000000000..095c5010a3 --- /dev/null +++ b/packages/nodes-base/test/nodes/credentials-helper.ts @@ -0,0 +1,82 @@ +import { Container, Service } from '@n8n/di'; +import { Credentials } from 'n8n-core'; +import { ICredentialsHelper } from 'n8n-workflow'; +import type { + ICredentialDataDecryptedObject, + IDataObject, + IHttpRequestHelper, + IHttpRequestOptions, + INode, + INodeCredentialsDetails, + IWorkflowExecuteAdditionalData, +} from 'n8n-workflow'; + +import { CredentialTypes } from './credential-types'; +import { FAKE_CREDENTIALS_DATA } from './FakeCredentialsMap'; + +@Service() +export class CredentialsHelper extends ICredentialsHelper { + getCredentialsProperties() { + return []; + } + + async authenticate( + credentials: ICredentialDataDecryptedObject, + typeName: string, + requestParams: IHttpRequestOptions, + ): Promise { + const credentialType = Container.get(CredentialTypes).getByName(typeName); + if (typeof credentialType.authenticate === 'function') { + return await credentialType.authenticate(credentials, requestParams); + } + return requestParams; + } + + async preAuthentication( + _helpers: IHttpRequestHelper, + _credentials: ICredentialDataDecryptedObject, + _typeName: string, + _node: INode, + _credentialsExpired: boolean, + ): Promise { + return undefined; + } + + getParentTypes(_name: string): string[] { + return []; + } + + async getDecrypted( + _additionalData: IWorkflowExecuteAdditionalData, + nodeCredentials: INodeCredentialsDetails, + type: string, + ): Promise { + return this.getFakeDecryptedCredentials(nodeCredentials, type); + } + + async getCredentials( + _nodeCredentials: INodeCredentialsDetails, + _type: string, + ): Promise { + return new Credentials({ id: null, name: '' }, '', ''); + } + + async updateCredentials( + _nodeCredentials: INodeCredentialsDetails, + _type: string, + _data: ICredentialDataDecryptedObject, + ): Promise {} + + private getFakeDecryptedCredentials(nodeCredentials: INodeCredentialsDetails, type: string) { + const credentialsMap = FAKE_CREDENTIALS_DATA as IDataObject; + if (nodeCredentials && credentialsMap[JSON.stringify(nodeCredentials)]) { + return credentialsMap[JSON.stringify(nodeCredentials)] as ICredentialDataDecryptedObject; + } + + if (type && credentialsMap[type]) { + return credentialsMap[type] as ICredentialDataDecryptedObject; + } + + return {}; + } +} diff --git a/packages/nodes-base/test/nodes/load-nodes-and-credentials.ts b/packages/nodes-base/test/nodes/load-nodes-and-credentials.ts new file mode 100644 index 0000000000..387669e5d9 --- /dev/null +++ b/packages/nodes-base/test/nodes/load-nodes-and-credentials.ts @@ -0,0 +1,39 @@ +import { Service } from '@n8n/di'; +import { LazyPackageDirectoryLoader } from 'n8n-core'; +import type { + ICredentialType, + INodeType, + IVersionedNodeType, + KnownNodesAndCredentials, + LoadedClass, +} from 'n8n-workflow'; + +@Service() +export class LoadNodesAndCredentials { + private loader: LazyPackageDirectoryLoader; + + readonly known: KnownNodesAndCredentials = { nodes: {}, credentials: {} }; + + constructor(baseDir: string) { + this.loader = new LazyPackageDirectoryLoader(baseDir); + } + + async init() { + await this.loader.loadAll(); + this.known.credentials = this.loader.known.credentials; + this.known.nodes = this.loader.known.nodes; + } + + recognizesCredential(credentialType: string): boolean { + return credentialType in this.known.credentials; + } + + getCredential(credentialType: string): LoadedClass { + return this.loader.getCredential(credentialType); + } + + getNode(fullNodeType: string): LoadedClass { + const nodeType = fullNodeType.split('.')[1]; + return this.loader.getNode(nodeType); + } +} diff --git a/packages/nodes-base/test/nodes/node-types.ts b/packages/nodes-base/test/nodes/node-types.ts new file mode 100644 index 0000000000..49c9e3a74c --- /dev/null +++ b/packages/nodes-base/test/nodes/node-types.ts @@ -0,0 +1,23 @@ +import { Service } from '@n8n/di'; +import { NodeHelpers } from 'n8n-workflow'; +import type { INodeType, INodeTypes, IVersionedNodeType } from 'n8n-workflow'; + +import { LoadNodesAndCredentials } from './load-nodes-and-credentials'; + +@Service() +export class NodeTypes implements INodeTypes { + constructor(private readonly loadNodesAndCredentials: LoadNodesAndCredentials) {} + + getByName(type: string): INodeType | IVersionedNodeType { + return this.loadNodesAndCredentials.getNode(type).type; + } + + getByNameAndVersion(type: string, version?: number): INodeType { + const node = this.loadNodesAndCredentials.getNode(type); + return NodeHelpers.getVersionedNodeType(node.type, version); + } + + getKnownTypes() { + return this.loadNodesAndCredentials.known.nodes; + } +} diff --git a/packages/nodes-base/test/nodes/types.ts b/packages/nodes-base/test/nodes/types.ts deleted file mode 100644 index 73e09fcb24..0000000000 --- a/packages/nodes-base/test/nodes/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { WorkflowTestData } from 'n8n-workflow'; -//TODO: remove, update import in tests -export { WorkflowTestData }; diff --git a/packages/nodes-base/tsconfig.json b/packages/nodes-base/tsconfig.json index 3ed7ddd987..a300196ce4 100644 --- a/packages/nodes-base/tsconfig.json +++ b/packages/nodes-base/tsconfig.json @@ -9,6 +9,8 @@ "@utils/*": ["./utils/*"] }, "tsBuildInfoFile": "dist/typecheck.tsbuildinfo", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, // TODO: remove all options below this line "noImplicitReturns": false, "useUnknownInCatchVariables": false diff --git a/packages/nodes-base/test/utils/utilities.test.ts b/packages/nodes-base/utils/__tests__/utilities.test.ts similarity index 100% rename from packages/nodes-base/test/utils/utilities.test.ts rename to packages/nodes-base/utils/__tests__/utilities.test.ts diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 4244feb6ca..cb85460d03 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -2090,6 +2090,11 @@ export type KnownNodesAndCredentials = { credentials: Record; }; +export interface LoadedNodesAndCredentials { + nodes: INodeTypeData; + credentials: ICredentialTypeData; +} + export interface LoadedClass { sourcePath: string; type: T;