198d3092c7
Picking a suggestion under "Tidigare motparter" in Bokför transaktion replaced
the page with "Något gick fel". handleOpenTemplateReview built the review state
from `{ id, name_sv } as BookingTemplate`, so `template.debit_account` was
undefined, reached QuickReviewDialog's required `defaultAccount: string`, and
threw on `accountOverride.startsWith('2')` during the first render.
Typed the dialog's template prop as a narrow ReviewTemplate whose optional
fields are actually optional, so the cast disappears and the compiler owns this
class of bug. Also carries the counterparty's learned accounts and VAT (the
preview showed the category fallback, not what the server books) and decides
"is this a counterparty booking" from the template id rather than the presence
of a line_pattern (single-line templates got an account/VAT editor the
categorize route discards).
Five more page-crashes of the same shape, adversarially verified:
- suppliers/[id] and supplier-invoices/[id] passed the error envelope OBJECT as
a toast description. The Toaster is a sibling of {children} in the ROOT
layout, so that throw escapes both segment error boundaries onto global-error.
- components/reports/views wrote the same object into a useState<string | null>
at 13 sites and rendered it bare.
- components/ui/toaster.tsx now coerces non-renderable values as a choke point.
- skattekonto read data.informationstext.length off Skatteverket's raw JSON,
where the field is not required.
- TicWorkspace read profile.statuses.length off a persisted jsonb blob. 17 of 17
prod rows predate the TIC v2 upgrade (#584) and lack the key, so that
workspace was in the error boundary for every company that had opened it.
Plus hardening: formatCurrency coerces a null currency to SEK (prod has 0 NULL
across 28 416 transactions, so defense not a live bug) and cleanSignatory
returns [] for a missing description.
Verified by rendering the real dialog against a throwaway /sandbox route: the
pre-fix prop shape reproduces the exact error boundary, the fixed one renders
D: 6570 Bankavgifter / K: 1930 Företagskonto and the matching verifikat.
No migrations.
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { swedishToday, formatCurrency } from '../utils'
|
|
|
|
describe('swedishToday', () => {
|
|
it('formats the date as ISO yyyy-MM-dd with a Swedish weekday', () => {
|
|
// 2026-01-01 is a Thursday → "torsdag". Noon UTC keeps us clear of any
|
|
// midnight boundary so the assertion is timezone-stable.
|
|
expect(swedishToday(new Date('2026-01-01T12:00:00Z'))).toBe('2026-01-01 (torsdag)')
|
|
})
|
|
|
|
it('reports the date in Europe/Stockholm, not UTC', () => {
|
|
// 23:30 UTC on 2026-05-26 is already 01:30 on 2026-05-27 in Stockholm
|
|
// (CEST, UTC+2). A naive UTC date would read the day before: the off-by-one
|
|
// we explicitly format around for users near midnight.
|
|
expect(swedishToday(new Date('2026-05-26T23:30:00Z'))).toBe('2026-05-27 (onsdag)')
|
|
})
|
|
|
|
it('omits clock time so the cached prompt prefix stays stable across a day', () => {
|
|
const morning = swedishToday(new Date('2026-05-27T06:00:00Z'))
|
|
const evening = swedishToday(new Date('2026-05-27T18:00:00Z'))
|
|
expect(morning).toBe(evening)
|
|
expect(morning).not.toMatch(/\d{2}:\d{2}/)
|
|
})
|
|
})
|
|
|
|
describe('formatCurrency', () => {
|
|
it('falls back to SEK for a NULL currency instead of throwing', () => {
|
|
// transactions.currency is nullable and NULL is legacy for the 'SEK'
|
|
// column default (migration 20260726100000), but the Transaction type
|
|
// declares it required. Intl throws RangeError on `currency: null`, and
|
|
// one such row used to blank the whole transactions list.
|
|
expect(() => formatCurrency(1234.5, null)).not.toThrow()
|
|
expect(formatCurrency(1234.5, null)).toBe(formatCurrency(1234.5, 'SEK'))
|
|
})
|
|
|
|
it('falls back to SEK for undefined and for an empty string', () => {
|
|
expect(formatCurrency(10, undefined)).toBe(formatCurrency(10, 'SEK'))
|
|
expect(formatCurrency(10, '')).toBe(formatCurrency(10, 'SEK'))
|
|
expect(formatCurrency(10)).toBe(formatCurrency(10, 'SEK'))
|
|
})
|
|
|
|
it('still honours a real currency code', () => {
|
|
expect(formatCurrency(10, 'EUR')).toContain('€')
|
|
})
|
|
})
|