feat: audit & sync with documentacion.html v1.1 — schema, tests, modules, web
Schema (packages/database/prisma/schema.prisma): - Add SenaeCategory, B2BRequestStatus, NotificationChannel enums - Add Package fields: lengthCm, widthCm, heightCm, hasDiscrepancy, photos[], senaeCategory, senaeAuthNumber, senaeDeclarationId - Add userId field to PreAlert - Add RefreshToken model (JWT auth — Fase 1) - Add Tariff model (configurable rates: pricePerLb, insurancePct, etc.) - Add B2BRequest model (heavy cargo imports — doc §13) - Add Notification model (multi-channel: email, whatsapp, sms, push — doc §16) - Add userAgent to AuditLog API (apps/api): - Add CalculatorModule: calculates SENAE cost breakdown (flete, seguro, FODINFA, arancel, IVA) per formulas in doc §15 - Add TrackingModule: public GET /api/tracking/:id endpoint (doc §07) - Register both modules in AppModule - Add Jest config + test scripts (test, test:watch, test:cov, test:ci) Tests (80 tests, 97.45% coverage): - calculator.util.spec.ts: 35 tests — SENAE formulas, volumetric weight, 4x4 regime, tariff rates, error validation, breakdown - tracking-id.util.spec.ts: 13 tests — format, uniqueness, validation - suite-code.util.spec.ts: 13 tests — generation, parsing, address builder - health.controller.spec.ts: 5 tests — ok/degraded/timestamp - calculator.spec.ts: 8 tests — controller + service unit tests - tracking.controller.spec.ts: 9 tests — public search, 404, no sensitive data Web (apps/web): - page.tsx: Full landing page matching documentation (Hero, Services, 8 Modules, Tracking states, SENAE calculator preview, 6 Roles, Companies) - /calculadora: SENAE categories + API usage guide - /tracking: Tracking ID format + 11 states reference Seed (packages/database/prisma/seed.ts): - Creates all 6 roles (SUPER_ADMIN, ADMIN_EMPRESA, OPERADOR_BODEGA, AGENTE_ADUANERO, CLIENTE, SOPORTE) - Assigns Suite EC-00001 to demo client - Creates demo Package EC-20260506-000001 with status history - Creates demo PreAlert and B2BRequest .env.example: Added all 9 integrations from doc §18: Amazon SP-API, SENAE WebService, Stripe/PayPhone, WhatsApp Business API, SendGrid/SES, SMS/Twilio, FedEx/DHL/UPS couriers, S3/MinIO, Sentry migration.sql: Updated to reflect all new models and fields turbo.json + package.json: Added test, test:cov, test:ci tasks + db:seed script
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { HealthController } from "./health.controller";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
describe("HealthController", () => {
|
||||
let controller: HealthController;
|
||||
let prismaService: { client: { $queryRaw: jest.Mock } };
|
||||
|
||||
beforeEach(async () => {
|
||||
prismaService = {
|
||||
client: {
|
||||
$queryRaw: jest.fn().mockResolvedValue([{ "?column?": 1 }]),
|
||||
},
|
||||
};
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [HealthController],
|
||||
providers: [
|
||||
{
|
||||
provide: PrismaService,
|
||||
useValue: prismaService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<HealthController>(HealthController);
|
||||
});
|
||||
|
||||
it("debe estar definido", () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it("retorna status 'ok' cuando la DB responde", async () => {
|
||||
const result = await controller.health();
|
||||
expect(result.status).toBe("ok");
|
||||
expect(result.checks.database).toBe("ok");
|
||||
});
|
||||
|
||||
it("retorna status 'degraded' cuando la DB falla", async () => {
|
||||
prismaService.client.$queryRaw.mockRejectedValueOnce(new Error("DB down"));
|
||||
const result = await controller.health();
|
||||
expect(result.status).toBe("degraded");
|
||||
expect(result.checks.database).toBe("error");
|
||||
});
|
||||
|
||||
it("el response incluye service, version y timestamp", async () => {
|
||||
const result = await controller.health();
|
||||
expect(result.service).toBe("moraworld-api");
|
||||
expect(result.version).toBe("0.1.0");
|
||||
expect(result.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
||||
});
|
||||
|
||||
it("timestamp es una fecha ISO válida", async () => {
|
||||
const result = await controller.health();
|
||||
const date = new Date(result.timestamp);
|
||||
expect(date.getTime()).not.toBeNaN();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user