diff --git a/packages/nodes-base/nodes/Aws/Comprehend/test/AwsComprehend.node.test.ts b/packages/nodes-base/nodes/Aws/Comprehend/test/AwsComprehend.node.test.ts index 4be8285434..e13bd8233f 100644 --- a/packages/nodes-base/nodes/Aws/Comprehend/test/AwsComprehend.node.test.ts +++ b/packages/nodes-base/nodes/Aws/Comprehend/test/AwsComprehend.node.test.ts @@ -1,6 +1,8 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + +import { credentials } from '../../__tests__/credentials'; const workflows = getWorkflowFilenames(__dirname); @@ -20,11 +22,10 @@ describe('Test AWS Comprehend Node', () => { }, ], }; + beforeAll(async () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); - await initBinaryDataService(); - const baseUrl = 'https://comprehend.eu-central-1.amazonaws.com'; mock = nock(baseUrl); @@ -34,6 +35,6 @@ describe('Test AWS Comprehend Node', () => { mock.post('/').reply(200, response); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); diff --git a/packages/nodes-base/nodes/Aws/Rekognition/test/AwsRekognition.node.test.ts b/packages/nodes-base/nodes/Aws/Rekognition/test/AwsRekognition.node.test.ts index f57696c690..9d3d57411b 100644 --- a/packages/nodes-base/nodes/Aws/Rekognition/test/AwsRekognition.node.test.ts +++ b/packages/nodes-base/nodes/Aws/Rekognition/test/AwsRekognition.node.test.ts @@ -2,6 +2,8 @@ import nock from 'nock'; import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../__tests__/credentials'; + const responseLabels = [ { LabelModelVersion: '3.0', @@ -298,6 +300,6 @@ describe('Test AWS Rekogntion Node', () => { mock.post('/').reply(200, responseLabels); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); diff --git a/packages/nodes-base/nodes/Aws/S3/test/V1/AwsS3.node.test.ts b/packages/nodes-base/nodes/Aws/S3/test/V1/AwsS3.node.test.ts index 145ca84516..ffa3c2840d 100644 --- a/packages/nodes-base/nodes/Aws/S3/test/V1/AwsS3.node.test.ts +++ b/packages/nodes-base/nodes/Aws/S3/test/V1/AwsS3.node.test.ts @@ -1,6 +1,8 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + +import { credentials } from '../../../__tests__/credentials'; const workflows = getWorkflowFilenames(__dirname); @@ -12,8 +14,6 @@ describe('Test S3 V1 Node', () => { beforeAll(async () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); - await initBinaryDataService(); - mock = nock('https://bucket.s3.eu-central-1.amazonaws.com'); }); @@ -39,6 +39,6 @@ describe('Test S3 V1 Node', () => { .reply(200, { success: true }); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); diff --git a/packages/nodes-base/nodes/Aws/S3/test/V2/AwsS3.node.test.ts b/packages/nodes-base/nodes/Aws/S3/test/V2/AwsS3.node.test.ts index ff8aded605..cea98a1f0e 100644 --- a/packages/nodes-base/nodes/Aws/S3/test/V2/AwsS3.node.test.ts +++ b/packages/nodes-base/nodes/Aws/S3/test/V2/AwsS3.node.test.ts @@ -1,6 +1,8 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + +import { credentials } from '../../../__tests__/credentials'; const workflows = getWorkflowFilenames(__dirname); @@ -12,8 +14,6 @@ describe('Test S3 V2 Node', () => { beforeAll(async () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); - await initBinaryDataService(); - mock = nock('https://s3.eu-central-1.amazonaws.com/buc.ket'); }); @@ -39,6 +39,6 @@ describe('Test S3 V2 Node', () => { .reply(200, { success: true }); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); 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 a28fc97528..7d626ed4b6 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 @@ -5,6 +5,8 @@ import qs from 'node:querystring'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; +import { credentials } from '../../__tests__/credentials'; + describe('AwsSes Node', () => { const email = 'test+user@example.com'; const templateData = { @@ -170,6 +172,7 @@ describe('AwsSes Node', () => { ]; test.each(tests)('$description', async (testData) => { + testData.credentials = credentials; const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => diff --git a/packages/nodes-base/nodes/Aws/__tests__/credentials.ts b/packages/nodes-base/nodes/Aws/__tests__/credentials.ts new file mode 100644 index 0000000000..c86b3c2a55 --- /dev/null +++ b/packages/nodes-base/nodes/Aws/__tests__/credentials.ts @@ -0,0 +1,7 @@ +export const credentials = { + aws: { + region: 'eu-central-1', + accessKeyId: 'key', + secretAccessKey: 'secret', + }, +}; 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 2cf847ad01..35583711a5 100644 --- a/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts +++ b/packages/nodes-base/nodes/Baserow/__tests__/workflow/workflow.test.ts @@ -11,6 +11,14 @@ import { } from './apiResponses'; describe('Baserow > Workflows', () => { + const credentials = { + baserowApi: { + host: 'https://api.baserow.io', + username: 'nathan@n8n.io', + password: 'fake-password', + }, + }; + describe('Run workflow', () => { beforeAll(() => { const mock = nock('https://api.baserow.io'); @@ -48,6 +56,6 @@ describe('Baserow > Workflows', () => { }); const workflows = getWorkflowFilenames(__dirname); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); diff --git a/packages/nodes-base/nodes/Code/test/Code.node.test.ts b/packages/nodes-base/nodes/Code/test/Code.node.test.ts index 595e4d177e..2953098c03 100644 --- a/packages/nodes-base/nodes/Code/test/Code.node.test.ts +++ b/packages/nodes-base/nodes/Code/test/Code.node.test.ts @@ -4,7 +4,7 @@ import { normalizeItems } from 'n8n-core'; import type { IExecuteFunctions, IWorkflowDataProxyData } from 'n8n-workflow'; import { ApplicationError } from 'n8n-workflow'; -import { testWorkflows, getWorkflowFilenames, initBinaryDataService } from '@test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; import { Code } from '../Code.node'; import { ValidationError } from '../ValidationError'; @@ -12,10 +12,6 @@ import { ValidationError } from '../ValidationError'; describe('Test Code Node', () => { const workflows = getWorkflowFilenames(__dirname); - beforeAll(async () => { - await initBinaryDataService(); - }); - 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 3c66af9ffb..314662b2a1 100644 --- a/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts +++ b/packages/nodes-base/nodes/Compression/test/node/Compression.test.ts @@ -4,14 +4,10 @@ import os from 'node:os'; import path from 'path'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, initBinaryDataService, readJsonFileSync } from '@test/nodes/Helpers'; +import { getResultNodeData, readJsonFileSync } from '@test/nodes/Helpers'; if (os.platform() !== 'win32') { describe('Execute Compression Node', () => { - beforeEach(async () => { - await initBinaryDataService(); - }); - const workflowData = readJsonFileSync('nodes/Compression/test/node/workflow.compression.json'); const node = workflowData.nodes.find((n: IDataObject) => n.name === 'Read Binary File'); diff --git a/packages/nodes-base/nodes/Crypto/test/Crypto.test.ts b/packages/nodes-base/nodes/Crypto/test/Crypto.test.ts index d473b0551f..c47efaf073 100644 --- a/packages/nodes-base/nodes/Crypto/test/Crypto.test.ts +++ b/packages/nodes-base/nodes/Crypto/test/Crypto.test.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import fsPromises from 'fs/promises'; import { Readable } from 'stream'; -import { testWorkflows, getWorkflowFilenames, initBinaryDataService } from '@test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; const workflows = getWorkflowFilenames(__dirname); @@ -13,9 +13,5 @@ describe('Test Crypto Node', () => { jest.mock('fs'); fs.createReadStream = () => Readable.from(Buffer.from('test')) as fs.ReadStream; - beforeEach(async () => { - await initBinaryDataService(); - }); - 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 58b59c3972..c5a158f2b8 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 @@ -3,8 +3,14 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; describe('Test DiscordV2, webhook => sendLegacy', () => { - nock('https://discord.com') - .post('/webhook?wait=true') + const credentials = { + discordWebhookApi: { + webhookUri: 'https://discord.com/webhook', + }, + }; + + nock(credentials.discordWebhookApi.webhookUri) + .post('?wait=true') .reply(200, { id: '1168768986385747999', type: 0, @@ -45,5 +51,5 @@ describe('Test DiscordV2, webhook => sendLegacy', () => { }); const workflows = ['nodes/Discord/test/v2/node/webhook/sendLegacy.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/EmailReadImap/test/v2/EmailReadImapV2.node.test.ts b/packages/nodes-base/nodes/EmailReadImap/test/v2/EmailReadImapV2.node.test.ts index a2803f3113..0236022f3b 100644 --- a/packages/nodes-base/nodes/EmailReadImap/test/v2/EmailReadImapV2.node.test.ts +++ b/packages/nodes-base/nodes/EmailReadImap/test/v2/EmailReadImapV2.node.test.ts @@ -2,7 +2,8 @@ import { mock } from 'jest-mock-extended'; import { type INodeTypeBaseDescription, type ITriggerFunctions } from 'n8n-workflow'; -import { type ICredentialsDataImap } from '../../../../credentials/Imap.credentials'; +import { type ICredentialsDataImap } from '@credentials/Imap.credentials'; + import { EmailReadImapV2 } from '../../v2/EmailReadImapV2.node'; jest.mock('@n8n/imap', () => { diff --git a/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts b/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts index a453619c92..e5b46c584f 100644 --- a/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts +++ b/packages/nodes-base/nodes/EmailReadImap/v2/EmailReadImapV2.node.ts @@ -17,9 +17,10 @@ import type { import { NodeConnectionTypes, NodeOperationError, TriggerCloseError } from 'n8n-workflow'; import rfc2047 from 'rfc2047'; +import type { ICredentialsDataImap } from '@credentials/Imap.credentials'; +import { isCredentialsDataImap } from '@credentials/Imap.credentials'; + import { getNewEmails } from './utils'; -import type { ICredentialsDataImap } from '../../../credentials/Imap.credentials'; -import { isCredentialsDataImap } from '../../../credentials/Imap.credentials'; const versionDescription: INodeTypeDescription = { displayName: 'Email Trigger (IMAP)', 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 4879a62ddf..a86838fad0 100644 --- a/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts +++ b/packages/nodes-base/nodes/Files/ReadWriteFile/test/ReadWriteFile.test.ts @@ -5,10 +5,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Test ReadWriteFile Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const temporaryDir = Helpers.createTemporaryDir(); const directory = __dirname.replace(/\\/gi, '/'); diff --git a/packages/nodes-base/nodes/Github/__tests__/node/Github.dispatchAndWait.node.test.ts b/packages/nodes-base/nodes/Github/__tests__/node/Github.dispatchAndWait.node.test.ts index 5db2a3336a..33eaa20d27 100644 --- a/packages/nodes-base/nodes/Github/__tests__/node/Github.dispatchAndWait.node.test.ts +++ b/packages/nodes-base/nodes/Github/__tests__/node/Github.dispatchAndWait.node.test.ts @@ -1,6 +1,6 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('GithubDispatchAndWaitWorkflow.json'), @@ -56,7 +56,6 @@ describe('Test Github Node - Dispatch and Wait', () => { beforeAll(async () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); - await initBinaryDataService(); }); beforeEach(async () => { diff --git a/packages/nodes-base/nodes/Github/__tests__/node/Github.node.test.ts b/packages/nodes-base/nodes/Github/__tests__/node/Github.node.test.ts index bbb5471495..a87694155a 100644 --- a/packages/nodes-base/nodes/Github/__tests__/node/Github.node.test.ts +++ b/packages/nodes-base/nodes/Github/__tests__/node/Github.node.test.ts @@ -1,7 +1,7 @@ import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { Github } from '../../Github.node'; @@ -65,7 +65,6 @@ describe('Test Github Node', () => { beforeAll(async () => { jest.useFakeTimers({ doNotFake: ['nextTick'], now }); - await initBinaryDataService(); }); beforeEach(async () => { 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 9251a002c8..4c1724c869 100644 --- a/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts +++ b/packages/nodes-base/nodes/Gong/test/Gong.node.test.ts @@ -1,12 +1,6 @@ -import type { - ICredentialDataDecryptedObject, - IDataObject, - IHttpRequestOptions, - WorkflowTestData, -} from 'n8n-workflow'; +import type { WorkflowTestData } from 'n8n-workflow'; import { NodeConnectionTypes } from 'n8n-workflow'; -import { CredentialsHelper } from '@test/nodes/credentials-helper'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; @@ -14,6 +8,10 @@ import { gongApiResponse, gongNodeResponse } from './mocks'; describe('Gong Node', () => { const baseUrl = 'https://api.gong.io'; + const credentials = { + gongApi: { baseUrl }, + gongOAuth2Api: { baseUrl }, + }; describe('Credentials', () => { const tests: WorkflowTestData[] = [ @@ -143,42 +141,8 @@ describe('Gong Node', () => { }, ]; - beforeAll(() => { - jest - .spyOn(CredentialsHelper.prototype, 'authenticate') - .mockImplementation( - async ( - credentials: ICredentialDataDecryptedObject, - typeName: string, - requestParams: IHttpRequestOptions, - ): Promise => { - if (typeName === 'gongApi') { - return { - ...requestParams, - headers: { - authorization: - 'basic ' + - Buffer.from(`${credentials.accessKey}:${credentials.accessKeySecret}`).toString( - 'base64', - ), - }, - }; - } else if (typeName === 'gongOAuth2Api') { - return { - ...requestParams, - headers: { - authorization: - 'bearer ' + (credentials.oauthTokenData as IDataObject).access_token, - }, - }; - } else { - return requestParams; - } - }, - ); - }); - test.each(tests)('$description', async (testData) => { + testData.credentials = credentials; const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => @@ -773,6 +737,7 @@ describe('Gong Node', () => { ]; test.each(tests)('$description', async (testData) => { + testData.credentials = credentials; const { result } = await executeWorkflow(testData); if (testData.description === 'should handle error response') { @@ -1042,6 +1007,7 @@ describe('Gong Node', () => { ]; test.each(tests)('$description', async (testData) => { + testData.credentials = credentials; const { result } = await executeWorkflow(testData); if (testData.description === 'should handle error response') { 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 7a545400e4..d134067539 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 @@ -69,11 +69,9 @@ describe('Test Gmail Node v1', () => { .reply(200, messages[0]); }); - testWorkflows(['nodes/Google/Gmail/test/v1/messages.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v1/messages.workflow.json']); }); describe('Labels', () => { @@ -94,11 +92,9 @@ describe('Test Gmail Node v1', () => { }); }); - testWorkflows(['nodes/Google/Gmail/test/v1/labels.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v1/labels.workflow.json']); }); describe('Message Labels', () => { @@ -113,11 +109,9 @@ describe('Test Gmail Node v1', () => { .reply(200, messages[0]); }); - testWorkflows(['nodes/Google/Gmail/test/v1/message-labels.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v1/message-labels.workflow.json']); }); describe('Drafts', () => { @@ -193,10 +187,8 @@ describe('Test Gmail Node v1', () => { }); }); - testWorkflows(['nodes/Google/Gmail/test/v1/drafts.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v1/drafts.workflow.json']); }); }); 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 1b8e384cc4..8cdf033db5 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 @@ -129,11 +129,9 @@ describe('Test Gmail Node v2', () => { .reply(200, messages[0]); }); - testWorkflows(['nodes/Google/Gmail/test/v2/messages.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v2/messages.workflow.json']); }); describe('Labels', () => { @@ -154,11 +152,9 @@ describe('Test Gmail Node v2', () => { }); }); - testWorkflows(['nodes/Google/Gmail/test/v2/labels.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v2/labels.workflow.json']); }); describe('Drafts', () => { @@ -244,11 +240,9 @@ describe('Test Gmail Node v2', () => { }); }); - testWorkflows(['nodes/Google/Gmail/test/v2/drafts.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v2/drafts.workflow.json']); }); describe('Threads', () => { @@ -307,11 +301,9 @@ describe('Test Gmail Node v2', () => { .reply(200, messages[0]); }); - testWorkflows(['nodes/Google/Gmail/test/v2/threads.workflow.json']); + afterAll(() => gmailNock.done()); - it('should make the correct network calls', () => { - gmailNock.done(); - }); + testWorkflows(['nodes/Google/Gmail/test/v2/threads.workflow.json']); }); describe('loadOptions', () => { diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts b/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts index 705820ac94..428792b856 100644 --- a/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts @@ -8,6 +8,15 @@ import playlistItems from './fixtures/playlistItems.json'; import playlists from './fixtures/playlists.json'; describe('Test YouTube Node', () => { + const credentials = { + youTubeOAuth2Api: { + scope: '', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + }, + }, + }; + const youtubeNock = nock('https://www.googleapis.com/youtube'); beforeAll(() => { jest @@ -51,16 +60,11 @@ describe('Test YouTube Node', () => { image: {}, }, }); - nock.emitter.on('no match', (req) => { - console.error('Unmatched request:', req); - }); }); - testWorkflows(['nodes/Google/YouTube/__test__/node/channels.workflow.json']); + afterAll(() => youtubeNock.done()); - it('should make the correct network calls', () => { - youtubeNock.done(); - }); + testWorkflows(['nodes/Google/YouTube/__test__/node/channels.workflow.json'], credentials); }); describe('Playlist', () => { @@ -107,16 +111,11 @@ describe('Test YouTube Node', () => { }) .reply(200, { items: playlists }); youtubeNock.delete('/v3/playlists', { id: 'playlist_id_1' }).reply(200, { success: true }); - nock.emitter.on('no match', (req) => { - console.error('Unmatched request:', req); - }); }); - testWorkflows(['nodes/Google/YouTube/__test__/node/playlists.workflow.json']); + afterAll(() => youtubeNock.done()); - it('should make the correct network calls', () => { - youtubeNock.done(); - }); + testWorkflows(['nodes/Google/YouTube/__test__/node/playlists.workflow.json'], credentials); }); describe('Video Categories', () => { @@ -128,17 +127,16 @@ describe('Test YouTube Node', () => { regionCode: 'GB', }) .reply(200, { items: categories }); - nock.emitter.on('no match', (req) => { - console.error('Unmatched request:', req); - }); }); - testWorkflows(['nodes/Google/YouTube/__test__/node/videoCategories.workflow.json']); + afterAll(() => youtubeNock.done()); - it('should make the correct network calls', () => { - youtubeNock.done(); - }); + testWorkflows( + ['nodes/Google/YouTube/__test__/node/videoCategories.workflow.json'], + credentials, + ); }); + describe('Playlist Item', () => { beforeAll(() => { youtubeNock @@ -171,15 +169,10 @@ describe('Test YouTube Node', () => { return body.id === 'UExWUDRtV2RxbGFhNWlwZEJRWXZVaFgyNk9RTENJRlV2cS41NkI0NEY2RDEwNTU3Q0M2'; }) .reply(200, {}); - nock.emitter.on('no match', (req) => { - console.error('Unmatched request:', req); - }); }); - testWorkflows(['nodes/Google/YouTube/__test__/node/playlistItems.workflow.json']); + afterAll(() => youtubeNock.done()); - // it('should make the correct network calls', () => { - // youtubeNock.done(); - // }); + testWorkflows(['nodes/Google/YouTube/__test__/node/playlistItems.workflow.json'], credentials); }); }); 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 8ed847d91d..1b097f64ae 100644 --- a/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts +++ b/packages/nodes-base/nodes/GraphQL/test/GraphQL.node.test.ts @@ -1,14 +1,12 @@ /* eslint-disable n8n-nodes-base/node-filename-against-convention */ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('GraphQL Node', () => { const baseUrl = 'https://api.n8n.io/'; beforeAll(async () => { - await initBinaryDataService(); - nock(baseUrl) .matchHeader('accept', 'application/json') .matchHeader('content-type', 'application/json') 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 6017c85fac..5059df6537 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/binaryData/HttpRequest.test.ts @@ -1,13 +1,11 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test Binary Data Download', () => { const baseUrl = 'https://dummy.domain'; beforeAll(async () => { - await initBinaryDataService(); - nock(baseUrl) .persist() .get('/path/to/image.png') 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 5b5a19fb64..0617f9913a 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts @@ -1,6 +1,6 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test Response Encoding', () => { const baseUrl = 'https://dummy.domain'; @@ -10,8 +10,6 @@ describe('Test Response Encoding', () => { ); beforeAll(async () => { - await initBinaryDataService(); - nock(baseUrl) .persist() .get('/index.html') 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 e3cb2563f7..a6f7975788 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/encodingQuoted/HttpRequest.test.ts @@ -1,6 +1,6 @@ import nock from 'nock'; -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test Quoted Response Encoding', () => { const baseUrl = 'https://dummy.domain'; @@ -10,8 +10,6 @@ describe('Test Quoted Response Encoding', () => { ); beforeAll(async () => { - await initBinaryDataService(); - nock(baseUrl) .persist() .get('/index.html') 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 cf429c7a3a..aa05ae3fa0 100644 --- a/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts +++ b/packages/nodes-base/nodes/HttpRequest/test/node/HttpRequest.test.ts @@ -1,14 +1,12 @@ import nock from 'nock'; import { parse as parseUrl } from 'url'; -import { initBinaryDataService, getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test HTTP Request Node', () => { const baseUrl = 'https://dummyjson.com'; beforeAll(async () => { - await initBinaryDataService(); - function getPaginationReturnData(this: nock.ReplyFnContext, limit = 10, skip = 0) { const nextUrl = `${baseUrl}/users?skip=${skip + limit}&limit=${limit}`; diff --git a/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts b/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts index 39b2dcf791..492f3aaa23 100644 --- a/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts +++ b/packages/nodes-base/nodes/Hubspot/__test__/Hubspot.node.test.ts @@ -112,11 +112,9 @@ describe('Hubspot Node', () => { .reply(200, companies.companies[0]); }); - testWorkflows(['nodes/Hubspot/__test__/companies.workflow.json']); + afterAll(() => hubspotNock.done()); - it('should make the correct network calls', () => { - hubspotNock.done(); - }); + testWorkflows(['nodes/Hubspot/__test__/companies.workflow.json']); }); describe('contacts', () => { @@ -210,11 +208,9 @@ describe('Hubspot Node', () => { .reply(200, contacts.contacts[0]); }); - testWorkflows(['nodes/Hubspot/__test__/contacts.workflow.json']); + afterAll(() => hubspotNock.done()); - it('should make the correct network calls', () => { - hubspotNock.done(); - }); + testWorkflows(['nodes/Hubspot/__test__/contacts.workflow.json']); }); describe('deals', () => { @@ -257,10 +253,8 @@ describe('Hubspot Node', () => { .reply(200, dealsSearchResult); }); - testWorkflows(['nodes/Hubspot/__test__/deals.workflow.json']); + afterAll(() => hubspotNock.done()); - it('should make the correct network calls', () => { - hubspotNock.done(); - }); + testWorkflows(['nodes/Hubspot/__test__/deals.workflow.json']); }); }); 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 851c0abf08..37b752a510 100644 --- a/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts +++ b/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts @@ -2,12 +2,9 @@ import type { WorkflowTestData } from 'n8n-workflow'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; -import { getResultNodeData, readJsonFileSync, initBinaryDataService } from '@test/nodes/Helpers'; +import { getResultNodeData, readJsonFileSync } from '@test/nodes/Helpers'; -describe('Execute iCalendar Node', () => { - beforeEach(async () => { - await initBinaryDataService(); - }); +describe('iCalendar Node', () => { const workflowData = readJsonFileSync('nodes/ICalendar/test/node/workflow.iCalendar.json'); const tests: WorkflowTestData[] = [ diff --git a/packages/nodes-base/nodes/Jwt/test/Jwt.node.test.ts b/packages/nodes-base/nodes/Jwt/test/Jwt.node.test.ts index 5757cd2a2b..6e062c1a2c 100644 --- a/packages/nodes-base/nodes/Jwt/test/Jwt.node.test.ts +++ b/packages/nodes-base/nodes/Jwt/test/Jwt.node.test.ts @@ -1,4 +1,13 @@ import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +const credentials = { + jwtAuth: { + keyType: 'passphrase', + secret: 'baz', + algorithm: 'HS256', + }, +}; + const workflows = getWorkflowFilenames(__dirname); -describe('Test Jwt Node', () => testWorkflows(workflows)); +describe('Test Jwt Node', () => testWorkflows(workflows, credentials)); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/create.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/create.test.ts index 5ada46bda6..37765758a2 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/create.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - getWorkflowFilenames, - initBinaryDataService, - testWorkflows, -} from '../../../../../test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Create Container', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('create.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -86,9 +75,5 @@ describe('Azure Cosmos DB - Create Container', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/delete.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/delete.test.ts index ff3d1c426f..daaa6faadb 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/delete.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/delete.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Delete Container', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('delete.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -30,9 +19,5 @@ describe('Azure Cosmos DB - Delete Container', () => { .reply(204, {}); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/get.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/get.test.ts index 25427f1c21..fb74c3ef9d 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/get.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Get Container', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('get.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -68,9 +57,5 @@ describe('Azure Cosmos DB - Get Container', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/getAll.test.ts index d1fd84fcbf..4218e31f48 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/container/getAll.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Get All Containers', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('getAll.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -170,9 +159,5 @@ describe('Azure Cosmos DB - Get All Containers', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials.ts new file mode 100644 index 0000000000..1670e03d27 --- /dev/null +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials.ts @@ -0,0 +1,8 @@ +export const credentials = { + microsoftAzureCosmosDbSharedKeyApi: { + account: 'n8n-us-east-account', + key: 'I3rwpzP0XoFpNzJ7hRIUXjwgpD1qaVKi71NZBbk7oOHUXrbd80WAoIAAoRaT47W9hHO3b6us1yABACDbVdilag==', + database: 'database_1', + baseUrl: 'https://n8n-us-east-account.documents.azure.com/dbs/database_1', + }, +}; diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials/sharedKey.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials/sharedKey.test.ts index 177d283940..5c0e28ed45 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials/sharedKey.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/credentials/sharedKey.test.ts @@ -1,12 +1,9 @@ import { OperationalError } from 'n8n-workflow'; -import type { - ICredentialDataDecryptedObject, - IHttpRequestOptions, - IRequestOptions, -} from 'n8n-workflow'; +import type { IHttpRequestOptions, IRequestOptions } from 'n8n-workflow'; -import { MicrosoftAzureCosmosDbSharedKeyApi } from '../../../../../credentials/MicrosoftAzureCosmosDbSharedKeyApi.credentials'; -import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap'; +import { MicrosoftAzureCosmosDbSharedKeyApi } from '@credentials/MicrosoftAzureCosmosDbSharedKeyApi.credentials'; + +import { credentials } from '../credentials'; jest.mock('crypto', () => ({ createHmac: jest.fn(() => ({ @@ -17,20 +14,18 @@ jest.mock('crypto', () => ({ })); describe('Azure Cosmos DB', () => { + const { account, key, baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; + describe('authenticate', () => { const azureCosmosDbSharedKeyApi = new MicrosoftAzureCosmosDbSharedKeyApi(); it('should generate a valid authorization header', async () => { jest.useFakeTimers().setSystemTime(new Date('2025-01-01T00:00:00Z')); - const credentials: ICredentialDataDecryptedObject = { - account: FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi.account, - key: FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi.key, - }; const requestOptions: IHttpRequestOptions = { - url: `${FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi.baseUrl}/colls/container1/docs/item1`, + url: `${baseUrl}/colls/container1/docs/item1`, method: 'GET', }; - const result = await azureCosmosDbSharedKeyApi.authenticate(credentials, requestOptions); + const result = await azureCosmosDbSharedKeyApi.authenticate({ account, key }, requestOptions); expect(result.headers?.authorization).toBe( 'type%3Dmaster%26ver%3D1.0%26sig%3Dfake-signature', @@ -114,15 +109,11 @@ describe('Azure Cosmos DB', () => { it('should properly construct the resourceId and payload', async () => { jest.useFakeTimers().setSystemTime(new Date('2025-01-01T00:00:00Z')); - const credentials: ICredentialDataDecryptedObject = { - account: FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi.account, - key: FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi.key, - }; const requestOptions: IHttpRequestOptions = { url: 'https://example.com/dbs/mydb/colls/mycoll/docs/mydoc', method: 'GET', }; - const result = await azureCosmosDbSharedKeyApi.authenticate(credentials, requestOptions); + const result = await azureCosmosDbSharedKeyApi.authenticate({ account, key }, requestOptions); expect(result.headers?.authorization).toBe( 'type%3Dmaster%26ver%3D1.0%26sig%3Dfake-signature', diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/helpers/utils.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/helpers/utils.test.ts index 1f6e3c2fb4..8c92f9431a 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/helpers/utils.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/helpers/utils.test.ts @@ -1,6 +1,16 @@ -import type { IDataObject, IHttpRequestOptions, INodeExecutionData } from 'n8n-workflow'; +import { mock } from 'jest-mock-extended'; +import type { + IDataObject, + IExecuteSingleFunctions, + IHttpRequestOptions, + INode, + INodeExecutionData, +} from 'n8n-workflow'; import { NodeApiError, NodeOperationError, OperationalError } from 'n8n-workflow'; +const azureCosmosDbApiRequest = jest.fn(); +jest.mock('../../transport', () => ({ azureCosmosDbApiRequest })); + import { ErrorMap } from '../../helpers/errorHandler'; import { getPartitionKey, @@ -10,31 +20,19 @@ import { validatePartitionKey, validateCustomProperties, } from '../../helpers/utils'; -import { azureCosmosDbApiRequest } from '../../transport'; interface RequestBodyWithParameters extends IDataObject { parameters: Array<{ name: string; value: string }>; } -jest.mock('n8n-workflow', () => ({ - ...jest.requireActual('n8n-workflow'), - azureCosmosDbApiRequest: jest.fn(), -})); +const mockExecuteSingleFunctions = mock(); +beforeEach(() => { + jest.resetAllMocks(); -jest.mock('../../transport', () => ({ - azureCosmosDbApiRequest: jest.fn(), -})); + mockExecuteSingleFunctions.getNode.mockReturnValue({ name: 'MockNode' } as INode); +}); describe('getPartitionKey', () => { - let mockExecuteSingleFunctions: any; - - beforeEach(() => { - mockExecuteSingleFunctions = { - getNodeParameter: jest.fn(), - getNode: jest.fn(() => ({ name: 'MockNode' })), - }; - }); - test('should return partition key when found', async () => { mockExecuteSingleFunctions.getNodeParameter.mockReturnValue('containerName'); const mockApiResponse = { @@ -42,7 +40,7 @@ describe('getPartitionKey', () => { paths: ['/partitionKeyPath'], }, }; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); const result = await getPartitionKey.call(mockExecuteSingleFunctions); @@ -52,7 +50,7 @@ describe('getPartitionKey', () => { test('should throw NodeOperationError if partition key is not found', async () => { mockExecuteSingleFunctions.getNodeParameter.mockReturnValue('containerName'); const mockApiResponse = {}; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); await expect(getPartitionKey.call(mockExecuteSingleFunctions)).rejects.toThrowError( new NodeOperationError(mockExecuteSingleFunctions.getNode(), 'Partition key not found', { @@ -77,7 +75,7 @@ describe('getPartitionKey', () => { }, ); - (azureCosmosDbApiRequest as jest.Mock).mockRejectedValue(mockError); + azureCosmosDbApiRequest.mockRejectedValue(mockError); await expect(getPartitionKey.call(mockExecuteSingleFunctions)).rejects.toThrowError( new NodeApiError( @@ -93,17 +91,12 @@ describe('getPartitionKey', () => { }); describe('validatePartitionKey', () => { - let mockExecuteSingleFunctions: any; let requestOptions: any; beforeEach(() => { - mockExecuteSingleFunctions = { - getNodeParameter: jest.fn(), - getNode: jest.fn(() => ({ name: 'MockNode' })), - }; requestOptions = { body: {}, headers: {} }; - (azureCosmosDbApiRequest as jest.Mock).mockClear(); + azureCosmosDbApiRequest.mockClear(); }); test('should throw NodeOperationError when partition key is missing for "create" operation', async () => { @@ -115,7 +108,7 @@ describe('validatePartitionKey', () => { paths: ['/partitionKeyPath'], }, }; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); await expect( validatePartitionKey.call(mockExecuteSingleFunctions, requestOptions), @@ -140,7 +133,7 @@ describe('validatePartitionKey', () => { paths: ['/partitionKeyPath'], }, }; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); await expect( validatePartitionKey.call(mockExecuteSingleFunctions, requestOptions), @@ -164,7 +157,7 @@ describe('validatePartitionKey', () => { paths: ['/partitionKeyPath'], }, }; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); await expect( validatePartitionKey.call(mockExecuteSingleFunctions, requestOptions), @@ -188,7 +181,7 @@ describe('validatePartitionKey', () => { paths: ['/partitionKeyPath'], }, }; - (azureCosmosDbApiRequest as jest.Mock).mockResolvedValue(mockApiResponse); + azureCosmosDbApiRequest.mockResolvedValue(mockApiResponse); await expect( validatePartitionKey.call(mockExecuteSingleFunctions, requestOptions), @@ -205,15 +198,6 @@ describe('validatePartitionKey', () => { }); describe('simplifyData', () => { - let mockExecuteSingleFunctions: any; - - beforeEach(() => { - mockExecuteSingleFunctions = { - getNodeParameter: jest.fn(), - getNode: jest.fn(() => ({ name: 'MockNode' })), - }; - }); - test('should return the same data when "simple" parameter is false', async () => { mockExecuteSingleFunctions.getNodeParameter.mockReturnValue(false); const items = [{ json: { foo: 'bar' } }] as INodeExecutionData[]; @@ -234,14 +218,9 @@ describe('simplifyData', () => { }); describe('validateQueryParameters', () => { - let mockExecuteSingleFunctions: any; let requestOptions: IHttpRequestOptions; beforeEach(() => { - mockExecuteSingleFunctions = { - getNodeParameter: jest.fn(), - getNode: jest.fn(() => ({ name: 'MockNode' })), - }; requestOptions = { body: {}, headers: {} } as IHttpRequestOptions; }); @@ -340,21 +319,12 @@ describe('processJsonInput', () => { }); describe('validateCustomProperties', () => { - let mockExecuteSingleFunctions: any; let requestOptions: any; beforeEach(() => { - mockExecuteSingleFunctions = { - getNodeParameter: jest.fn(), - getNode: jest.fn(() => ({ name: 'MockNode' })), - }; requestOptions = { body: {}, headers: {}, url: 'http://mock.url' }; }); - afterEach(() => { - jest.resetAllMocks(); - }); - test('should merge custom properties into requestOptions.body for valid input', async () => { const validCustomProperties = { property1: 'value1', property2: 'value2' }; mockExecuteSingleFunctions.getNodeParameter.mockReturnValue(validCustomProperties); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/create.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/create.test.ts index 8ddbf66cd8..0d9f66fa98 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/create.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/create.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Create Item', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('create.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -68,9 +57,5 @@ describe('Azure Cosmos DB - Create Item', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/delete.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/delete.test.ts index ad58c47a51..d557f3b485 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/delete.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/delete.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Delete Item', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('delete.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -61,9 +50,5 @@ describe('Azure Cosmos DB - Delete Item', () => { .reply(204, ''); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/get.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/get.test.ts index 82e45566e2..ac86066888 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/get.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/get.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Get Item', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('get.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -69,9 +58,5 @@ describe('Azure Cosmos DB - Get Item', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/getAll.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/getAll.test.ts index ef84ced552..6f2bc49394 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/getAll.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/getAll.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Get All Items', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('getAll.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -80,9 +69,5 @@ describe('Azure Cosmos DB - Get All Items', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/query.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/query.test.ts index 0b1db28809..43ba02653c 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/query.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/query.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Query Items', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('query.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -45,9 +34,5 @@ describe('Azure Cosmos DB - Query Items', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/update.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/update.test.ts index f6cf8edc27..860f7345b1 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/update.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/item/update.test.ts @@ -1,28 +1,17 @@ import nock from 'nock'; -import { - initBinaryDataService, - testWorkflows, - getWorkflowFilenames, -} from '../../../../../test/nodes/Helpers'; +import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; + +import { credentials } from '../credentials'; describe('Azure Cosmos DB - Update Item', () => { const workflows = getWorkflowFilenames(__dirname).filter((filename) => filename.includes('update.workflow.json'), ); - beforeAll(async () => { - await initBinaryDataService(); - }); - beforeEach(() => { - if (!nock.isActive()) { - nock.activate(); - } + const { baseUrl } = credentials.microsoftAzureCosmosDbSharedKeyApi; - const baseUrl = 'https://n8n-us-east-account.documents.azure.com/dbs/database_1'; - - nock.cleanAll(); nock(baseUrl) .persist() .defaultReplyHeaders({ 'Content-Type': 'application/json' }) @@ -73,9 +62,5 @@ describe('Azure Cosmos DB - Update Item', () => { }); }); - afterEach(() => { - nock.cleanAll(); - }); - - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/listSearch/listSearch.test.ts b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/listSearch/listSearch.test.ts index 75c1f6636a..2fcef51c84 100644 --- a/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/listSearch/listSearch.test.ts +++ b/packages/nodes-base/nodes/Microsoft/AzureCosmosDb/test/listSearch/listSearch.test.ts @@ -4,9 +4,9 @@ import { type ILoadOptionsFunctions, } from 'n8n-workflow'; -import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap'; import { AzureCosmosDb } from '../../AzureCosmosDb.node'; import { HeaderConstants } from '../../helpers/constants'; +import { credentials } from '../credentials'; describe('Azure Cosmos DB', () => { describe('List search', () => { @@ -31,7 +31,7 @@ describe('Azure Cosmos DB', () => { const mockGetCredentials = jest.fn(async (type: string, _itemIndex?: number) => { if (type === 'microsoftAzureCosmosDbSharedKeyApi') { - return FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi; + return credentials.microsoftAzureCosmosDbSharedKeyApi; } throw new OperationalError('Unknown credentials'); }); @@ -100,7 +100,7 @@ describe('Azure Cosmos DB', () => { const mockGetCredentials = jest.fn(async (type: string, _itemIndex?: number) => { if (type === 'microsoftAzureCosmosDbSharedKeyApi') { - return FAKE_CREDENTIALS_DATA.microsoftAzureCosmosDbSharedKeyApi; + return credentials.microsoftAzureCosmosDbSharedKeyApi; } throw new OperationalError('Unknown credentials'); }); 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 b1504a0161..233e1a1ded 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 @@ -1,13 +1,6 @@ -import type { - ICredentialDataDecryptedObject, - IDataObject, - IHttpRequestOptions, - ILoadOptionsFunctions, - WorkflowTestData, -} from 'n8n-workflow'; +import type { ILoadOptionsFunctions, WorkflowTestData } from 'n8n-workflow'; import { NodeConnectionTypes } from 'n8n-workflow'; -import { CredentialsHelper } from '@test/nodes/credentials-helper'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; @@ -18,6 +11,15 @@ describe('Microsoft Entra Node', () => { const baseUrl = 'https://graph.microsoft.com/v1.0'; describe('Credentials', () => { + const credentials = { + microsoftEntraOAuth2Api: { + scope: '', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + }, + }, + }; + const tests: WorkflowTestData[] = [ { description: 'should use correct credentials', @@ -92,33 +94,10 @@ describe('Microsoft Entra Node', () => { }, ], }, + credentials, }, ]; - beforeAll(() => { - jest - .spyOn(CredentialsHelper.prototype, 'authenticate') - .mockImplementation( - async ( - credentials: ICredentialDataDecryptedObject, - typeName: string, - requestParams: IHttpRequestOptions, - ): Promise => { - if (typeName === 'microsoftEntraOAuth2Api') { - return { - ...requestParams, - headers: { - authorization: - 'bearer ' + (credentials.oauthTokenData as IDataObject).access_token, - }, - }; - } else { - return requestParams; - } - }, - ); - }); - test.each(tests)('$description', async (testData) => { const { result } = await executeWorkflow(testData); const resultNodeData = Helpers.getResultNodeData(result, testData); diff --git a/packages/nodes-base/nodes/Microsoft/Excel/test/credentials.ts b/packages/nodes-base/nodes/Microsoft/Excel/test/credentials.ts new file mode 100644 index 0000000000..c41b5df802 --- /dev/null +++ b/packages/nodes-base/nodes/Microsoft/Excel/test/credentials.ts @@ -0,0 +1,8 @@ +export const credentials = { + microsoftExcelOAuth2Api: { + scope: 'openid', + oauthTokenData: { + access_token: 'token', + }, + }, +}; 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 4f30c28971..794d3f95c3 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => addTable', () => { nock('https://graph.microsoft.com/v1.0/me') .post( @@ -23,5 +25,5 @@ describe('Test MicrosoftExcelV2, table => addTable', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/addTable.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 42f9325b7b..1c734a0d82 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => append', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -24,5 +26,5 @@ describe('Test MicrosoftExcelV2, table => append', () => { .reply(200); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/append.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 7a3a29cd34..8cef6af557 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => convertToRange', () => { nock('https://graph.microsoft.com/v1.0/me') .post( @@ -19,5 +21,5 @@ describe('Test MicrosoftExcelV2, table => convertToRange', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/convertToRange.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 23fc5b8123..dc11e8aafa 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => deleteTable', () => { nock('https://graph.microsoft.com/v1.0/me') .delete( @@ -10,5 +12,5 @@ describe('Test MicrosoftExcelV2, table => deleteTable', () => { .reply(200); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/deleteTable.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 8b4bb89964..c5faff5f8c 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => getColumns', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -21,5 +23,5 @@ describe('Test MicrosoftExcelV2, table => getColumns', () => { .reply(200, { value: [] }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/getColumns.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 5f74d7ebe3..022579dc6d 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => getRows', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -30,5 +32,5 @@ describe('Test MicrosoftExcelV2, table => getRows', () => { .reply(200, { value: [] }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/getRows.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 582d1b8df0..c2db36e45b 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, table => lookup', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -38,5 +40,5 @@ describe('Test MicrosoftExcelV2, table => lookup', () => { .reply(200, { value: [] }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/table/lookup.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 729b312984..81bc1a7d46 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, workbook => addWorksheet', () => { nock('https://graph.microsoft.com/v1.0/me') .post('/drive/items/01FUWX3BQ4ATCOZNR265GLA6IJEZDQUE4I/workbook/createSession', { @@ -22,5 +24,5 @@ describe('Test MicrosoftExcelV2, workbook => addWorksheet', () => { .reply(200); const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/addWorksheet.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 12c0ec8442..6006163218 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 @@ -2,11 +2,13 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + 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']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 3b1b594945..0273a71c02 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, workbook => getAll', () => { nock('https://graph.microsoft.com/v1.0/me') .get("/drive/root/search(q='.xlsx')?%24select=name&%24top=2") @@ -19,5 +21,5 @@ describe('Test MicrosoftExcelV2, workbook => getAll', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/workbook/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 d769967157..4f6eea86ea 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => append', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -38,5 +40,5 @@ describe('Test MicrosoftExcelV2, worksheet => append', () => { .reply(200, { values: [[4, 'Don', 37, 'data 44']] }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/append.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 aac6c2bb8e..1c3c2c2bd7 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => clear', () => { nock('https://graph.microsoft.com/v1.0/me') .post( @@ -13,5 +15,5 @@ describe('Test MicrosoftExcelV2, worksheet => clear', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/clear.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 a2849aceac..61ecdad2ac 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => deleteWorksheet', () => { nock('https://graph.microsoft.com/v1.0/me') .delete( @@ -12,5 +14,5 @@ describe('Test MicrosoftExcelV2, worksheet => deleteWorksheet', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/deleteWorksheet.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 231c9bd5c5..3a7d979c07 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => getAll', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -25,5 +27,5 @@ describe('Test MicrosoftExcelV2, worksheet => getAll', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 64535f2adf..db0ab30827 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => readRows', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -27,5 +29,5 @@ describe('Test MicrosoftExcelV2, worksheet => readRows', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/readRows.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 1d5c272bfa..7475c1283b 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => update', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -52,5 +54,5 @@ describe('Test MicrosoftExcelV2, worksheet => update', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/update.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 51482fa172..3a78d999da 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftExcelV2, worksheet => upsert', () => { nock('https://graph.microsoft.com/v1.0/me') .get( @@ -54,5 +56,5 @@ describe('Test MicrosoftExcelV2, worksheet => upsert', () => { }); const workflows = ['nodes/Microsoft/Excel/test/v2/node/worksheet/upsert.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 a0ddb0cbde..5bce0fbfad 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_create.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -55,6 +57,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 be3d050c22..6d5560a66a 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_delete.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -24,6 +26,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 fb7ccb3970..b6a353b00c 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_get.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -76,6 +78,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 518b2cb3cb..da71d317e9 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_getAll.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -25,6 +27,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 73379146e8..ec3eec67ab 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = [ 'nodes/Microsoft/Storage/test/workflows/blob_getAllLimitOptions.workflow.json', @@ -20,6 +22,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 fdaeb52852..6b26834ed1 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_create.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -27,6 +29,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 24b8d69f81..cd71ff362a 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_delete.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -24,6 +26,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 8e7bb36902..b4ceb451fa 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_get.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -33,6 +35,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 409cc9b507..cf7f8e54a3 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/container_getAll.workflow.json']; const workflowTests = workflowToTests(workflows); @@ -25,6 +27,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 1cbd1252f3..fe863e44e2 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,5 +1,7 @@ import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = [ 'nodes/Microsoft/Storage/test/workflows/container_getAllLimitOptions.workflow.json', @@ -20,6 +22,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; test(workflow.description, async () => await equalityTest(workflow)); } }); diff --git a/packages/nodes-base/nodes/Microsoft/Storage/test/credentials.ts b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials.ts new file mode 100644 index 0000000000..5d93fa2c72 --- /dev/null +++ b/packages/nodes-base/nodes/Microsoft/Storage/test/credentials.ts @@ -0,0 +1,29 @@ +export const credentials = { + azureStorageOAuth2Api: { + grantType: 'authorizationCode', + authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', + accessTokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token', + clientId: 'CLIENTID', + clientSecret: 'CLIENTSECRET', + scope: 'https://storage.azure.com/user_impersonation', + authQueryParameters: 'response_mode=query', + authentication: 'body', + oauthTokenData: { + token_type: 'Bearer', + scope: 'https://storage.azure.com/user_impersonation', + expires_in: 4730, + ext_expires_in: 4730, + access_token: 'ACCESSTOKEN', + callbackQueryString: { + session_state: 'SESSIONSTATE', + }, + }, + account: 'myaccount', + baseUrl: 'https://myaccount.blob.core.windows.net', + }, + azureStorageSharedKeyApi: { + account: 'devstoreaccount1', + key: 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', + baseUrl: 'https://myaccount.blob.core.windows.net', + }, +}; 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 9eaafeb4ff..e1eb9a4706 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 @@ -1,43 +1,13 @@ -import type { - ICredentialDataDecryptedObject, - IDataObject, - IHttpRequestOptions, -} from 'n8n-workflow'; - -import { CredentialsHelper } from '@test/nodes/credentials-helper'; import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; +import { credentials } from '../credentials'; + describe('Azure Storage Node', () => { const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_oauth2.workflow.json']; const workflowTests = workflowToTests(workflows); describe('should use correct oauth2 credentials', () => { - beforeAll(() => { - jest - .spyOn(CredentialsHelper.prototype, 'authenticate') - .mockImplementation( - async ( - credentials: ICredentialDataDecryptedObject, - typeName: string, - requestParams: IHttpRequestOptions, - ): Promise => { - if (typeName === 'azureStorageOAuth2Api') { - return { - ...requestParams, - headers: { - authorization: `bearer ${(credentials.oauthTokenData as IDataObject).access_token as string}`, - }, - }; - } else { - return requestParams; - } - }, - ); - }); - - afterAll(() => { - jest.restoreAllMocks(); - }); + beforeEach(() => jest.restoreAllMocks()); for (const workflow of workflowTests) { workflow.nock = { @@ -67,6 +37,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; 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 cc5d7689c7..8bb0a165b5 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,44 +1,17 @@ import type { ICredentialDataDecryptedObject, IHttpRequestOptions } from 'n8n-workflow'; -import { CredentialsHelper } from '@test/nodes/credentials-helper'; -import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; +import { AzureStorageSharedKeyApi } from '@credentials/AzureStorageSharedKeyApi.credentials'; import { equalityTest, workflowToTests } from '@test/nodes/Helpers'; -import { AzureStorageSharedKeyApi } from '../../../../../credentials/AzureStorageSharedKeyApi.credentials'; +import { credentials } from '../credentials'; describe('Azure Storage Node', () => { - const { account, baseUrl, key } = FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi; + const { account, baseUrl, key } = credentials.azureStorageSharedKeyApi; const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_sharedKey.workflow.json']; const workflowTests = workflowToTests(workflows); describe('should use correct shared key credentials', () => { - beforeAll(() => { - jest - .spyOn(CredentialsHelper.prototype, 'authenticate') - .mockImplementation( - async ( - _credentials: ICredentialDataDecryptedObject, - typeName: string, - requestParams: IHttpRequestOptions, - ): Promise => { - if (typeName === 'azureStorageSharedKeyApi') { - return { - ...requestParams, - headers: { - authorization: - 'SharedKey Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', - }, - }; - } else { - return requestParams; - } - }, - ); - }); - - afterAll(() => { - jest.restoreAllMocks(); - }); + beforeEach(() => jest.restoreAllMocks()); for (const workflow of workflowTests) { workflow.nock = { @@ -68,6 +41,7 @@ describe('Azure Storage Node', () => { }, ], }; + workflow.credentials = credentials; test(workflow.description, async () => await equalityTest(workflow)); } }); @@ -76,7 +50,7 @@ describe('Azure Storage Node', () => { const azureStorageSharedKeyApi = new AzureStorageSharedKeyApi(); it('should remove undefined query parameters and headers', async () => { - const credentials: ICredentialDataDecryptedObject = { + const authCredentials: ICredentialDataDecryptedObject = { account, key, }; @@ -89,14 +63,14 @@ describe('Azure Storage Node', () => { method: 'GET', }; - const result = await azureStorageSharedKeyApi.authenticate(credentials, requestOptions); + const result = await azureStorageSharedKeyApi.authenticate(authCredentials, requestOptions); expect(result.qs).toEqual({ restype: 'container' }); expect(result.headers).not.toHaveProperty('Content-Length'); }); it('should default method to GET if not provided', async () => { - const credentials: ICredentialDataDecryptedObject = { + const authCredentials: ICredentialDataDecryptedObject = { account, key, }; @@ -108,12 +82,12 @@ describe('Azure Storage Node', () => { }, }; - const result = await azureStorageSharedKeyApi.authenticate(credentials, requestOptions); + const result = await azureStorageSharedKeyApi.authenticate(authCredentials, requestOptions); expect(result.method).toBe('GET'); }); it('should generate a valid authorization header', async () => { - const credentials: ICredentialDataDecryptedObject = { + const authCredentials: ICredentialDataDecryptedObject = { account, key, }; @@ -133,7 +107,7 @@ describe('Azure Storage Node', () => { }, method: 'PUT', }; - const result = await azureStorageSharedKeyApi.authenticate(credentials, requestOptions); + const result = await azureStorageSharedKeyApi.authenticate(authCredentials, requestOptions); expect(result.headers?.authorization).toBe( 'SharedKey devstoreaccount1:6sSQ3N4yNFQynBs/iLptIRPS5DQeaFBocW+dyYbAdOI=', 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 fe4d2da7a9..fac0086630 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,9 +1,8 @@ import type { ILoadOptionsFunctions, INodeParameterResourceLocator } from 'n8n-workflow'; -import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; - import { AzureStorage } from '../../AzureStorage.node'; import { XMsVersion } from '../../GenericFunctions'; +import { credentials } from '../credentials'; describe('Azure Storage Node', () => { describe('List search', () => { @@ -25,7 +24,7 @@ describe('Azure Storage Node', () => { }); const mockGetCredentials = jest.fn(async (type: string, _itemIndex?: number) => { if (type === 'azureStorageSharedKeyApi') { - return FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi; + return credentials.azureStorageSharedKeyApi; } // eslint-disable-next-line n8n-local-rules/no-plain-errors throw new Error('Unknown credentials'); @@ -76,7 +75,7 @@ describe('Azure Storage Node', () => { }); const mockGetCredentials = jest.fn(async (type: string, _itemIndex?: number) => { if (type === 'azureStorageSharedKeyApi') { - return FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi; + return credentials.azureStorageSharedKeyApi; } // eslint-disable-next-line n8n-local-rules/no-plain-errors throw new Error('Unknown credentials'); diff --git a/packages/nodes-base/nodes/Microsoft/Teams/test/credentials.ts b/packages/nodes-base/nodes/Microsoft/Teams/test/credentials.ts new file mode 100644 index 0000000000..f02e1fd1e5 --- /dev/null +++ b/packages/nodes-base/nodes/Microsoft/Teams/test/credentials.ts @@ -0,0 +1,8 @@ +export const credentials = { + microsoftTeamsOAuth2Api: { + scope: 'openid', + oauthTokenData: { + access_token: 'token', + }, + }, +}; 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 52357f1fb3..238e7c6d4d 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channel => create', () => { nock('https://graph.microsoft.com') .post('/v1.0/teams/1644e7fe-547e-4223-a24f-922395865343/channels') @@ -20,5 +22,5 @@ describe('Test MicrosoftTeamsV2, channel => create', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/create.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 2285408b17..44d4615953 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channel => deleteChannel', () => { nock('https://graph.microsoft.com') .delete( @@ -10,5 +12,5 @@ describe('Test MicrosoftTeamsV2, channel => deleteChannel', () => { .reply(200, {}); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/deleteChannel.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 e816dd86a3..1381955173 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channel => get', () => { nock('https://graph.microsoft.com') .get( @@ -23,5 +25,5 @@ describe('Test MicrosoftTeamsV2, channel => get', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/get.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 57db7670e3..83d6657734 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channel => getAll', () => { nock('https://graph.microsoft.com') .get('/v1.0/teams/1111-2222-3333/channels') @@ -47,5 +49,5 @@ describe('Test MicrosoftTeamsV2, channel => getAll', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 adb615621b..a9566e145b 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channel => update', () => { nock('https://graph.microsoft.com') .patch( @@ -11,5 +13,5 @@ describe('Test MicrosoftTeamsV2, channel => update', () => { .reply(200, {}); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channel/update.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 f62194fa8c..d01a548fef 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channelMessage => create', () => { nock('https://graph.microsoft.com') .post('/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages', { @@ -52,5 +54,5 @@ describe('Test MicrosoftTeamsV2, channelMessage => create', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/create.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 958f7d19e7..9f2ed49567 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, channelMessage => getAll', () => { nock('https://graph.microsoft.com') .get('/beta/teams/1111-2222-3333/channels/42:aaabbbccc.tacv2/messages') @@ -64,5 +66,5 @@ describe('Test MicrosoftTeamsV2, channelMessage => getAll', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/channelMessage/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 d448575074..77fe592cc6 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, chatMessage => create', () => { nock('https://graph.microsoft.com') .post('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages') @@ -46,5 +48,5 @@ describe('Test MicrosoftTeamsV2, chatMessage => create', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/create.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 0218981ecc..a7db5a705e 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, chatMessage => get', () => { nock('https://graph.microsoft.com') .get('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages/1698378560692') @@ -47,5 +49,5 @@ describe('Test MicrosoftTeamsV2, chatMessage => get', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/get.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 00f3fa1c6d..791ef01f3b 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, chatMessage => getAll', () => { nock('https://graph.microsoft.com') .get('/v1.0/chats/19:ebed9ad42c904d6c83adf0db360053ec@thread.v2/messages') @@ -87,5 +89,5 @@ describe('Test MicrosoftTeamsV2, chatMessage => getAll', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/chatMessage/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 d4a2ce1f8f..7471469e80 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, task => create', () => { nock('https://graph.microsoft.com') .post('/v1.0/planner/tasks', { @@ -70,5 +72,5 @@ describe('Test MicrosoftTeamsV2, task => create', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/create.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 745a564609..8d09b0050c 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, task => deleteTask', () => { nock('https://graph.microsoft.com') .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') @@ -11,5 +13,5 @@ describe('Test MicrosoftTeamsV2, task => deleteTask', () => { .reply(200, {}); const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/deleteTask.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 1b97df264d..aa901632e0 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, task => get', () => { nock('https://graph.microsoft.com') .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') @@ -58,5 +60,5 @@ describe('Test MicrosoftTeamsV2, task => get', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/get.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 680a38236a..26774d9bdb 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, task => getAll', () => { nock('https://graph.microsoft.com') .get('/v1.0/me') @@ -147,5 +149,5 @@ describe('Test MicrosoftTeamsV2, task => getAll', () => { }); const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/getAll.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); 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 b320ab729e..37bc10849d 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 @@ -2,6 +2,8 @@ import nock from 'nock'; import { testWorkflows } from '@test/nodes/Helpers'; +import { credentials } from '../../../credentials'; + describe('Test MicrosoftTeamsV2, task => update', () => { nock('https://graph.microsoft.com') .get('/v1.0/planner/tasks/lDrRJ7N_-06p_26iKBtJ6ZgAKffD') @@ -15,5 +17,5 @@ describe('Test MicrosoftTeamsV2, task => update', () => { .reply(200); const workflows = ['nodes/Microsoft/Teams/test/v2/node/task/update.workflow.json']; - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts b/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts index f2a77fc5e6..2aaf5c19ed 100644 --- a/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts +++ b/packages/nodes-base/nodes/MoveBinaryData/test/MoveBinaryData.test.ts @@ -6,10 +6,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Test Move Binary Data Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const workflow = Helpers.readJsonFileSync( 'nodes/MoveBinaryData/test/MoveBinaryData.workflow.json', ); 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 b38860f0ec..a9735461ff 100644 --- a/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts +++ b/packages/nodes-base/nodes/N8n/test/node/N8n.test.ts @@ -5,12 +5,19 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import { workflowToTests, getWorkflowFilenames } from '@test/nodes/Helpers'; describe('Test N8n Node, expect base_url to be received from credentials', () => { + const credentials = { + n8nApi: { + apiKey: 'key123', + baseUrl: 'https://test.app.n8n.cloud/api/v1', + }, + }; + const workflows = getWorkflowFilenames(__dirname); - const tests = workflowToTests(workflows); + const tests = workflowToTests(workflows, credentials); beforeAll(() => { //base url is set in fake credentials map packages/nodes-base/test/nodes/FakeCredentialsMap.ts - const baseUrl = 'https://test.app.n8n.cloud/api/v1'; + const { baseUrl } = credentials.n8nApi; nock(baseUrl).get('/workflows?tags=n8n-test').reply(200, {}); }); diff --git a/packages/nodes-base/nodes/Npm/test/Npm.node.test.ts b/packages/nodes-base/nodes/Npm/test/Npm.node.test.ts index 12cb215935..71c7af6b42 100644 --- a/packages/nodes-base/nodes/Npm/test/Npm.node.test.ts +++ b/packages/nodes-base/nodes/Npm/test/Npm.node.test.ts @@ -1,11 +1,17 @@ import nock from 'nock'; -import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; describe('Test npm Node', () => { + const credentials = { + npmApi: { + accessToken: 'fake-npm-access-token', + registryUrl: 'https://fake.npm.registry', + }, + }; + beforeAll(() => { - const { registryUrl } = FAKE_CREDENTIALS_DATA.npmApi; + const { registryUrl } = credentials.npmApi; const mock = nock(registryUrl); //.matchHeader('Authorization', `Bearer ${accessToken}`); mock.get('/-/package/n8n/dist-tags').reply(200, { @@ -29,5 +35,5 @@ describe('Test npm Node', () => { }); const workflows = getWorkflowFilenames(__dirname); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts b/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts index 75e16d6754..1240afdda1 100644 --- a/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts +++ b/packages/nodes-base/nodes/PhilipsHue/test/workflow.test.ts @@ -10,6 +10,25 @@ import { } from './apiResponses'; describe('PhilipsHue', () => { + const credentials = { + philipsHueOAuth2Api: { + grantType: 'authorizationCode', + appId: 'APPID', + authUrl: 'https://api.meethue.com/v2/oauth2/authorize', + accessTokenUrl: 'https://api.meethue.com/v2/oauth2/token', + authQueryParameters: 'appid=APPID', + scope: '', + authentication: 'header', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + refresh_token: 'REFRESHTOKEN', + scope: '', + token_type: 'bearer', + expires_in: 86400, + }, + }, + }; + describe('Run workflow', () => { beforeAll(() => { const mock = nock('https://api.meethue.com/route'); @@ -20,6 +39,6 @@ describe('PhilipsHue', () => { }); const workflows = getWorkflowFilenames(__dirname); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); 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 e6689182bf..d63fb157c7 100644 --- a/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts +++ b/packages/nodes-base/nodes/QuickChart/test/QuickChart.node.test.ts @@ -7,7 +7,6 @@ import * as Helpers from '@test/nodes/Helpers'; describe('Test QuickChart Node', () => { beforeEach(async () => { - await Helpers.initBinaryDataService(); nock('https://quickchart.io') .persist() .get(/chart.*/) diff --git a/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts b/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts index 2549134bbf..376a13bb94 100644 --- a/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts +++ b/packages/nodes-base/nodes/ReadBinaryFile/test/ReadBinaryFile.test.ts @@ -6,10 +6,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Test Read Binary File Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const workflow = Helpers.readJsonFileSync( 'nodes/ReadBinaryFile/test/ReadBinaryFile.workflow.json', ); diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts index 9c8e43c5c3..9e407f45da 100644 --- a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts @@ -6,10 +6,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Test Read Binary Files Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const workflow = Helpers.readJsonFileSync( 'nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json', ); diff --git a/packages/nodes-base/nodes/ReadPdf/test/ReadPDF.test.ts b/packages/nodes-base/nodes/ReadPdf/test/ReadPDF.test.ts index 8a394c0ce9..492724df16 100644 --- a/packages/nodes-base/nodes/ReadPdf/test/ReadPDF.test.ts +++ b/packages/nodes-base/nodes/ReadPdf/test/ReadPDF.test.ts @@ -1,11 +1,7 @@ -import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers'; +import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; describe('Test Read PDF Node', () => { const workflows = getWorkflowFilenames(__dirname); - beforeAll(async () => { - await initBinaryDataService(); - }); - testWorkflows(workflows); }); diff --git a/packages/nodes-base/nodes/Salesforce/__test__/node/Salesforce.node.test.ts b/packages/nodes-base/nodes/Salesforce/__test__/node/Salesforce.node.test.ts index fac291ebab..808e480370 100644 --- a/packages/nodes-base/nodes/Salesforce/__test__/node/Salesforce.node.test.ts +++ b/packages/nodes-base/nodes/Salesforce/__test__/node/Salesforce.node.test.ts @@ -10,13 +10,19 @@ import opportunityDetails from './fixtures/opportunity-details.json'; import taskDetails from './fixtures/task-details.json'; import taskSummary from './fixtures/task-summary.json'; import tasks from './fixtures/tasks.json'; -import userDeltails from './fixtures/user-details.json'; +import userDetails from './fixtures/user-details.json'; import users from './fixtures/users.json'; describe('Salesforce Node', () => { - nock.emitter.on('no match', (req) => { - console.error('Unmatched request: ', req); - }); + const credentials = { + salesforceOAuth2Api: { + scope: 'full refresh_token', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + instance_url: 'https://salesforce.instance', + }, + }, + }; const salesforceNock = nock('https://salesforce.instance/services/data/v59.0'); @@ -29,14 +35,12 @@ describe('Salesforce Node', () => { }) .reply(200, { records: users }) .get('/sobjects/user/id1') - .reply(200, userDeltails); + .reply(200, userDetails); }); - testWorkflows(['nodes/Salesforce/__test__/node/users.workflow.json']); + afterAll(() => salesforceNock.done()); - it('should make the correct network calls', () => { - salesforceNock.done(); - }); + testWorkflows(['nodes/Salesforce/__test__/node/users.workflow.json'], credentials); }); describe('tasks', () => { @@ -63,11 +67,9 @@ describe('Salesforce Node', () => { .reply(200, { success: true, errors: [] }); }); - testWorkflows(['nodes/Salesforce/__test__/node/tasks.workflow.json']); + afterAll(() => salesforceNock.done()); - it('should make the correct network calls', () => { - salesforceNock.done(); - }); + testWorkflows(['nodes/Salesforce/__test__/node/tasks.workflow.json'], credentials); }); describe('accounts', () => { @@ -96,11 +98,9 @@ describe('Salesforce Node', () => { .reply(200, { success: true, errors: [] }); }); - testWorkflows(['nodes/Salesforce/__test__/node/accounts.workflow.json']); + afterAll(() => salesforceNock.done()); - it('should make the correct network calls', () => { - salesforceNock.done(); - }); + testWorkflows(['nodes/Salesforce/__test__/node/accounts.workflow.json'], credentials); }); describe('search', () => { @@ -113,11 +113,9 @@ describe('Salesforce Node', () => { .reply(200, { records: accounts }); }); - testWorkflows(['nodes/Salesforce/__test__/node/search.workflow.json']); + afterAll(() => salesforceNock.done()); - it('should make the correct network calls', () => { - salesforceNock.done(); - }); + testWorkflows(['nodes/Salesforce/__test__/node/search.workflow.json'], credentials); }); describe('opportunities', () => { @@ -156,10 +154,8 @@ describe('Salesforce Node', () => { .reply(200, opportunitiesSummary); }); - testWorkflows(['nodes/Salesforce/__test__/node/opportunities.workflow.json']); + afterAll(() => salesforceNock.done()); - it('should make the correct network calls', () => { - salesforceNock.done(); - }); + testWorkflows(['nodes/Salesforce/__test__/node/opportunities.workflow.json'], credentials); }); }); 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 dafa67a49f..e7ba0d647e 100644 --- a/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts +++ b/packages/nodes-base/nodes/SendGrid/test/SendGrid.node.test.ts @@ -13,10 +13,8 @@ describe('Test SendGrid Node', () => { ) .reply(202); - testWorkflows(['nodes/SendGrid/test/mail.workflow.json']); + afterAll(() => sendgridNock.done()); - it('should make the correct network calls', () => { - sendgridNock.done(); - }); + testWorkflows(['nodes/SendGrid/test/mail.workflow.json']); }); }); diff --git a/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts b/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts index 11f55bcfa1..dfe7342daa 100644 --- a/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts +++ b/packages/nodes-base/nodes/SpreadsheetFile/test/SpreadsheetFile.test.ts @@ -6,10 +6,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Execute Spreadsheet File Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const readBinaryFile = (fileName: string) => readFileSync(path.resolve(__dirname, fileName), 'base64'); diff --git a/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts b/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts index ee2b22bc5d..920b46b5ee 100644 --- a/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts +++ b/packages/nodes-base/nodes/Start/__tests__/StartNode.test.ts @@ -1,5 +1,7 @@ import type { WorkflowTestData } from 'n8n-workflow'; +// This is (temporarily) needed to setup LoadNodesAndCredentials first +import '@test/nodes/Helpers'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; describe('Execute Start Node', () => { 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 4b518b1afa..4e7ce98ad1 100644 --- a/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts +++ b/packages/nodes-base/nodes/StopAndError/test/node/StopAndError.test.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-loop-func */ import { NodeConnectionTypes, type IDataObject, type WorkflowTestData } from 'n8n-workflow'; +// This is (temporarily) needed to setup LoadNodesAndCredentials first +import '@test/nodes/Helpers'; import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; describe('Execute Stop and Error Node', () => { 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 ebb84ac705..398938346c 100644 --- a/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts +++ b/packages/nodes-base/nodes/Telegram/tests/Workflow/workflow.test.ts @@ -1,6 +1,5 @@ import nock from 'nock'; -import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap'; import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { @@ -18,10 +17,16 @@ import { } from './apiResponses'; describe('Telegram', () => { + const credentials = { + telegramApi: { + accessToken: 'testToken', + baseUrl: 'https://api.telegram.org', + }, + }; + describe('Run Telegram workflow', () => { beforeAll(() => { - const { baseUrl } = FAKE_CREDENTIALS_DATA.telegramApi; - const mock = nock(baseUrl); + const mock = nock(credentials.telegramApi.baseUrl); mock.post('/bottestToken/getChat').reply(200, getChatResponse); mock.post('/bottestToken/sendMessage').reply(200, sendMessageResponse); @@ -43,6 +48,6 @@ describe('Telegram', () => { }); const workflows = getWorkflowFilenames(__dirname); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); }); 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 ca9afe45ee..ae76a86934 100644 --- a/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts +++ b/packages/nodes-base/nodes/Totp/test/Totp.node.test.ts @@ -25,6 +25,12 @@ describe('Execute TOTP node', () => { TOTP: [[{ json: { token: '123456' } }]], // ignore secondsRemaining to prevent flakiness }, }, + credentials: { + totpApi: { + label: 'GitHub:john-doe', + secret: 'BVDRSBXQB2ZEL5HE', + }, + }, }, ]; diff --git a/packages/nodes-base/nodes/Twitter/test/Twitter.test.ts b/packages/nodes-base/nodes/Twitter/test/Twitter.test.ts index 49339e1a61..48c344590b 100644 --- a/packages/nodes-base/nodes/Twitter/test/Twitter.test.ts +++ b/packages/nodes-base/nodes/Twitter/test/Twitter.test.ts @@ -72,6 +72,15 @@ const meResult = { }; describe('Test Twitter Request Node', () => { + const credentials = { + twitterOAuth2Api: { + scope: '', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + }, + }, + }; + beforeAll(() => { const baseUrl = 'https://api.twitter.com/2'; //GET @@ -83,7 +92,7 @@ describe('Test Twitter Request Node', () => { }); const workflows = getWorkflowFilenames(__dirname); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); describe('X / Twitter Node unit tests', () => { diff --git a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/credentials.ts b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/credentials.ts new file mode 100644 index 0000000000..5a99867601 --- /dev/null +++ b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/credentials.ts @@ -0,0 +1,8 @@ +export const credentials = { + wordpressApi: { + url: 'https://myblog.com', + allowUnauthorizedCerts: false, + username: 'nodeqa', + password: 'fake-password', + }, +}; diff --git a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/page/page.test.ts b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/page/page.test.ts index 22aef51a9a..6d3e5cdc50 100644 --- a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/page/page.test.ts +++ b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/page/page.test.ts @@ -3,12 +3,13 @@ import nock from 'nock'; import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { pageCreate, pageGet, pageGetMany, pageUpdate } from '../apiResponses'; +import { credentials } from '../credentials'; describe('Wordpress > Page Workflows', () => { const workflows = getWorkflowFilenames(__dirname); beforeAll(() => { - const mock = nock('https://myblog.com'); + const mock = nock(credentials.wordpressApi.url); mock .post('/wp-json/wp/v2/pages', { title: 'A new page', @@ -31,5 +32,5 @@ describe('Wordpress > Page Workflows', () => { .reply(200, pageUpdate); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/post/post.test.ts b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/post/post.test.ts index 81b146df3c..572b42868e 100644 --- a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/post/post.test.ts +++ b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/post/post.test.ts @@ -3,12 +3,13 @@ import nock from 'nock'; import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { postCreate, postGet, postGetMany, postUpdate } from '../apiResponses'; +import { credentials } from '../credentials'; describe('Wordpress > Post Workflows', () => { const workflows = getWorkflowFilenames(__dirname); beforeAll(() => { - const mock = nock('https://myblog.com'); + const mock = nock(credentials.wordpressApi.url); mock.get('/wp-json/wp/v2/posts/1').reply(200, postGet); mock.get('/wp-json/wp/v2/posts').query({ per_page: 10, page: 1 }).reply(200, postGetMany); mock @@ -35,5 +36,5 @@ describe('Wordpress > Post Workflows', () => { .reply(200, postUpdate); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/user/user.test.ts b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/user/user.test.ts index 2e372813a7..d90fc74892 100644 --- a/packages/nodes-base/nodes/Wordpress/__tests__/workflow/user/user.test.ts +++ b/packages/nodes-base/nodes/Wordpress/__tests__/workflow/user/user.test.ts @@ -3,12 +3,13 @@ import nock from 'nock'; import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers'; import { userCreate, userGet, userGetMany, userUpdate } from '../apiResponses'; +import { credentials } from '../credentials'; describe('Wordpress > User Workflows', () => { const workflows = getWorkflowFilenames(__dirname); beforeAll(() => { - const mock = nock('https://myblog.com'); + const mock = nock(credentials.wordpressApi.url); mock .post('/wp-json/wp/v2/users', { name: 'nathan tester', @@ -32,5 +33,5 @@ describe('Wordpress > User Workflows', () => { .reply(200, userUpdate); }); - testWorkflows(workflows); + testWorkflows(workflows, credentials); }); diff --git a/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts b/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts index f85a8d3994..0db8a1e9ff 100644 --- a/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts +++ b/packages/nodes-base/nodes/WriteBinaryFile/test/WriteBinaryFile.test.ts @@ -6,10 +6,6 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow'; import * as Helpers from '@test/nodes/Helpers'; describe('Test Write Binary File Node', () => { - beforeEach(async () => { - await Helpers.initBinaryDataService(); - }); - const temporaryDir = Helpers.createTemporaryDir(); const workflow = Helpers.readJsonFileSync( 'nodes/WriteBinaryFile/test/WriteBinaryFile.workflow.json', diff --git a/packages/nodes-base/test/globalSetup.ts b/packages/nodes-base/test/globalSetup.ts index 49629bf321..dadf7ed029 100644 --- a/packages/nodes-base/test/globalSetup.ts +++ b/packages/nodes-base/test/globalSetup.ts @@ -2,4 +2,8 @@ import nock from 'nock'; export default async () => { nock.disableNetConnect(); + + nock.emitter.on('no match', (req) => { + console.error('No mock for network request: ', req); + }); }; diff --git a/packages/nodes-base/test/nodes/ExecuteWorkflow.ts b/packages/nodes-base/test/nodes/ExecuteWorkflow.ts index c5b1e5ec6b..83b6d41423 100644 --- a/packages/nodes-base/test/nodes/ExecuteWorkflow.ts +++ b/packages/nodes-base/test/nodes/ExecuteWorkflow.ts @@ -13,12 +13,12 @@ import nock from 'nock'; 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); + const credentialsHelper = Container.get(CredentialsHelper); + credentialsHelper.setCredentials(testData.credentials ?? {}); + if (testData.nock) { const { baseUrl, mocks } = testData.nock; const agent = nock(baseUrl); @@ -47,6 +47,7 @@ export async function executeWorkflow(testData: WorkflowTestData) { }, ); } + const executionMode = testData.trigger?.mode ?? 'manual'; const workflowInstance = new Workflow({ id: 'test', @@ -64,12 +65,13 @@ export async function executeWorkflow(testData: WorkflowTestData) { nodeExecutionOrder.push(nodeName); }); hooks.addHandler('workflowExecuteAfter', (fullRunData) => waitPromise.resolve(fullRunData)); + const additionalData = mock({ - credentialsHelper: Container.get(CredentialsHelper), hooks, // Get from node.parameters currentNodeParameters: undefined, }); + additionalData.credentialsHelper = credentialsHelper; let executionData: IRun; const runExecutionData: IRunExecutionData = { diff --git a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts deleted file mode 100644 index 42fd70212b..0000000000 --- a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts +++ /dev/null @@ -1,301 +0,0 @@ -// If your test needs data from credentials, you can add it here. -// as JSON.stringify({ id: 'credentials_ID', name: 'credentials_name' }) for specific credentials -// or as 'credentials_type' for all credentials of that type -// expected keys for credentials can be found in packages/nodes-base/credentials/[credentials_type].credentials.ts -export const FAKE_CREDENTIALS_DATA = { - [JSON.stringify({ id: '20', name: 'Airtable account' })]: { - apiKey: 'key456', - }, - [JSON.stringify({ id: 'G45TOKX5kBEraTr1', name: 'JWT Auth test PEM' })]: { - keyType: 'pemKey', - privateKey: ` ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCfw0m1K+M1/6Tw -CvLYDv0gmxa+reEdKBfT0/hfkkjFWqbMRo0f4CQ3PwrOavS+80PDy6nVL21BmGev -w1bF7KXmqOzr+yKOUJ8A4u6vXUQKzVSFBqb2YZmZL1s7va9aaO6pVANTbmYHpTjh -SBnBrXgidVOXNX1c+IG+OZZMiTFWg4lJTE9rvMbLh4o5FPwdZlA1rLAux4KXVNNr -mE7T5/tsuikR06KMJS6V6YR4PZmTsy/3D2clADXDCtbUdEe0eBYoUmRLMhRL6umq -h98Dsm5ZG+YB2dn0ThR/g7DPVwvmnrK2S5e4hpqFYxQ8V8pGx7dQLsc/utbvsn32 -dctGivkFAgMBAAECggEABDB0QdZtRlC2S/8VgBnghFbcwVJA6WlQOqM/y43D77zh -S9D7yV6wxGwYRfJjCZDKcZtpECiGtmYfLeoy38zFSueaEtQKg23UxYqt1JZe/uOE -eFqEzUgg5XXq8AWY0AeZXoJP9gOalE++TpX76uq4EDtAXmIuL95qVIkhCk+8pfaR -avLcejnyYGSJAG1J9pXHNChXXDVPd7PrIa20A44osvusifVMlcIYM3qkv167ULzX -4nu2hZwlNxGKtpVPldFY/qu5S7SdLo/2BQinrMSSKRSFihA4Uuod8GK0+UwjE4gO -TD15bjqIcadlAYV6bn34sHnMU9hjhPB5NyXiINYdsQKBgQDNu0XFjYyAgwORaZYs -jVTJg+fQ9wM7xnlfxXCVb9eoOGF0blW9VjIEz8lLjmPlPFFVS+EPN0andHHqH4t5 -SQZVZxgNMcodWs8BJTVZUkXa+IljHXT1Vkb2zvtH96ADzs3c43+tNpmKhjG3XK1U -rL/v8feU31nwQb7imOmYmzbHCQKBgQDGzJ/pRLByB24W6FRfHIItP81vVg5ckCXi -sIhzHUdUmTdVbdAxeS6IW2oAc/IuksvmiZMLYsm+sIFFePJQrBsoD41R5VsFcJqE -o5x0DUzbOzqaV4HPOHDniibudyryZKnBvkXlCjyCv4iPKaFhH4T1aB+wdK4pJPo2 -fyABs2lFHQKBgQDHz6IFK+QREK3PdhA/twhpK65jWvUOAkbxyE3/JX/7xr6IGX02 -hdfQqoqj0midRMbto+OzJol9q+/TZs3MfysimR1X+0qE1iSExUGaPfjQomC1He/x -M9l6bi7Jh+wmpp10cpQXhBb93jW9E8rYmWtVPNmsAn1UhlZBuCfwapd6GQKBgATM -f7ezzsaR41huN0ssdv/8oErluucFG8UDGegddtFV+X34bqQjFrp36nEkW15AcOeZ -vpDxy4js3dH9f2vvG6C172VgsffJphE5mdc7UvWf0mRTZHDKHf+Y2CO9gK3lPCvP -GgTTYG6PjQ5XpOuhRSZfYxRxXJrlp5yVKQKhgBMJAoGBAMc6ktd0iqHAYCW3d9QP -e618RiMlVIYZIUlLWAUQWQSf3linqMjo1rCbbI/lSxE216XwI/VBX50gg/Oy3aUl -CibHHk2aKGlxVxe0Huv5gcjbZgVh1EMi4oxh4600IrWRH1Uz5AleXnheNiappKnA -lOMhy99LXMlAOL7qOBnZHgrm ------END PRIVATE KEY----- - `, - publicKey: ` ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn8NJtSvjNf+k8Ary2A79 -IJsWvq3hHSgX09P4X5JIxVqmzEaNH+AkNz8Kzmr0vvNDw8up1S9tQZhnr8NWxeyl -5qjs6/sijlCfAOLur11ECs1UhQam9mGZmS9bO72vWmjuqVQDU25mB6U44UgZwa14 -InVTlzV9XPiBvjmWTIkxVoOJSUxPa7zGy4eKORT8HWZQNaywLseCl1TTa5hO0+f7 -bLopEdOijCUulemEeD2Zk7Mv9w9nJQA1wwrW1HRHtHgWKFJkSzIUS+rpqoffA7Ju -WRvmAdnZ9E4Uf4Owz1cL5p6ytkuXuIaahWMUPFfKRse3UC7HP7rW77J99nXLRor5 -BQIDAQAB ------END PUBLIC KEY----- - `, - algorithm: 'RS256', - }, - airtableApi: { - apiKey: 'key123', - }, - azureStorageOAuth2Api: { - grantType: 'authorizationCode', - authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', - accessTokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: 'https://storage.azure.com/user_impersonation', - authQueryParameters: 'response_mode=query', - authentication: 'body', - oauthTokenData: { - token_type: 'Bearer', - scope: 'https://storage.azure.com/user_impersonation', - expires_in: 4730, - ext_expires_in: 4730, - access_token: 'ACCESSTOKEN', - callbackQueryString: { - session_state: 'SESSIONSTATE', - }, - }, - account: 'myaccount', - baseUrl: 'https://myaccount.blob.core.windows.net', - }, - azureStorageSharedKeyApi: { - account: 'devstoreaccount1', - key: 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', - baseUrl: 'https://myaccount.blob.core.windows.net', - }, - gongApi: { - baseUrl: 'https://api.gong.io', - accessKey: 'accessKey123', - accessKeySecret: 'accessKeySecret123', - }, - gongOAuth2Api: { - grantType: 'authorizationCode', - authUrl: 'https://app.gong.io/oauth2/authorize', - accessTokenUrl: 'https://app.gong.io/oauth2/generate-customer-token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: - 'api:calls:read:transcript api:provisioning:read api:workspaces:read api:meetings:user:delete api:crm:get-objects api:data-privacy:delete api:crm:schema api:flows:write api:crm:upload api:meetings:integration:status api:calls:read:extensive api:meetings:user:update api:integration-settings:write api:settings:scorecards:read api:stats:scorecards api:stats:interaction api:stats:user-actions api:crm:integration:delete api:calls:read:basic api:calls:read:media-url api:digital-interactions:write api:crm:integrations:read api:library:read api:data-privacy:read api:users:read api:logs:read api:calls:create api:meetings:user:create api:stats:user-actions:detailed api:settings:trackers:read api:crm:integration:register api:provisioning:read-write api:engagement-data:write api:permission-profile:read api:permission-profile:write api:flows:read api:crm-calls:manual-association:read', - authQueryParameters: '', - authentication: 'header', - oauthTokenData: { - access_token: 'ACCESSTOKEN', - refresh_token: 'REFRESHTOKEN', - scope: - 'api:calls:read:transcript api:provisioning:read api:workspaces:read api:meetings:user:delete api:crm:get-objects api:data-privacy:delete api:crm:schema api:flows:write api:crm:upload api:meetings:integration:status api:calls:read:extensive api:meetings:user:update api:integration-settings:write api:settings:scorecards:read api:stats:scorecards api:stats:interaction api:stats:user-actions api:crm:integration:delete api:calls:read:basic api:calls:read:media-url api:digital-interactions:write api:crm:integrations:read api:library:read api:data-privacy:read api:users:read api:logs:read api:calls:create api:meetings:user:create api:stats:user-actions:detailed api:settings:trackers:read api:crm:integration:register api:provisioning:read-write api:engagement-data:write api:permission-profile:read api:permission-profile:write api:flows:read api:crm-calls:manual-association:read', - token_type: 'bearer', - expires_in: 86400, - api_base_url_for_customer: 'https://api.gong.io', - }, - baseUrl: 'https://api.gong.io', - }, - microsoftAzureCosmosDbSharedKeyApi: { - account: 'n8n-us-east-account', - key: 'I3rwpzP0XoFpNzJ7hRIUXjwgpD1qaVKi71NZBbk7oOHUXrbd80WAoIAAoRaT47W9hHO3b6us1yABACDbVdilag==', - database: 'database_1', - baseUrl: 'https://n8n-us-east-account.documents.azure.com/dbs/database_1', - }, - microsoftEntraOAuth2Api: { - grantType: 'authorizationCode', - authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', - accessTokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: - 'openid offline_access AccessReview.ReadWrite.All Directory.ReadWrite.All NetworkAccessPolicy.ReadWrite.All DelegatedAdminRelationship.ReadWrite.All EntitlementManagement.ReadWrite.All User.ReadWrite.All Directory.AccessAsUser.All Sites.FullControl.All', - authQueryParameters: 'response_mode=query', - authentication: 'body', - oauthTokenData: { - token_type: 'Bearer', - scope: - 'AccessReview.ReadWrite.All DelegatedAdminRelationship.ReadWrite.All Directory.AccessAsUser.All Directory.Read.All Directory.ReadWrite.All EntitlementManagement.ReadWrite.All Group.ReadWrite.All NetworkAccessPolicy.ReadWrite.All openid Sites.FullControl.All User.DeleteRestore.All User.EnableDisableAccount.All User.Export.All User.Invite.All User.ManageIdentities.All User.Read User.Read.All User.ReadBasic.All User.ReadWrite User.ReadWrite.All User.RevokeSessions.All profile email', - expires_in: 4822, - ext_expires_in: 4822, - access_token: 'ACCESSTOKEN', - refresh_token: 'REFRESHTOKEN', - id_token: 'IDTOKEN', - callbackQueryString: { - session_state: 'SESSIONSTATE', - }, - }, - }, - 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', - }, - npmApi: { - accessToken: 'fake-npm-access-token', - registryUrl: 'https://fake.npm.registry', - }, - totpApi: { - label: 'GitHub:john-doe', - secret: 'BVDRSBXQB2ZEL5HE', - }, - aws: { - region: 'eu-central-1', - accessKeyId: 'key', - secretAccessKey: 'secret', - }, - twitterOAuth2Api: { - grantType: 'pkce', - authUrl: 'https://twitter.com/i/oauth2/authorize', - accessTokenUrl: 'https://api.twitter.com/2/oauth2/token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: - 'tweet.read users.read tweet.write tweet.moderate.write users.read follows.read follows.write offline.access like.read like.write dm.write dm.read list.read list.write', - authQueryParameters: '', - authentication: 'header', - oauthTokenData: { - token_type: 'bearer', - expires_in: 7200, - access_token: 'ACCESSTOKEN', - scope: - 'tweet.moderate.write follows.read offline.access list.write dm.read list.read tweet.write like.write like.read users.read dm.write tweet.read follows.write', - refresh_token: 'REFRESHTOKEN', - }, - }, - jwtAuth: { - keyType: 'passphrase', - secret: 'baz', - algorithm: 'HS256', - }, - telegramApi: { - accessToken: 'testToken', - baseUrl: 'https://api.telegram.org', - }, - gmailOAuth2: { - grantType: 'authorizationCode', - authUrl: 'https://accounts.google.com/o/oauth2/v2/auth', - accessTokenUrl: 'https://oauth2.googleapis.com/token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: - 'https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.addons.current.message.action https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose', - authQueryParameters: 'access_type=offline&prompt=consent', - authentication: 'body', - oauthTokenData: { - access_token: 'ACCESSTOKEN', - refresh_token: 'REFRESHTOKEN', - scope: - 'https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.addons.current.message.action https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose', - token_type: 'bearer', - expires_in: 86400, - }, - }, - youTubeOAuth2Api: { - grantType: 'authorizationCode', - authUrl: 'https://accounts.google.com/o/oauth2/v2/auth', - accessTokenUrl: 'https://oauth2.googleapis.com/token', - clientId: 'CLIENTID', - clientSecret: 'CLIENTSECRET', - scope: - 'https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner-channel-audit', - authQueryParameters: 'access_type=offline&prompt=consent', - authentication: 'body', - oauthTokenData: { - access_token: 'ACCESSTOKEN', - refresh_token: 'REFRESHTOKEN', - scope: - 'https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner-channel-audit', - token_type: 'bearer', - expires_in: 86400, - }, - }, - notionApi: { - apiKey: 'key123', - }, - philipsHueOAuth2Api: { - grantType: 'authorizationCode', - appId: 'APPID', - authUrl: 'https://api.meethue.com/v2/oauth2/authorize', - accessTokenUrl: 'https://api.meethue.com/v2/oauth2/token', - authQueryParameters: 'appid=APPID', - scope: '', - authentication: 'header', - oauthTokenData: { - access_token: 'ACCESSTOKEN', - refresh_token: 'REFRESHTOKEN', - scope: '', - token_type: 'bearer', - expires_in: 86400, - }, - }, - spotifyOAuth2Api: { - accessTokenUrl: 'https://accounts.spotify.com/api/token', - authQueryParameters: '', - authUrl: 'https://accounts.spotify.com/authorize', - authentication: 'header', - clientId: 'CLIENT_ID', - clientSecret: 'CLIENT_SECRET', - grantType: 'authorizationCode', - oauthTokenData: { - access_token: 'ACCESS_TOKEN', - expires_in: 3600, - refresh_token: 'REFRESH_TOKEN', - scope: - 'playlist-read-private playlist-read-collaborative user-modify-playback-state user-library-read user-follow-read playlist-modify-private playlist-modify-public user-read-playback-state user-read-currently-playing user-read-recently-played', - token_type: 'Bearer', - }, - scope: - 'user-read-playback-state playlist-read-collaborative user-modify-playback-state playlist-modify-public user-read-currently-playing playlist-read-private user-read-recently-played playlist-modify-private user-library-read user-follow-read', - server: 'https://api.spotify.com/', - }, - baserowApi: { - host: 'https://api.baserow.io', - username: 'nathan@n8n.io', - password: 'fake-password', - }, - wordpressApi: { - url: 'https://myblog.com', - allowUnauthorizedCerts: false, - username: 'nodeqa', - password: 'fake-password', - }, - discordWebhookApi: { - webhookUri: 'https://discord.com/webhook', - }, - salesforceOAuth2Api: { - grantType: 'pkce', - environment: 'production', - authUrl: 'https://login.salesforce.com/services/oauth2/authorize', - accessTokenUrl: 'https://login.salesforce.com/services/oauth2/token', - scope: 'full refresh_token', - authQueryParameters: '', - authentication: 'header', - oauthTokenData: { - access_token: 'ACCESSTOKEN', - instance_url: 'https://salesforce.instance', - }, - }, -} as const; diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 77a3ae7803..e927ac0284 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -1,10 +1,10 @@ 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 { type BinaryDataConfig, BinaryDataService, constructExecutionMetaData } from 'n8n-core'; +import { constructExecutionMetaData } from 'n8n-core'; import type { + ICredentialDataDecryptedObject, IDataObject, IExecuteFunctions, IGetNodeParameterOptions, @@ -36,17 +36,6 @@ export function createTemporaryDir(prefix = 'n8n') { return mkdtempSync(path.join(tmpdir(), prefix)); } -export async function initBinaryDataService() { - const binaryDataConfig = mock({ - mode: 'default', - availableModes: ['default'], - localStoragePath: createTemporaryDir(), - }); - const binaryDataService = new BinaryDataService(binaryDataConfig); - await binaryDataService.init(); - Container.set(BinaryDataService, binaryDataService); -} - export function getResultNodeData(result: IRun, testData: WorkflowTestData) { return Object.keys(testData.output.nodeData).map((nodeName) => { const error = result.data.resultData.error; @@ -127,7 +116,10 @@ const preparePinData = (pinData: IDataObject) => { return returnData; }; -export const workflowToTests = (workflowFiles: string[]) => { +export const workflowToTests = ( + workflowFiles: string[], + credentials?: Record, +) => { const testCases: WorkflowTestData[] = []; for (const filePath of workflowFiles) { const description = filePath.replace('.json', ''); @@ -155,13 +147,16 @@ export const workflowToTests = (workflowFiles: string[]) => { const input = { workflowData }; const output = { nodeData }; - testCases.push({ description, input, output, trigger }); + testCases.push({ description, input, output, trigger, credentials }); } return testCases; }; -export const testWorkflows = (workflows: string[]) => { - const tests = workflowToTests(workflows); +export const testWorkflows = ( + workflows: string[], + credentials?: Record, +) => { + const tests = workflowToTests(workflows, credentials); for (const testData of tests) { test(testData.description, async () => await equalityTest(testData)); diff --git a/packages/nodes-base/test/nodes/credentials-helper.ts b/packages/nodes-base/test/nodes/credentials-helper.ts index 095c5010a3..549c19635b 100644 --- a/packages/nodes-base/test/nodes/credentials-helper.ts +++ b/packages/nodes-base/test/nodes/credentials-helper.ts @@ -3,7 +3,6 @@ import { Credentials } from 'n8n-core'; import { ICredentialsHelper } from 'n8n-workflow'; import type { ICredentialDataDecryptedObject, - IDataObject, IHttpRequestHelper, IHttpRequestOptions, INode, @@ -12,10 +11,15 @@ import type { } from 'n8n-workflow'; import { CredentialTypes } from './credential-types'; -import { FAKE_CREDENTIALS_DATA } from './FakeCredentialsMap'; @Service() export class CredentialsHelper extends ICredentialsHelper { + private credentialsMap: Record = {}; + + setCredentials(credentialsMap: Record) { + this.credentialsMap = credentialsMap; + } + getCredentialsProperties() { return []; } @@ -48,10 +52,10 @@ export class CredentialsHelper extends ICredentialsHelper { async getDecrypted( _additionalData: IWorkflowExecuteAdditionalData, - nodeCredentials: INodeCredentialsDetails, + _nodeCredentials: INodeCredentialsDetails, type: string, ): Promise { - return this.getFakeDecryptedCredentials(nodeCredentials, type); + return this.credentialsMap[type] ?? {}; } async getCredentials( @@ -66,17 +70,4 @@ export class CredentialsHelper extends ICredentialsHelper { _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/tsconfig.json b/packages/nodes-base/tsconfig.json index a300196ce4..81c91734b8 100644 --- a/packages/nodes-base/tsconfig.json +++ b/packages/nodes-base/tsconfig.json @@ -5,6 +5,7 @@ ], "compilerOptions": { "paths": { + "@credentials/*": ["./credentials/*"], "@test/*": ["./test/*"], "@utils/*": ["./utils/*"] }, diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 842626bbe3..dc9cc5530e 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -2457,6 +2457,7 @@ export interface WorkflowTestData { mode: WorkflowExecuteMode; input: INodeExecutionData; }; + credentials?: Record; } export type LogLevel = (typeof LOG_LEVELS)[number];