Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
import { isMessagePayload, isWebhookBeforeResult } from './hook-results';
describe('hook result checks', () => {
it('accepts a message payload only when it carries both a string id and a string chatId', () => {
expect(isMessagePayload({ id: 'm', chatId: '[email protected]' })).toBe(true);
expect(isMessagePayload({ id: 'm' })).toBe(false);
expect(isMessagePayload({ chatId: '[email protected]' })).toBe(false);
expect(isMessagePayload({ id: 1, chatId: '[email protected]' })).toBe(false);
expect(isMessagePayload({ id: 'm', chatId: 2 })).toBe(false);
expect(isMessagePayload(null)).toBe(false);
expect(isMessagePayload(['m', 'c'])).toBe(false);
expect(isMessagePayload('m')).toBe(false);
});
it('accepts a webhook:before result only when it carries an object payload', () => {
expect(isWebhookBeforeResult({ payload: { a: 1 } })).toBe(true);
expect(isWebhookBeforeResult({ payload: null })).toBe(false);
expect(isWebhookBeforeResult({ payload: [1] })).toBe(false);
expect(isWebhookBeforeResult({})).toBe(false);
expect(isWebhookBeforeResult(null)).toBe(false);
});
});