Files
accounted/lib/import/__tests__/fiscal-period-start-day.pg.test.ts
T
Jakob WennbergandClaude Sonnet 5 ec27228a8e style: remove em/en dashes repo-wide, add CLAUDE.md rule against them (#890)
Em dashes (—) and en dashes (–) had spread across comments, docs, tests,
and a few UI strings, reading as AI-generated boilerplate rather than
house style. Replaced each with punctuation matching its context: colon
for explanatory clauses, comma for asides, plain hyphen for numeric/legal
ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for
paired-dash asides. messages/en.json and messages/sv.json were fixed by
hand together to keep sv/en in sync.

Left untouched where the dash is the functional subject rather than
decorative punctuation: date-range-parser.ts's separator regex,
charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE
encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the
agent system-prompt files that already instruct against em dashes, and
a golden iXBRL test fixture compared byte-for-byte.

Also fixes two bugs surfaced along the way: an off-by-one in
ApiKeysPanel's scope-label split (a leftover from an earlier partial
pass), and a charset-repair test that had lost the literal en-dash it
exists to verify.

Regenerated the agent atom seed migration (skills:generate) since 27
SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes,
with an explicit carve-out for the functional-dash cases above.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:58:06 +02:00

75 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getPool } from '@/tests/pg/setup'
import { seedCompany } from '@/tests/pg/fixtures'
// Covers enforce_first_of_month_for_subsequent_periods (migration
// 20260418120000). The trigger only blocks mid-month period_start when a
// strictly earlier period exists: so importing a company's chronologically
// first fiscal year (förlängt första räkenskapsår) via SIE must succeed even
// after a later period was created during onboarding.
//
// seedCompany() creates a default 2026-01-01..2026-12-31 fiscal period; the
// no_overlapping_fiscal_periods exclusion constraint (per-company since
// migration 20260506140100) means every period inserted here must avoid
// overlapping that year. The years below are chosen accordingly.
describe('fiscal_periods: subsequent-period start-day trigger', () => {
async function insertPeriod(
companyId: string,
name: string,
periodStart: string,
periodEnd: string,
) {
return getPool().query(
`INSERT INTO public.fiscal_periods
(company_id, name, period_start, period_end, is_closed, opening_balances_set)
VALUES ($1, $2, $3, $4, false, false)
RETURNING id`,
[companyId, name, periodStart, periodEnd],
)
}
it('allows a mid-month start when no earlier period exists', async () => {
const { companyId } = await seedCompany()
// The seeded 2026 period is later than this one, so this insert is the
// chronologically earliest period for the company → trigger must permit
// a mid-month start (förlängt första räkenskapsår path).
const { rows } = await insertPeriod(
companyId,
'Räkenskapsår 2024/2025',
'2024-06-15',
'2025-12-31',
)
expect(rows[0]!.id).toBeTruthy()
})
it('allows importing an earlier mid-month period after a later day-1 period exists', async () => {
const { companyId } = await seedCompany()
// Onboarding-created period (day 1, year N): sits before the seeded 2026.
await insertPeriod(companyId, 'Räkenskapsår 2025', '2025-01-01', '2025-12-31')
// SIE import of förlängt första räkenskapsår: earlier in time,
// mid-month start. This used to fail with the old trigger.
const { rows } = await insertPeriod(
companyId,
'Räkenskapsår 2023/2024',
'2023-06-15',
'2024-12-31',
)
expect(rows[0]!.id).toBeTruthy()
})
it('still rejects mid-month start when a strictly earlier period already exists', async () => {
const { companyId } = await seedCompany()
await insertPeriod(companyId, 'Räkenskapsår 2024', '2024-01-01', '2024-12-31')
// Mid-month start in 2025: strictly later than 2024 and not overlapping
// with the seeded 2026 period → only the start-day trigger should fire.
await expect(
insertPeriod(companyId, 'Räkenskapsår 2025 (bad)', '2025-06-15', '2025-12-31'),
).rejects.toThrow(/Non-first fiscal period must start on the 1st of a month/)
})
})