* feat(onboarding): minimal input: orgnr + moms period is the whole ask
Two fixes from the third E2E attempt (2026-08-26):
1. accounting_method is now optional in CompanySetupSchema and defaults by
form in planCompanySetup: aktiebolag = accrual (the norm), enskild
firma = cash (the common small-EF choice; legal under 3 MSEK, BFL 4
kap 4 paragraf). The plan flags the default (resolved.accountingMethodDefaulted)
and gnubok_create_company's preview carries accounting_method_defaulted
so the readback names it and the user overrides in the same 'ja'.
Never silent: the preview is the checkpoint. Applies to the MCP tool
and POST /api/v1/companies (additive; response shows the resolved
value). The lookup tool's still_to_ask no longer lists it.
2. The agent refused a real orgnr because the user said 'nytt bolag' and
the registry showed an established company ('Stopp. Numret matchar
inte ett nytt bolag'): lookup instructions now state that an
established company with F-skatt/VAT is the NORMAL case (new = new to
Accounted) and the orgnr is never second-guessed for looking
established.
Skill + plugin (v1.2.1) updated; API skill regenerated; DECISIONS.md entry.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(onboarding): surface the kontantmetod 3-MSEK condition on the defaulted cash method
Compliance-review finding on #1952: the EF cash default carries a legal
eligibility condition (turnover normally under 3 MSEK, BFL 4 kap 4 §)
that a client not reading the onboarding skill would never see. The
create preview now carries accounting_method_note with the condition
whenever cash was defaulted, and the v1 pitfall states it for API
integrators. The registry cannot verify turnover, so the confirm-time
human check is the gate; the default itself stays (a brand-new EF has
zero turnover by definition).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
201 lines
7.3 KiB
TypeScript
201 lines
7.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { CompanySetupSchema, planCompanySetup } from '../onboarding-input'
|
|
|
|
const base = {
|
|
name: 'Testbolaget AB',
|
|
entity_type: 'aktiebolag' as const,
|
|
org_number: '5560000001',
|
|
vat_registered: true,
|
|
moms_period: 'quarterly' as const,
|
|
accounting_method: 'accrual' as const,
|
|
f_skatt: true,
|
|
}
|
|
|
|
describe('CompanySetupSchema', () => {
|
|
it('accepts a complete aktiebolag setup', () => {
|
|
expect(CompanySetupSchema.safeParse(base).success).toBe(true)
|
|
})
|
|
|
|
it('refuses a VAT-registered company without a moms_period (silent zero-deadline trap)', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, moms_period: undefined })
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.issues.some((i) => i.path.join('.') === 'moms_period')).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('refuses a moms_period on a company that is not VAT-registered', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, vat_registered: false })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it('accepts a non-VAT company with no moms_period', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, vat_registered: false, moms_period: undefined })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('defaults an omitted accounting_method by form and flags it in the plan', () => {
|
|
// Minimal-input decision 2026-08-26: orgnr + moms period is the whole ask.
|
|
const ab = CompanySetupSchema.safeParse({ ...base, accounting_method: undefined })
|
|
expect(ab.success).toBe(true)
|
|
if (ab.success) {
|
|
const plan = planCompanySetup(ab.data)
|
|
expect(plan.ok).toBe(true)
|
|
if (plan.ok) {
|
|
expect(plan.resolved).toEqual({ accountingMethod: 'accrual', accountingMethodDefaulted: true })
|
|
expect(plan.input.settings.accounting_method).toBe('accrual')
|
|
}
|
|
}
|
|
|
|
const ef = CompanySetupSchema.safeParse({
|
|
...base,
|
|
entity_type: 'enskild_firma',
|
|
accounting_method: undefined,
|
|
})
|
|
expect(ef.success).toBe(true)
|
|
if (ef.success) {
|
|
const plan = planCompanySetup(ef.data)
|
|
expect(plan.ok && plan.resolved.accountingMethod).toBe('cash')
|
|
}
|
|
})
|
|
|
|
it('an explicit accounting_method always wins over the form default', () => {
|
|
const parsed = CompanySetupSchema.safeParse({ ...base, accounting_method: 'cash' })
|
|
expect(parsed.success).toBe(true)
|
|
if (parsed.success) {
|
|
const plan = planCompanySetup(parsed.data)
|
|
expect(plan.ok && plan.resolved.accountingMethod).toBe('cash')
|
|
expect(plan.ok && plan.resolved.accountingMethodDefaulted).toBe(false)
|
|
}
|
|
})
|
|
|
|
it('refuses a VAT-registered company without an org number (invoice momsregistreringsnummer)', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, org_number: undefined })
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.issues.some((i) => i.path.join('.') === 'org_number')).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('accepts a non-VAT company without an org number', () => {
|
|
const result = CompanySetupSchema.safeParse({
|
|
...base,
|
|
org_number: undefined,
|
|
vat_registered: false,
|
|
moms_period: undefined,
|
|
})
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('refuses an omitted f_skatt: F-skatt approval is never assumed', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, f_skatt: undefined })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it('refuses an enskild firma first fiscal year that does not end on 31 December', () => {
|
|
const result = CompanySetupSchema.safeParse({
|
|
...base,
|
|
entity_type: 'enskild_firma',
|
|
first_fiscal_year: { start: '2026-03-15', end: '2027-06-30' },
|
|
})
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.issues.some((i) => i.path.join('.') === 'first_fiscal_year.end')).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('refuses a malformed organisationsnummer', () => {
|
|
const result = CompanySetupSchema.safeParse({ ...base, org_number: '1234' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('planCompanySetup', () => {
|
|
it('produces the wizard-shaped settings and a calendar-year period by default', () => {
|
|
const plan = planCompanySetup(CompanySetupSchema.parse(base))
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
const year = new Date().getFullYear()
|
|
expect(plan.fiscalPeriod.startDate).toBe(`${year}-01-01`)
|
|
expect(plan.fiscalPeriod.endDate).toBe(`${year}-12-31`)
|
|
expect(plan.input.settings).toMatchObject({
|
|
entity_type: 'aktiebolag',
|
|
company_name: 'Testbolaget AB',
|
|
org_number: '5560000001',
|
|
vat_registered: true,
|
|
vat_number: 'SE556000000101',
|
|
moms_period: 'quarterly',
|
|
accounting_method: 'accrual',
|
|
f_skatt: true,
|
|
fiscal_year_start_month: 1,
|
|
is_first_fiscal_year: false,
|
|
})
|
|
})
|
|
|
|
it('forces enskild firma onto the calendar year regardless of the requested start month', () => {
|
|
const plan = planCompanySetup(
|
|
CompanySetupSchema.parse({ ...base, entity_type: 'enskild_firma', fiscal_year_start_month: 7 })
|
|
)
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
expect(plan.input.settings.fiscal_year_start_month).toBe(1)
|
|
expect(plan.fiscalPeriod.startDate.endsWith('-01-01')).toBe(true)
|
|
})
|
|
|
|
it('uses the first fiscal year dates and derives the start month from its end', () => {
|
|
const plan = planCompanySetup(
|
|
CompanySetupSchema.parse({
|
|
...base,
|
|
first_fiscal_year: { start: '2026-03-15', end: '2027-06-30' },
|
|
})
|
|
)
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
expect(plan.fiscalPeriod).toMatchObject({ startDate: '2026-03-15', endDate: '2027-06-30' })
|
|
expect(plan.fiscalPeriod.name).toContain('Första räkenskapsåret')
|
|
expect(plan.input.settings.fiscal_year_start_month).toBe(7)
|
|
expect(plan.input.settings.is_first_fiscal_year).toBe(true)
|
|
})
|
|
|
|
it('keeps an enskild firma on the calendar year through a first fiscal year ending 31 December', () => {
|
|
const plan = planCompanySetup(
|
|
CompanySetupSchema.parse({
|
|
...base,
|
|
entity_type: 'enskild_firma',
|
|
first_fiscal_year: { start: '2026-03-15', end: '2026-12-31' },
|
|
})
|
|
)
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
expect(plan.fiscalPeriod).toMatchObject({ startDate: '2026-03-15', endDate: '2026-12-31' })
|
|
expect(plan.input.settings.fiscal_year_start_month).toBe(1)
|
|
})
|
|
|
|
it('carries f_skatt=false through instead of defaulting to approved', () => {
|
|
const plan = planCompanySetup(CompanySetupSchema.parse({ ...base, f_skatt: false }))
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
expect(plan.input.settings.f_skatt).toBe(false)
|
|
})
|
|
|
|
it('rejects a first fiscal year longer than 18 months', () => {
|
|
const plan = planCompanySetup(
|
|
CompanySetupSchema.parse({
|
|
...base,
|
|
first_fiscal_year: { start: '2026-01-01', end: '2027-12-31' },
|
|
})
|
|
)
|
|
expect(plan.ok).toBe(false)
|
|
})
|
|
|
|
it('leaves vat_number null and moms_period null for a non-VAT company', () => {
|
|
const plan = planCompanySetup(
|
|
CompanySetupSchema.parse({ ...base, vat_registered: false, moms_period: undefined })
|
|
)
|
|
expect(plan.ok).toBe(true)
|
|
if (!plan.ok) return
|
|
expect(plan.input.settings.vat_number).toBeNull()
|
|
expect(plan.input.settings.moms_period).toBeNull()
|
|
})
|
|
})
|