mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
feat(Magento 2 Node): Add credential tests (#3086)
* Implements Magento Auth API Test * Deletes unit tests * Fixed lint issues and changed the URI for the credential test * ⚡ Move credential verification to the credential file * ⚡ Simplify code Co-authored-by: paolo-rechia <paolo@e-bot7.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
c7a037e9fe
commit
a11b00a037
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
IAuthenticateBearer,
|
||||||
|
ICredentialTestRequest,
|
||||||
ICredentialType,
|
ICredentialType,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
@ -21,4 +23,15 @@ export class Magento2Api implements ICredentialType {
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: '={{$credentials.host}}',
|
||||||
|
url: '/rest/default/V1/modules',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
authenticate = {
|
||||||
|
type: 'bearer',
|
||||||
|
properties: {},
|
||||||
|
} as IAuthenticateBearer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,6 @@ export async function magentoApiRequest(this: IWebhookFunctions | IHookFunctions
|
||||||
const credentials = await this.getCredentials('magento2Api') as IDataObject;
|
const credentials = await this.getCredentials('magento2Api') as IDataObject;
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${credentials.accessToken}`,
|
|
||||||
},
|
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs,
|
qs,
|
||||||
|
@ -45,7 +41,7 @@ export async function magentoApiRequest(this: IWebhookFunctions | IHookFunctions
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return await this.helpers.request.call(this, options);
|
return await this.helpers.requestWithAuthentication.call(this, 'magento2Api', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error);
|
throw new NodeApiError(this.getNode(), error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ICredentialsDecrypted,
|
||||||
|
ICredentialTestFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
|
INodeCredentialTestResult,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
INodeType,
|
INodeType,
|
||||||
|
|
Loading…
Reference in a new issue