a28db8f8f0
Eliminate the pre-existing TS errors that were masked by next.config.js `typescript.ignoreBuildErrors: true`, then turn the flag OFF so the compiler is a real safety net for future changes. `next build` and `tsc --noEmit` now pass with 0 errors. The errors were not cosmetic — several exposed real latent bugs hidden by the flag, e.g. the drafting-engine ConstraintEnforcer read non-existent fields (`t.rule.dsfaRequired`, `d.required`, `r.title`), so its DSFA hard gate and risk-flag checks were silently no-ops; scopeDefaults read snake_case CompanyProfile fields that never matched the camelCase type (generator defaults never populated). Both fixed by aligning code to the current types. Highlights: - Vitest globals: add vitest-globals.d.ts (config already had globals:true) so the test files type-check; exclude Playwright specs from vitest. - Add a minimal ambient `pg` module declaration (no @types/pg installed). - Fix Next 15 route handlers to await Promise params. - Reconcile drifted types across loeschfristen, compliance-scope, document- generator, drafting-engine, vendor-compliance, agent and more. Pre-existing (NOT caused here, proven by stashing the diff): 3 vitest logic tests still fail — getNextStep (2) and buildDocumentScope priority (1). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
194 lines
6.9 KiB
TypeScript
194 lines
6.9 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
parseEmployeeRange,
|
|
parseRevenueRange,
|
|
buildAssessmentPayload,
|
|
} from '../scope-to-facts'
|
|
import type { CompanyProfile } from '../types'
|
|
import type { ScopeProfilingAnswer, ScopeDecision } from '../compliance-scope-types'
|
|
|
|
// =============================================================================
|
|
// parseEmployeeRange
|
|
// =============================================================================
|
|
|
|
describe('parseEmployeeRange', () => {
|
|
it('returns 5 for "1-9"', () => {
|
|
expect(parseEmployeeRange('1-9')).toBe(5)
|
|
})
|
|
|
|
it('returns 30 for "10-49"', () => {
|
|
expect(parseEmployeeRange('10-49')).toBe(30)
|
|
})
|
|
|
|
it('returns 150 for "50-249"', () => {
|
|
expect(parseEmployeeRange('50-249')).toBe(150)
|
|
})
|
|
|
|
it('returns 625 for "250-999"', () => {
|
|
expect(parseEmployeeRange('250-999')).toBe(625)
|
|
})
|
|
|
|
it('returns 1500 for "1000+"', () => {
|
|
expect(parseEmployeeRange('1000+')).toBe(1500)
|
|
})
|
|
|
|
it('returns 10 for null', () => {
|
|
expect(parseEmployeeRange(null)).toBe(10)
|
|
})
|
|
|
|
it('returns 10 for undefined', () => {
|
|
expect(parseEmployeeRange(undefined)).toBe(10)
|
|
})
|
|
})
|
|
|
|
// =============================================================================
|
|
// parseRevenueRange
|
|
// =============================================================================
|
|
|
|
describe('parseRevenueRange', () => {
|
|
it('returns 1000000 for "< 2 Mio"', () => {
|
|
expect(parseRevenueRange('< 2 Mio')).toBe(1000000)
|
|
})
|
|
|
|
it('returns 6000000 for "2-10 Mio"', () => {
|
|
expect(parseRevenueRange('2-10 Mio')).toBe(6000000)
|
|
})
|
|
|
|
it('returns 30000000 for "10-50 Mio"', () => {
|
|
expect(parseRevenueRange('10-50 Mio')).toBe(30000000)
|
|
})
|
|
|
|
it('returns 75000000 for "> 50 Mio"', () => {
|
|
expect(parseRevenueRange('> 50 Mio')).toBe(75000000)
|
|
})
|
|
|
|
it('returns 1000000 for null', () => {
|
|
expect(parseRevenueRange(null)).toBe(1000000)
|
|
})
|
|
|
|
it('returns 1000000 for undefined', () => {
|
|
expect(parseRevenueRange(undefined)).toBe(1000000)
|
|
})
|
|
})
|
|
|
|
// =============================================================================
|
|
// buildAssessmentPayload
|
|
// =============================================================================
|
|
|
|
describe('buildAssessmentPayload', () => {
|
|
const baseProfile = {
|
|
companyName: 'Test GmbH',
|
|
legalForm: 'gmbh',
|
|
industry: ['IT', 'Software'],
|
|
employeeCount: '50-249',
|
|
annualRevenue: '10-50 Mio',
|
|
headquartersCountry: 'DE',
|
|
headquartersState: 'BW',
|
|
isDataController: true,
|
|
isDataProcessor: false,
|
|
offerings: ['software_saas'],
|
|
} as unknown as CompanyProfile
|
|
|
|
const baseAnswers: ScopeProfilingAnswer[] = [
|
|
{ questionId: 'data_art9', value: false, blockId: 'data' },
|
|
{ questionId: 'data_minors', value: false, blockId: 'data' },
|
|
{ questionId: 'data_hr', value: true, blockId: 'data' },
|
|
{ questionId: 'data_financial', value: false, blockId: 'data' },
|
|
{ questionId: 'tech_third_country', value: true, blockId: 'tech' },
|
|
{ questionId: 'tech_subprocessors', value: true, blockId: 'tech' },
|
|
{ questionId: 'proc_adm_scoring', value: false, blockId: 'processing' },
|
|
{ questionId: 'proc_employee_monitoring', value: false, blockId: 'processing' },
|
|
{ questionId: 'proc_video_surveillance', value: false, blockId: 'processing' },
|
|
{ questionId: 'proc_tracking', value: false, blockId: 'processing' },
|
|
{ questionId: 'prod_cookies_consent', value: true, blockId: 'product' },
|
|
{ questionId: 'data_volume', value: false, blockId: 'data' },
|
|
{ questionId: 'ai_uses_ai', value: true, blockId: 'ai' },
|
|
{ questionId: 'ai_categories', value: ['ai_provider'], blockId: 'ai' },
|
|
{ questionId: 'ai_risk_assessment', value: 'limited', blockId: 'ai' },
|
|
{ questionId: 'org_cert_target', value: 'iso27001', blockId: 'organisation' },
|
|
]
|
|
|
|
it('maps a full profile correctly', () => {
|
|
const payload = buildAssessmentPayload(baseProfile, baseAnswers, null)
|
|
|
|
expect(payload.employee_count).toBe(150)
|
|
expect(payload.annual_revenue).toBe(30000000)
|
|
expect(payload.country).toBe('DE')
|
|
expect(payload.industry).toBe('IT, Software')
|
|
expect(payload.legal_form).toBe('gmbh')
|
|
expect(payload.is_controller).toBe(true)
|
|
expect(payload.is_processor).toBe(false)
|
|
expect(payload.cross_border_transfer).toBe(true)
|
|
expect(payload.uses_processors).toBe(true)
|
|
expect(payload.uses_cookies).toBe(true)
|
|
expect(payload.processes_employee_data).toBe(true)
|
|
expect(payload.operates_platform).toBe(true)
|
|
expect(payload.proc_ai_usage).toBe(true)
|
|
expect(payload.cert_target).toBe('iso27001')
|
|
})
|
|
|
|
it('uses defaults for null/undefined profile fields', () => {
|
|
const emptyProfile = {
|
|
companyName: 'Minimal',
|
|
} as unknown as CompanyProfile
|
|
const payload = buildAssessmentPayload(emptyProfile, [], null)
|
|
|
|
expect(payload.employee_count).toBe(10) // parseEmployeeRange(undefined)
|
|
expect(payload.annual_revenue).toBe(1000000)
|
|
expect(payload.country).toBe('DE') // default
|
|
expect(payload.industry).toBe('')
|
|
expect(payload.legal_form).toBe('')
|
|
expect(payload.is_controller).toBe(true) // default
|
|
expect(payload.is_processor).toBe(false) // default
|
|
expect(payload.determined_level).toBe('L2') // default
|
|
})
|
|
|
|
it('detects AI provider from ai_categories', () => {
|
|
const payload = buildAssessmentPayload(baseProfile, baseAnswers, null)
|
|
|
|
expect(payload.is_ai_provider).toBe(true)
|
|
expect(payload.is_ai_deployer).toBe(false)
|
|
expect(payload.limited_risk_ai).toBe(true)
|
|
expect(payload.high_risk_ai).toBe(false)
|
|
})
|
|
|
|
it('detects AI deployer from ai_categories', () => {
|
|
const deployerAnswers = baseAnswers.map(a =>
|
|
a.questionId === 'ai_categories'
|
|
? { ...a, value: ['ai_deployer'] }
|
|
: a
|
|
)
|
|
const payload = buildAssessmentPayload(baseProfile, deployerAnswers, null)
|
|
|
|
expect(payload.is_ai_provider).toBe(false)
|
|
expect(payload.is_ai_deployer).toBe(true)
|
|
})
|
|
|
|
it('detects financial institution from industry', () => {
|
|
const finProfile: CompanyProfile = {
|
|
...baseProfile,
|
|
industry: ['Finanzdienstleistungen', 'Banking'],
|
|
}
|
|
const payload = buildAssessmentPayload(finProfile, baseAnswers, null)
|
|
|
|
expect(payload.is_financial_institution).toBe(true)
|
|
})
|
|
|
|
it('includes decision data when provided', () => {
|
|
const decision: ScopeDecision = {
|
|
determinedLevel: 'L3',
|
|
triggeredHardTriggers: [
|
|
{ ruleId: 'rule-1', rule: { id: 'rule-1', name: 'Test Rule', description: '', targetLevel: 'L3', trigger: { field: '', op: 'eq', value: true } }, factValue: true },
|
|
],
|
|
requiredDocuments: [
|
|
{ documentType: 'dsfa', reason: 'test', regulation: 'dsgvo' },
|
|
],
|
|
} as any
|
|
const payload = buildAssessmentPayload(baseProfile, baseAnswers, decision)
|
|
|
|
expect(payload.determined_level).toBe('L3')
|
|
expect(payload.triggered_rules).toEqual(['rule-1'])
|
|
expect(payload.required_documents).toEqual(['dsfa'])
|
|
})
|
|
})
|