fix(Discourse Node): Fix issue with not all posts getting returned and add credential test (#3007)

* 🔨 fix for not all posts returning

*  added credential test

*  Improvements

*  Improvements

*  Define test the new way

*  Remove not needed imports

*  Fix auth test problem

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
Co-authored-by: Ricardo Espinoza <ricardo@n8n.io>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Michael Kret
2022-04-18 20:31:59 +03:00
committed by GitHub
parent a9653c20ef
commit d68b7a4cf4
5 changed files with 57 additions and 20 deletions

View File

@@ -9,18 +9,14 @@ import {
} from 'n8n-core';
import {
IDataObject, NodeApiError,
IDataObject, JsonObject, NodeApiError,
} from 'n8n-workflow';
export async function discourseApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = await this.getCredentials('discourseApi');
const credentials = await this.getCredentials('discourseApi') as { url: string };
const options: OptionsWithUri = {
headers: {
'Api-Key': credentials.apiKey,
'Api-Username': credentials.username,
},
method,
body,
qs,
@@ -32,10 +28,9 @@ export async function discourseApiRequest(this: IExecuteFunctions | IExecuteSing
if (Object.keys(body).length === 0) {
delete options.body;
}
//@ts-ignore
return await this.helpers.request.call(this, options);
return await this.helpers.requestWithAuthentication.call(this, 'discourseApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}