Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(template): document the validation 400 on create and update
Yudhi Armyndharisab4b57118274
diff --git a/src/modules/template/template.controller.spec.ts b/src/modules/template/template.controller.spec.tsindex ab127f895..25ae2d391 100644--- a/src/modules/template/template.controller.spec.ts+++ b/src/modules/template/template.controller.spec.ts@@ -40,6 +40,15 @@ describe('TemplateController', () => {expect(service.update).toHaveBeenCalledWith('s1', 't1', dto);});+ // The global ValidationPipe refuses an invalid body, or one carrying an undeclared field, with a 400.+ it.each(['create', 'update'] as const)('declares the validation 400 on %s', handler => {+ const responses = (Reflect.getMetadata(+ 'swagger/apiResponse',+ Object.getOwnPropertyDescriptor(TemplateController.prototype, handler)?.value as object,+ ) ?? {}) as Record<string, unknown>;+ expect(Object.keys(responses)).toContain('400');+ });+it('delete delegates and resolves void', async () => {service.delete.mockResolvedValue(undefined);await expect(controller.delete('s1', 't1')).resolves.toBeUndefined();diff --git a/src/modules/template/template.controller.ts b/src/modules/template/template.controller.tsindex db64d9b47..addb319ca 100644--- a/src/modules/template/template.controller.ts+++ b/src/modules/template/template.controller.ts@@ -16,6 +16,7 @@ export class TemplateController {@ApiOperation({ summary: 'Create a message template for the session' })@ApiParam({ name: 'sessionId', description: 'Session ID' })@ApiResponse({ status: 201, description: 'Template created', type: TemplateResponseDto })+ @ApiResponse({ status: 400, description: 'Validation failed, or the body carries a field the DTO does not declare.' })@ApiResponse({ status: 404, description: 'Session not found' })@ApiResponse({ status: 409, description: 'A template with that name already exists for the session' })async create(@Param('sessionId') sessionId: string, @Body() dto: CreateTemplateDto): Promise<Template> {@@ -48,6 +49,7 @@ export class TemplateController {@ApiParam({ name: 'sessionId', description: 'Session ID' })@ApiParam({ name: 'id', description: 'Template ID' })@ApiResponse({ status: 200, description: 'Template updated', type: TemplateResponseDto })+ @ApiResponse({ status: 400, description: 'Validation failed, or the body carries a field the DTO does not declare.' })@ApiResponse({ status: 404, description: 'Template not found' })@ApiResponse({ status: 409, description: 'A template with that name already exists for the session' })async update(