From f5f05a57371a241b9113682803a9552a1870078e Mon Sep 17 00:00:00 2001 From: Leandro Moraes Date: Tue, 19 May 2026 08:17:29 -0300 Subject: [PATCH 1/2] fix: exclude vitest.config.ts from production build tsconfig.build.json was including the root-level vitest.config.ts, causing TypeScript to infer rootDir as '.' instead of 'src'. This nested all compiled output under dist/src/ instead of dist/, so the container could not find dist/main at startup. --- tsconfig.build.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"] } From 82c7f3d644db2a1a76605c85d0e7e5167059a281 Mon Sep 17 00:00:00 2001 From: Leandro Moraes Date: Tue, 19 May 2026 08:26:25 -0300 Subject: [PATCH 2/2] fix: add upper bound validation for amount field Without a max constraint, values above PostgreSQL's integer limit (2,147,483,647) passed Zod validation but crashed at the DB layer with a 500. Now returns 400 at the validation boundary. --- src/modules/charges/application/dto/create-charge.dto.ts | 2 +- test/e2e/charges.controller.e2e-spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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')