Files
bilin/tests/main/compliance.test.ts
T

34 lines
1.1 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { mkdtempSync, rmSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { ComplianceService } from '../../src/main/services/compliance.service'
import { GlobalSettingsService } from '../../src/main/services/global-settings'
describe('ComplianceService', () => {
let dir: string
let svc: ComplianceService
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'bilin-compliance-'))
svc = new ComplianceService(new GlobalSettingsService(dir))
})
afterEach(() => {
rmSync(dir, { recursive: true, force: true })
})
it('UT-COMP-01: scans built-in and custom words', () => {
svc.setWords(['测试敏感词'])
const result = svc.scanText('正文含违禁与测试敏感词内容')
const words = result.matches.map((m) => m.word)
expect(words).toContain('违禁')
expect(words).toContain('测试敏感词')
})
it('UT-COMP-02: applyReplacements replaces configured pairs', () => {
const out = svc.applyReplacements('这里有违禁词', { : '***' })
expect(out).toBe('这里有***词')
})
})