mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)
This commit is contained in:
committed by
GitHub
parent
f85b851851
commit
73e8d76e13
82
packages/nodes-base/test/nodes/credentials-helper.ts
Normal file
82
packages/nodes-base/test/nodes/credentials-helper.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { Container, Service } from '@n8n/di';
|
||||
import { Credentials } from 'n8n-core';
|
||||
import { ICredentialsHelper } from 'n8n-workflow';
|
||||
import type {
|
||||
ICredentialDataDecryptedObject,
|
||||
IDataObject,
|
||||
IHttpRequestHelper,
|
||||
IHttpRequestOptions,
|
||||
INode,
|
||||
INodeCredentialsDetails,
|
||||
IWorkflowExecuteAdditionalData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { CredentialTypes } from './credential-types';
|
||||
import { FAKE_CREDENTIALS_DATA } from './FakeCredentialsMap';
|
||||
|
||||
@Service()
|
||||
export class CredentialsHelper extends ICredentialsHelper {
|
||||
getCredentialsProperties() {
|
||||
return [];
|
||||
}
|
||||
|
||||
async authenticate(
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
typeName: string,
|
||||
requestParams: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
const credentialType = Container.get(CredentialTypes).getByName(typeName);
|
||||
if (typeof credentialType.authenticate === 'function') {
|
||||
return await credentialType.authenticate(credentials, requestParams);
|
||||
}
|
||||
return requestParams;
|
||||
}
|
||||
|
||||
async preAuthentication(
|
||||
_helpers: IHttpRequestHelper,
|
||||
_credentials: ICredentialDataDecryptedObject,
|
||||
_typeName: string,
|
||||
_node: INode,
|
||||
_credentialsExpired: boolean,
|
||||
): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getParentTypes(_name: string): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
async getDecrypted(
|
||||
_additionalData: IWorkflowExecuteAdditionalData,
|
||||
nodeCredentials: INodeCredentialsDetails,
|
||||
type: string,
|
||||
): Promise<ICredentialDataDecryptedObject> {
|
||||
return this.getFakeDecryptedCredentials(nodeCredentials, type);
|
||||
}
|
||||
|
||||
async getCredentials(
|
||||
_nodeCredentials: INodeCredentialsDetails,
|
||||
_type: string,
|
||||
): Promise<Credentials> {
|
||||
return new Credentials({ id: null, name: '' }, '', '');
|
||||
}
|
||||
|
||||
async updateCredentials(
|
||||
_nodeCredentials: INodeCredentialsDetails,
|
||||
_type: string,
|
||||
_data: ICredentialDataDecryptedObject,
|
||||
): Promise<void> {}
|
||||
|
||||
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 {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user