- Tests caught 2 real bugs:
- Zod NaN bypass in orders/offers schemas (Number(v) || fallback)
- invoiceTotalWithVat using Number() on { toNumber() } objects
- 7 new test files covering auth, env, exchange rates, NAS paths,
schema NaN rejection, invoice VAT calculation, customer validation
- 45 tests passing, build clean
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { CreateOrderSchema } from "../schemas/orders.schema";
|
|
import { CreateQuotationSchema } from "../schemas/offers.schema";
|
|
|
|
describe("Zod NaN rejection", () => {
|
|
describe("CreateOrderSchema", () => {
|
|
it("rejects NaN string in quantity", () => {
|
|
const result = CreateOrderSchema.safeParse({
|
|
customer_id: 1,
|
|
items: [{ quantity: "not-a-number" }],
|
|
});
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
it("rejects NaN string in unit_price", () => {
|
|
const result = CreateOrderSchema.safeParse({
|
|
customer_id: 1,
|
|
items: [{ unit_price: "abc" }],
|
|
});
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
it("accepts valid numbers", () => {
|
|
const result = CreateOrderSchema.safeParse({
|
|
customer_id: 1,
|
|
items: [{ quantity: 2, unit_price: 100 }],
|
|
});
|
|
expect(result.success).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("CreateQuotationSchema", () => {
|
|
it("rejects NaN string in top-level vat_rate", () => {
|
|
const result = CreateQuotationSchema.safeParse({
|
|
customer_id: 1,
|
|
vat_rate: "bad",
|
|
});
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
it("accepts valid vat_rate", () => {
|
|
const result = CreateQuotationSchema.safeParse({
|
|
customer_id: 1,
|
|
vat_rate: 21,
|
|
});
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it("rejects NaN string in item quantity", () => {
|
|
const result = CreateQuotationSchema.safeParse({
|
|
customer_id: 1,
|
|
items: [{ quantity: "bad" }],
|
|
});
|
|
expect(result.success).toBe(false);
|
|
});
|
|
});
|
|
});
|