f9ef8913ae
First of four PRs replacing the onboarding wizard with the journey flow
(dev_docs/onboarding_migration_plan.md, local). No UI change.
- Move deriveFirstYearDefaults + parseStartMonthDay out of
WelcomeOnboarding into lib/company/first-year-defaults.ts and unit-test
them (11-vs-13-months boundary, UTC month seeding, malformed input).
- Add the missing computeFiscalPeriod unit tests (calendar year, brutet
ar, first year short/extended, EF calendar-year rule, period names,
BFL 3 kap. 6-18 month window errors).
- New shared fetchCompanyLookup() client: the single client path to the
Lens-backed /lookup, typed outcomes (found / not_found / disabled /
error / aborted), never throws. Fixes the 403/404 conflation: the
dispatcher's 404 ("Extension not found") and feature-flag 503
(EXTENSION_DISABLED) now degrade silently instead of rendering as
"company not found"; only the TIC handler's own 404 does.
- Step2CompanyDetails consumes the helper; identical UX otherwise.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { deriveFirstYearDefaults, parseStartMonthDay } from '../first-year-defaults'
|
|
|
|
const NOW = new Date('2026-07-24T12:00:00Z').getTime()
|
|
const MONTH_MS = 1000 * 60 * 60 * 24 * 30.44
|
|
|
|
describe('parseStartMonthDay', () => {
|
|
it('parses a TIC MM-DD into the start month', () => {
|
|
expect(parseStartMonthDay('07-01')).toBe(7)
|
|
expect(parseStartMonthDay('1-15')).toBe(1)
|
|
expect(parseStartMonthDay('12-31')).toBe(12)
|
|
})
|
|
|
|
it('returns null for missing input', () => {
|
|
expect(parseStartMonthDay(null)).toBeNull()
|
|
expect(parseStartMonthDay(undefined)).toBeNull()
|
|
expect(parseStartMonthDay('')).toBeNull()
|
|
})
|
|
|
|
it('returns null for malformed or out-of-range input', () => {
|
|
expect(parseStartMonthDay('July 1')).toBeNull()
|
|
expect(parseStartMonthDay('2026-07-01')).toBeNull()
|
|
expect(parseStartMonthDay('13-01')).toBeNull()
|
|
expect(parseStartMonthDay('0-15')).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('deriveFirstYearDefaults', () => {
|
|
it('pre-checks first year for a company registered 11 months ago', () => {
|
|
const registered = NOW - 11 * MONTH_MS
|
|
const result = deriveFirstYearDefaults(registered, NOW)
|
|
expect(result.isFirstFiscalYear).toBe(true)
|
|
expect(result.firstYearStart).toBeDefined()
|
|
})
|
|
|
|
it('does not pre-check for a company registered 13 months ago', () => {
|
|
const registered = NOW - 13 * MONTH_MS
|
|
expect(deriveFirstYearDefaults(registered, NOW)).toEqual({
|
|
isFirstFiscalYear: false,
|
|
firstYearStart: undefined,
|
|
})
|
|
})
|
|
|
|
it('does not pre-check at exactly 12 months', () => {
|
|
const registered = NOW - 12 * MONTH_MS
|
|
expect(deriveFirstYearDefaults(registered, NOW).isFirstFiscalYear).toBe(false)
|
|
})
|
|
|
|
it('seeds first_year_start as the 1st of the UTC registration month', () => {
|
|
const registered = new Date('2026-03-14T10:00:00Z').getTime()
|
|
const result = deriveFirstYearDefaults(registered, NOW)
|
|
expect(result.isFirstFiscalYear).toBe(true)
|
|
expect(result.firstYearStart).toBe('2026-03-01')
|
|
})
|
|
|
|
it('returns falsy defaults for missing or invalid registration dates', () => {
|
|
const empty = { isFirstFiscalYear: false, firstYearStart: undefined }
|
|
expect(deriveFirstYearDefaults(null, NOW)).toEqual(empty)
|
|
expect(deriveFirstYearDefaults(undefined, NOW)).toEqual(empty)
|
|
expect(deriveFirstYearDefaults(0, NOW)).toEqual(empty)
|
|
expect(deriveFirstYearDefaults(Number.NaN, NOW)).toEqual(empty)
|
|
})
|
|
})
|