mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Improve test-webhooks (no-changelog) (#8069)
Remove duplication, improve readability, and expand tests for `TestWebhooks.ts` - in anticipation for storing test webhooks in Redis. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -60,34 +60,6 @@ export const separate = <T>(array: T[], test: (element: T) => boolean) => {
|
||||
return [pass, fail];
|
||||
};
|
||||
|
||||
export const webhookNotFoundErrorMessage = (
|
||||
path: string,
|
||||
httpMethod?: string,
|
||||
webhookMethods?: string[],
|
||||
) => {
|
||||
let webhookPath = path;
|
||||
|
||||
if (httpMethod) {
|
||||
webhookPath = `${httpMethod} ${webhookPath}`;
|
||||
}
|
||||
|
||||
if (webhookMethods?.length && httpMethod) {
|
||||
let methods = '';
|
||||
|
||||
if (webhookMethods.length === 1) {
|
||||
methods = webhookMethods[0];
|
||||
} else {
|
||||
const lastMethod = webhookMethods.pop();
|
||||
|
||||
methods = `${webhookMethods.join(', ')} or ${lastMethod as string}`;
|
||||
}
|
||||
|
||||
return `This webhook is not registered for ${httpMethod} requests. Did you mean to make a ${methods} request?`;
|
||||
} else {
|
||||
return `The requested webhook "${webhookPath}" is not registered.`;
|
||||
}
|
||||
};
|
||||
|
||||
export const toError = (maybeError: unknown) =>
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
maybeError instanceof Error ? maybeError : new Error(`${maybeError}`);
|
||||
|
||||
Reference in New Issue
Block a user