mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor: Overhaul nodes-testing setup - Part 2 (no-changelog) (#14873)
This commit is contained in:
committed by
GitHub
parent
897338bd24
commit
91069f057e
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
};
|
||||
@@ -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<IHttpRequestOptions> => {
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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<IHttpRequestOptions> => {
|
||||
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=',
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user