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

@@ -1,32 +1,44 @@
import { webhookNotFoundErrorMessage } from '@/utils';
import { webhookNotFoundErrorMessage } from '@/errors/response-errors/webhook-not-found.error';
describe('utils test webhookNotFoundErrorMessage ', () => {
it('should return a message with path and method', () => {
const message = webhookNotFoundErrorMessage('webhook12345', 'GET');
const message = webhookNotFoundErrorMessage({ path: 'webhook12345', httpMethod: 'GET' });
expect(message).toEqual('The requested webhook "GET webhook12345" is not registered.');
});
it('should return a message with path', () => {
const message = webhookNotFoundErrorMessage('webhook12345');
const message = webhookNotFoundErrorMessage({ path: 'webhook12345' });
expect(message).toEqual('The requested webhook "webhook12345" is not registered.');
});
it('should return a message with method with tip', () => {
const message = webhookNotFoundErrorMessage('webhook12345', 'POST', ['GET', 'PUT']);
const message = webhookNotFoundErrorMessage({
path: 'webhook12345',
httpMethod: 'POST',
webhookMethods: ['GET', 'PUT'],
});
expect(message).toEqual(
'This webhook is not registered for POST requests. Did you mean to make a GET or PUT request?',
);
});
it('should return a message with method with tip', () => {
const message = webhookNotFoundErrorMessage('webhook12345', 'POST', ['PUT']);
const message = webhookNotFoundErrorMessage({
path: 'webhook12345',
httpMethod: 'POST',
webhookMethods: ['PUT'],
});
expect(message).toEqual(
'This webhook is not registered for POST requests. Did you mean to make a PUT request?',
);
});
it('should return a message with method with tip', () => {
const message = webhookNotFoundErrorMessage('webhook12345', 'POST', ['GET', 'PUT', 'DELETE']);
const message = webhookNotFoundErrorMessage({
path: 'webhook12345',
httpMethod: 'POST',
webhookMethods: ['GET', 'PUT', 'DELETE'],
});
expect(message).toEqual(
'This webhook is not registered for POST requests. Did you mean to make a GET, PUT or DELETE request?',