Some checks failed
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) Failing after 36s
CI / test-python-backend-compliance (push) Successful in 34s
CI / test-python-document-crawler (push) Successful in 26s
CI / test-python-dsms-gateway (push) Successful in 20s
- Company Profile: setCompanyProfile() und COMPLETE_STEP dispatch nach Backend-Load, damit Sidebar-Checkmarks nach Refresh erhalten bleiben - compliance-scope-engine.test.ts: Property-Namen anpassen (composite_score, risk_score, etc.) - dsfa/types.test.ts: 9 Sections (0-8), 7 required, 2 optional - api-client.test.ts: SDKApiClient-Klasse statt nicht-existierendem Singleton - types.test.ts: use-case-assessment statt use-case-workshop - vitest.config.ts: E2E-Verzeichnis aus Vitest excluden Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
3.0 KiB
TypeScript
107 lines
3.0 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'
|
|
|
|
const client = new SDKApiClient({
|
|
baseUrl: '/api/sdk/v1',
|
|
tenantId: 'test-tenant',
|
|
})
|
|
|
|
describe('SDK API Client', () => {
|
|
beforeEach(() => {
|
|
mockFetch.mockReset()
|
|
})
|
|
|
|
describe('getModules', () => {
|
|
it('fetches modules from backend', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve({ modules: [{ id: 'mod-1', name: 'DSGVO' }], total: 1 }),
|
|
})
|
|
|
|
const result = await client.getModules()
|
|
expect(result.modules).toHaveLength(1)
|
|
expect(result.total).toBe(1)
|
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
expect.stringContaining('/api/sdk/v1/modules'),
|
|
expect.any(Object)
|
|
)
|
|
})
|
|
|
|
it('throws on network error', async () => {
|
|
mockFetch.mockRejectedValueOnce(new Error('Network error'))
|
|
await expect(client.getModules()).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe('analyzeDocument', () => {
|
|
it('sends FormData to import analyze endpoint', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve({
|
|
data: { document_id: 'doc-1', detected_type: 'DSFA', confidence: 0.85 },
|
|
}),
|
|
})
|
|
|
|
const formData = new FormData()
|
|
const result = await client.analyzeDocument(formData) as any
|
|
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 () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve({
|
|
data: { id: 'scan-1', status: 'completed', total_components: 10, total_issues: 2 },
|
|
}),
|
|
})
|
|
|
|
const formData = new FormData()
|
|
const result = await client.scanDependencies(formData) as any
|
|
expect(result.id).toBe('scan-1')
|
|
expect(result.total_components).toBe(10)
|
|
})
|
|
})
|
|
|
|
describe('assessUseCase', () => {
|
|
it('sends intake data to UCCA assess endpoint', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve({ id: 'assessment-1', feasibility: 'GREEN' }),
|
|
})
|
|
|
|
const result = await client.assessUseCase({
|
|
name: 'Test Use Case',
|
|
domain: 'education',
|
|
}) as any
|
|
expect(result.feasibility).toBe('GREEN')
|
|
})
|
|
})
|
|
|
|
describe('getAssessments', () => {
|
|
it('fetches assessment list', async () => {
|
|
mockFetch.mockResolvedValueOnce({
|
|
ok: true,
|
|
json: () => Promise.resolve({ data: [{ id: 'a1' }, { id: 'a2' }] }),
|
|
})
|
|
|
|
const result = await client.getAssessments()
|
|
expect(result).toHaveLength(2)
|
|
})
|
|
})
|
|
})
|