All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 37s
CI / test-python-backend-compliance (push) Successful in 32s
CI / test-python-document-crawler (push) Successful in 22s
CI / test-python-dsms-gateway (push) Successful in 18s
Phase A: PostgreSQL State Store (sdk_states Tabelle, InMemory-Fallback) Phase B: Modules dynamisch vom Backend, Scope DB-Persistenz, Source Policy State Phase C: UCCA Frontend (3 Seiten, Wizard, RiskScoreGauge), Obligations Live-Daten Phase D: Document Import (PDF/LLM/Gap-Analyse), System Screening (SBOM/OSV.dev) Phase E: Company Profile CRUD mit Audit-Logging Phase F: Tests (Python + TypeScript), flow-data.ts DB-Tabellen aktualisiert Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
/**
|
|
* Tests for SDK API Client extensions (modules, UCCA, import, screening).
|
|
*/
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
// Mock fetch globally
|
|
const mockFetch = vi.fn()
|
|
global.fetch = mockFetch
|
|
|
|
// Import after mocking
|
|
import { sdkApiClient } from '../api-client'
|
|
|
|
describe('SDK API Client', () => {
|
|
beforeEach(() => {
|
|
mockFetch.mockReset()
|
|
})
|
|
|
|
describe('getModules', () => {
|
|
it('fetches modules from backend', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve([{ id: 'mod-1', name: 'DSGVO' }]),
|
|
})
|
|
|
|
const result = await sdkApiClient.getModules()
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].name).toBe('DSGVO')
|
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
expect.stringContaining('/api/sdk/v1/modules'),
|
|
expect.any(Object)
|
|
)
|
|
})
|
|
|
|
it('returns empty array on error', async () => {
|
|
mockFetch.mockRejectedValueOnce(new Error('Network error'))
|
|
const result = await sdkApiClient.getModules()
|
|
expect(result).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('analyzeDocument', () => {
|
|
it('sends FormData to import analyze endpoint', async () => {
|
|
const mockResponse = {
|
|
document_id: 'doc-1',
|
|
detected_type: 'DSFA',
|
|
confidence: 0.85,
|
|
}
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve(mockResponse),
|
|
})
|
|
|
|
const formData = new FormData()
|
|
const result = await sdkApiClient.analyzeDocument(formData)
|
|
expect(result.document_id).toBe('doc-1')
|
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
expect.stringContaining('/api/sdk/v1/import/analyze'),
|
|
expect.objectContaining({ method: 'POST' })
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('scanDependencies', () => {
|
|
it('sends FormData to screening scan endpoint', async () => {
|
|
const mockResponse = {
|
|
id: 'scan-1',
|
|
status: 'completed',
|
|
total_components: 10,
|
|
total_issues: 2,
|
|
}
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve(mockResponse),
|
|
})
|
|
|
|
const formData = new FormData()
|
|
const result = await sdkApiClient.scanDependencies(formData)
|
|
expect(result.id).toBe('scan-1')
|
|
expect(result.total_components).toBe(10)
|
|
})
|
|
})
|
|
|
|
describe('assessUseCase', () => {
|
|
it('sends intake data to UCCA assess endpoint', async () => {
|
|
const mockResult = { id: 'assessment-1', feasibility: 'GREEN' }
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve(mockResult),
|
|
})
|
|
|
|
const result = await sdkApiClient.assessUseCase({
|
|
name: 'Test Use Case',
|
|
domain: 'education',
|
|
})
|
|
expect(result.feasibility).toBe('GREEN')
|
|
})
|
|
})
|
|
|
|
describe('getAssessments', () => {
|
|
it('fetches assessment list', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve([{ id: 'a1' }, { id: 'a2' }]),
|
|
})
|
|
|
|
const result = await sdkApiClient.getAssessments()
|
|
expect(result).toHaveLength(2)
|
|
})
|
|
})
|
|
})
|