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>
92 lines
3.5 KiB
TypeScript
92 lines
3.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { NextResponse } from 'next/server'
|
|
import { parseJsonResponse } from '@/tests/helpers'
|
|
|
|
const mockSupabase = {
|
|
auth: { getUser: vi.fn() },
|
|
}
|
|
vi.mock('@/lib/supabase/server', () => ({
|
|
createClient: () => Promise.resolve(mockSupabase),
|
|
}))
|
|
|
|
vi.mock('@/lib/company/context', () => ({
|
|
getActiveCompanyId: vi.fn().mockResolvedValue('company-1'),
|
|
}))
|
|
|
|
vi.mock('@/lib/auth/require-auth', () => ({
|
|
requireAuth: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/salary/tax-tables', () => ({
|
|
fetchKommunTaxRates: vi.fn(),
|
|
}))
|
|
|
|
import { GET } from '../route'
|
|
import { requireAuth } from '@/lib/auth/require-auth'
|
|
import { fetchKommunTaxRates } from '@/lib/salary/tax-tables'
|
|
|
|
const mockUser = { id: 'user-1', email: 'test@test.se' }
|
|
|
|
describe('GET /api/salary/tax-tables/kommuner', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
vi.mocked(requireAuth).mockResolvedValue({
|
|
user: mockUser as never,
|
|
supabase: mockSupabase as never,
|
|
error: null,
|
|
})
|
|
vi.mocked(fetchKommunTaxRates).mockResolvedValue([
|
|
{ kommun: 'Östersund', totalRate: 33.0, tableNumber: 33 },
|
|
{ kommun: 'Aronsjö', totalRate: 32.49, tableNumber: 32 },
|
|
{ kommun: 'Stockholm', totalRate: 29.82, tableNumber: 30 },
|
|
])
|
|
})
|
|
|
|
it('returns 401 when not authenticated', async () => {
|
|
vi.mocked(requireAuth).mockResolvedValue({
|
|
user: null as never,
|
|
supabase: mockSupabase as never,
|
|
error: NextResponse.json({ error: 'Unauthorized' }, { status: 401 }),
|
|
})
|
|
|
|
const request = new Request('http://localhost/api/salary/tax-tables/kommuner?year=2030')
|
|
const response = await GET(request, { params: Promise.resolve({}) })
|
|
const { status } = await parseJsonResponse(response)
|
|
expect(status).toBe(401)
|
|
})
|
|
|
|
it('returns the kommun list sorted by Swedish collation', async () => {
|
|
const request = new Request('http://localhost/api/salary/tax-tables/kommuner?year=2031')
|
|
const response = await GET(request, { params: Promise.resolve({}) })
|
|
const { status, body } = await parseJsonResponse<{
|
|
data: { year: number; kommuner: { kommun: string; tableNumber: number }[] }
|
|
}>(response)
|
|
|
|
expect(status).toBe(200)
|
|
expect(body.data.year).toBe(2031)
|
|
expect(body.data.kommuner.map((k) => k.kommun)).toEqual(['Aronsjö', 'Stockholm', 'Östersund'])
|
|
expect(body.data.kommuner[1]).toMatchObject({ kommun: 'Stockholm', tableNumber: 30 })
|
|
})
|
|
|
|
it('falls back to the current year for a non-numeric year (no NaN reaches Skatteverket/cache)', async () => {
|
|
const currentYear = new Date().getFullYear()
|
|
const request = new Request('http://localhost/api/salary/tax-tables/kommuner?year=not-a-year')
|
|
const response = await GET(request, { params: Promise.resolve({}) })
|
|
const { status, body } = await parseJsonResponse<{ data: { year: number } }>(response)
|
|
|
|
expect(status).toBe(200)
|
|
expect(body.data.year).toBe(currentYear)
|
|
expect(fetchKommunTaxRates).toHaveBeenCalledWith(currentYear)
|
|
})
|
|
|
|
it('caches per year: a second request for the same year does not refetch', async () => {
|
|
const req1 = new Request('http://localhost/api/salary/tax-tables/kommuner?year=2032')
|
|
await GET(req1, { params: Promise.resolve({}) })
|
|
const req2 = new Request('http://localhost/api/salary/tax-tables/kommuner?year=2032')
|
|
await GET(req2, { params: Promise.resolve({}) })
|
|
|
|
expect(fetchKommunTaxRates).toHaveBeenCalledTimes(1)
|
|
expect(fetchKommunTaxRates).toHaveBeenCalledWith(2032)
|
|
})
|
|
})
|