37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
// The invoice terms accept exactly what the Invoicing service accepts: its `DecimalAmount` grammar and ISO 4217
|
|
// codes (business-services/types). The module's own regex let `007.50` and `XYZ` through, which the service then
|
|
// refused; a person found out only after submitting.
|
|
import { describe, expect, it } from "vitest"
|
|
import { decimal, line, money } from "../contract/index.js"
|
|
|
|
describe("the invoice's exact money", () => {
|
|
it("refuses an amount with a leading zero and a currency the service does not know", () => {
|
|
for (const amount of ["007.50", "00", "-01", "1.", ".5", "+1", "1e3", "1,50"]) {
|
|
expect(decimal.safeParse(amount).success, amount).toBe(false)
|
|
}
|
|
expect(money.safeParse({ amount: "7.50", currency: "XYZ" }).success).toBe(false)
|
|
expect(money.safeParse({ amount: "7.50", currency: "LTL" }).success).toBe(false)
|
|
})
|
|
|
|
it("takes a line's unit only as a UN/CEFACT Rec 20 code the service accepts", () => {
|
|
const base = {
|
|
quantity: "3",
|
|
item_name: "Bolt",
|
|
net_price: { amount: "1.20", currency: "EUR" },
|
|
vat_category: "S",
|
|
vat_rate: "21",
|
|
}
|
|
expect(line.safeParse({ ...base, unit: "C62" }).success).toBe(true)
|
|
for (const unit of ["pcs", "PCS", "XBX", "m2"]) expect(line.safeParse({ ...base, unit }).success, unit).toBe(false)
|
|
})
|
|
|
|
it("accepts every amount the service accepts, trailing zeros and its bounds included", () => {
|
|
for (const amount of ["0", "-0.00", "7.50", "9999999999999999999999999999.999999999999999999"]) {
|
|
expect(decimal.safeParse(amount).success, amount).toBe(true)
|
|
}
|
|
expect(decimal.safeParse("10000000000000000000000000000").success).toBe(false)
|
|
expect(money.safeParse({ amount: "7.50", currency: "EUR" }).success).toBe(true)
|
|
})
|
|
})
|