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:
Iván Ovejero
2023-12-19 17:32:02 +01:00
committed by GitHub
parent 38d1336fa7
commit 9dc491c3a5
14 changed files with 486 additions and 416 deletions

View File

@@ -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}`);