refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-04-01 10:15:13 +02:00
committed by GitHub
parent f85b851851
commit 73e8d76e13
165 changed files with 3397 additions and 6453 deletions

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_create.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should create blob', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -66,7 +55,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_delete.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should delete blob', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -35,7 +24,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_get.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get blob', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -87,7 +76,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/blob_getAll.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get all blobs', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -36,7 +25,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,6 +1,4 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = [
@@ -8,16 +6,7 @@ describe('Azure Storage Node', () => {
];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get all blobs with limit and options', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -31,7 +20,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/container_create.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should create container', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -38,7 +27,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/container_delete.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should delete container', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -35,7 +24,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/container_get.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get container', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -44,7 +33,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,21 +1,10 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/container_getAll.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get all containers', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -36,7 +25,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,6 +1,4 @@
import nock from 'nock';
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = [
@@ -8,16 +6,7 @@ describe('Azure Storage Node', () => {
];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should get all containers with limit and options', () => {
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -31,7 +20,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -3,25 +3,16 @@ import type {
IDataObject,
IHttpRequestOptions,
} from 'n8n-workflow';
import nock from 'nock';
import { CredentialsHelper, equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { CredentialsHelper } from '@test/nodes/credentials-helper';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
describe('Azure Storage Node', () => {
const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_oauth2.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should use correct oauth2 credentials', () => {
beforeAll(() => {
nock.disableNetConnect();
jest
.spyOn(CredentialsHelper.prototype, 'authenticate')
.mockImplementation(
@@ -45,12 +36,9 @@ describe('Azure Storage Node', () => {
});
afterAll(() => {
nock.restore();
jest.restoreAllMocks();
});
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
@@ -59,7 +47,6 @@ describe('Azure Storage Node', () => {
method: 'get',
path: '/mycontainer?restype=container',
statusCode: 200,
requestHeaders: { authorization: 'bearer ACCESSTOKEN' },
responseBody: '',
responseHeaders: {
'content-length': '0',
@@ -80,7 +67,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
});

View File

@@ -1,26 +1,18 @@
import type { ICredentialDataDecryptedObject, IHttpRequestOptions } from 'n8n-workflow';
import nock from 'nock';
import { CredentialsHelper, equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
import { CredentialsHelper } from '@test/nodes/credentials-helper';
import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap';
import { equalityTest, workflowToTests } from '@test/nodes/Helpers';
import { AzureStorageSharedKeyApi } from '../../../../../credentials/AzureStorageSharedKeyApi.credentials';
import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap';
describe('Azure Storage Node', () => {
const { account, baseUrl, key } = FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi;
const workflows = ['nodes/Microsoft/Storage/test/workflows/credentials_sharedKey.workflow.json'];
const workflowTests = workflowToTests(workflows);
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('should use correct shared key credentials', () => {
beforeAll(() => {
nock.disableNetConnect();
jest
.spyOn(CredentialsHelper.prototype, 'authenticate')
.mockImplementation(
@@ -45,24 +37,17 @@ describe('Azure Storage Node', () => {
});
afterAll(() => {
nock.restore();
jest.restoreAllMocks();
});
const nodeTypes = setup(workflowTests);
for (const workflow of workflowTests) {
workflow.nock = {
baseUrl: 'https://myaccount.blob.core.windows.net',
baseUrl,
mocks: [
{
method: 'get',
path: '/mycontainer?restype=container',
statusCode: 200,
requestHeaders: {
authorization:
'SharedKey Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',
},
responseBody: '',
responseHeaders: {
'content-length': '0',
@@ -83,7 +68,7 @@ describe('Azure Storage Node', () => {
},
],
};
test(workflow.description, async () => await equalityTest(workflow, nodeTypes));
test(workflow.description, async () => await equalityTest(workflow));
}
});
@@ -92,11 +77,11 @@ describe('Azure Storage Node', () => {
it('should remove undefined query parameters and headers', async () => {
const credentials: ICredentialDataDecryptedObject = {
account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account,
key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key,
account,
key,
};
const requestOptions: IHttpRequestOptions = {
url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer`,
url: `${baseUrl}/mycontainer`,
qs: { restype: 'container', query1: undefined },
headers: {
'Content-Length': undefined,
@@ -112,11 +97,11 @@ describe('Azure Storage Node', () => {
it('should default method to GET if not provided', async () => {
const credentials: ICredentialDataDecryptedObject = {
account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account,
key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key,
account,
key,
};
const requestOptions: IHttpRequestOptions = {
url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer`,
url: `${baseUrl}/mycontainer`,
qs: { restype: 'container' },
headers: {
'Content-Length': undefined,
@@ -129,11 +114,11 @@ describe('Azure Storage Node', () => {
it('should generate a valid authorization header', async () => {
const credentials: ICredentialDataDecryptedObject = {
account: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.account,
key: FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.key,
account,
key,
};
const requestOptions: IHttpRequestOptions = {
url: `${FAKE_CREDENTIALS_DATA.azureStorageSharedKeyApi.baseUrl}/mycontainer/myblob`,
url: `${baseUrl}/mycontainer/myblob`,
qs: { param1: 'value1' },
headers: {
'x-ms-date': 'Thu, 27 Feb 2025 11:05:49 GMT',

View File

@@ -1,18 +1,11 @@
import type { ILoadOptionsFunctions, INodeParameterResourceLocator } from 'n8n-workflow';
import nock from 'nock';
import { FAKE_CREDENTIALS_DATA } from '../../../../../test/nodes/FakeCredentialsMap';
import { FAKE_CREDENTIALS_DATA } from '@test/nodes/FakeCredentialsMap';
import { AzureStorage } from '../../AzureStorage.node';
import { XMsVersion } from '../../GenericFunctions';
describe('Azure Storage Node', () => {
beforeEach(() => {
// https://github.com/nock/nock/issues/2057#issuecomment-663665683
if (!nock.isActive()) {
nock.activate();
}
});
describe('List search', () => {
it('should list search blobs', async () => {
const mockResponse =