diff --git a/src/modules/charges/application/dto/create-charge.dto.ts b/src/modules/charges/application/dto/create-charge.dto.ts index 050a06b..1a82f10 100644 --- a/src/modules/charges/application/dto/create-charge.dto.ts +++ b/src/modules/charges/application/dto/create-charge.dto.ts @@ -2,7 +2,7 @@ import { createZodDto } from 'nestjs-zod'; import { z } from 'zod'; const CreateChargeSchema = z.object({ - amount: z.number().int().min(1), + amount: z.number().int().min(1).max(2147483647), currency: z.string().length(3), payer_document: z.string().regex(/^\d{11}$/, 'payer_document must be an 11-digit CPF'), description: z.string().optional(), diff --git a/test/e2e/charges.controller.e2e-spec.ts b/test/e2e/charges.controller.e2e-spec.ts index 62472f9..f3091b5 100644 --- a/test/e2e/charges.controller.e2e-spec.ts +++ b/test/e2e/charges.controller.e2e-spec.ts @@ -105,6 +105,15 @@ describe('ChargesController (e2e)', () => { expect(res.status).toBe(400); }); + it('retorna 400 quando amount excede o limite inteiro (validação Zod)', async () => { + const res = await request(app.getHttpServer()) + .post('/charges') + .set('Idempotency-Key', uuidv4()) + .send({ ...validBody, amount: 2147483648 }); + + expect(res.status).toBe(400); + }); + it('retorna 400 quando currency está ausente (validação Zod)', async () => { const res = await request(app.getHttpServer()) .post('/charges') diff --git a/tsconfig.build.json b/tsconfig.build.json index 64f86c6..69c66fc 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] + "exclude": ["node_modules", "test", "dist", "**/*spec.ts", "vitest.config.ts"] }