Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): type-check media base64 even when a url is present
Yudhi Armyndharisa549d8360a5d
diff --git a/src/modules/message/dto/send-message.dto.spec.ts b/src/modules/message/dto/send-message.dto.spec.tsindex 7e78d1c86..48680155b 100644--- a/src/modules/message/dto/send-message.dto.spec.ts+++ b/src/modules/message/dto/send-message.dto.spec.ts@@ -254,3 +254,17 @@ describe('SendMediaMessageDto url', () => {expect(errors.map(e => e.property)).toContain('url');});});++describe('SendMediaMessageDto base64', () => {+ // A url next to it must not switch the type check off: buildMediaInput reads base64 first, so a+ // non-string there reached the engine whatever the url said.+ it('rejects a non-string base64 even when a url is present', async () => {+ const errors = await validateDto(SendMediaMessageDto, {+ chatId: '[email protected]',+ url: 'https://example.com/a.jpg',+ base64: ['x'],+ mimetype: 'image/jpeg',+ });+ expect(errors.map(e => e.property)).toContain('base64');+ });+});diff --git a/src/modules/message/dto/send-message.dto.ts b/src/modules/message/dto/send-message.dto.tsindex a3e52ff2c..00a3c4e8d 100644--- a/src/modules/message/dto/send-message.dto.ts+++ b/src/modules/message/dto/send-message.dto.ts@@ -5,7 +5,6 @@ import {IsNotEmpty,IsOptional,MaxLength,- ValidateIf,IsArray,ArrayMaxSize,IsBoolean,@@ -204,7 +203,6 @@ export class SendMediaMessageDto {})@IsOptional()@IsString()- @ValidateIf((o: SendMediaMessageDto) => !o.url)base64?: string;@ApiPropertyOptional({