Files
accounted/lib/salary/__tests__/agi-reporting-period.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

54 lines
2.2 KiB
TypeScript

/**
* The AGI redovisningsperiod follows the payout month (kontantprincipen),
* not the earned month on the run (#2191).
*/
import { describe, it, expect } from 'vitest'
import {
agiPeriodDiffersFromRunPeriod,
agiReportingPeriod,
formatAgiPeriodCompact,
formatAgiPeriodDashed,
} from '../agi/reporting-period'
describe('agiReportingPeriod', () => {
it('uses the payout month for lön i efterskott (August work paid 25 September)', () => {
const run = { period_year: 2026, period_month: 8, payment_date: '2026-09-25' }
expect(agiReportingPeriod(run)).toEqual({ periodYear: 2026, periodMonth: 9 })
expect(agiPeriodDiffersFromRunPeriod(run)).toBe(true)
})
it('crosses the year boundary with the payout date (December work paid in January)', () => {
const run = { period_year: 2026, period_month: 12, payment_date: '2027-01-25' }
expect(agiReportingPeriod(run)).toEqual({ periodYear: 2027, periodMonth: 1 })
})
it('equals the run period when the pay goes out inside the earned month', () => {
const run = { period_year: 2026, period_month: 3, payment_date: '2026-03-25' }
expect(agiReportingPeriod(run)).toEqual({ periodYear: 2026, periodMonth: 3 })
expect(agiPeriodDiffersFromRunPeriod(run)).toBe(false)
})
it('falls back to the run period when payment_date is missing or malformed', () => {
expect(agiReportingPeriod({ period_year: 2026, period_month: 6 })).toEqual({
periodYear: 2026,
periodMonth: 6,
})
expect(agiReportingPeriod({ period_year: 2026, period_month: 6, payment_date: null })).toEqual({
periodYear: 2026,
periodMonth: 6,
})
expect(
agiReportingPeriod({ period_year: 2026, period_month: 6, payment_date: '25/06/2026' }),
).toEqual({ periodYear: 2026, periodMonth: 6 })
expect(
agiReportingPeriod({ period_year: 2026, period_month: 6, payment_date: '2026-13-01' }),
).toEqual({ periodYear: 2026, periodMonth: 6 })
})
it('formats the compact and dashed forms with a zero-padded month', () => {
const period = { periodYear: 2026, periodMonth: 9 }
expect(formatAgiPeriodCompact(period)).toBe('202609')
expect(formatAgiPeriodDashed(period)).toBe('2026-09')
})
})