fix(invoices): accept empty self-billing fields on invoice create (#920)
#911 added self-billing fields to the shared CreateInvoiceSchema with external_invoice_number: z.string().min(1), but the invoice form has always sent that field (plus self_billing_agreement_ref and received_date) as '' on every normal invoice. The empty string failed min(1), so every invoice create returned 400. Normalise the empty optional self-billing strings to undefined in the schema (matching the existing optionalIsoDate / deduction_brf_org_number patterns), and strip the unused empty carriers client-side before the form POSTs. Required-when-self-billed is still enforced post-parse in the v1 route, so the self-billed path is unaffected. Adds schema regression tests. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
27b88426e2
commit
cbffcd7292
@@ -384,6 +384,37 @@ describe('CreateInvoiceSchema', () => {
|
||||
}))
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
// Regression: the dashboard invoice form always sends the self-billing fields
|
||||
// (default '' for a normal invoice). Empty strings must read as "not
|
||||
// provided", not fail min(1)/isoDate, or every regular invoice create 400s.
|
||||
it('treats empty self-billing strings as omitted (not a validation error)', () => {
|
||||
const result = CreateInvoiceSchema.safeParse(validInvoice({
|
||||
external_invoice_number: '',
|
||||
self_billing_agreement_ref: '',
|
||||
received_date: '',
|
||||
}))
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.external_invoice_number).toBeUndefined()
|
||||
expect(result.data.self_billing_agreement_ref).toBeUndefined()
|
||||
expect(result.data.received_date).toBeUndefined()
|
||||
}
|
||||
})
|
||||
|
||||
it('still accepts real self-billing values', () => {
|
||||
const result = CreateInvoiceSchema.safeParse(validInvoice({
|
||||
is_self_billed: true,
|
||||
external_invoice_number: 'CUST-2026-014',
|
||||
self_billing_agreement_ref: 'AVTAL-7',
|
||||
received_date: '2026-07-07',
|
||||
}))
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.external_invoice_number).toBe('CUST-2026-014')
|
||||
expect(result.data.received_date).toBe('2026-07-07')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('UpdateInvoiceSchema', () => {
|
||||
|
||||
Reference in New Issue
Block a user