Files
accounted/lib/bokslut/ixbrl/validate/__tests__/arelle-client.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

53 lines
1.8 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { validateIxbrlWithArelle } from '../arelle-client'
afterEach(() => {
vi.unstubAllGlobals()
})
describe('validateIxbrlWithArelle', () => {
it('returns unavailable when no validator is configured', async () => {
const result = await validateIxbrlWithArelle('<html />', { url: '' })
expect(result.status).toBe('unavailable')
expect(result.issues[0].code).toBe('ARELLE-NOT-CONFIGURED')
})
it('sends the exact artifact and accepts a clean validation', async () => {
const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {
const body = JSON.parse(String(init.body)) as { content_base64: string }
expect(Buffer.from(body.content_base64, 'base64').toString('utf8')).toBe('<html />')
return new Response(JSON.stringify({ ok: true, validator_version: '2.37.50', issues: [] }))
})
vi.stubGlobal('fetch', fetchMock)
const result = await validateIxbrlWithArelle('<html />', {
url: 'https://validator.example/validate',
token: 'secret',
})
expect(result.status).toBe('passed')
expect(result.validator_version).toBe('2.37.50')
expect(fetchMock).toHaveBeenCalledOnce()
})
it('normalizes Arelle errors into a blocking result', async () => {
vi.stubGlobal(
'fetch',
vi.fn(async () =>
new Response(
JSON.stringify({
ok: false,
issues: [{ code: 'xbrl.5.2.5.2', severity: 'error', message: 'Invalid fact' }],
}),
),
),
)
const result = await validateIxbrlWithArelle('<html />', {
url: 'https://validator.example/validate',
})
expect(result.status).toBe('failed')
expect(result.issues).toEqual([
{ code: 'xbrl.5.2.5.2', severity: 'error', message: 'Invalid fact' },
])
})
})