## 配置与环境 - .env.example: 更新环境变量配置 - docker-compose.yml: 完善Docker编排配置 - docker/README.md: 更新Docker文档 ## 后端知识库模块 - endpoints/knowledge.py: 增强知识库API端点 - schemas/knowledge.py: 扩展知识库数据模型 - services/knowledge.py: 完善知识库业务逻辑 - config.py: 优化配置管理 - storage/knowledge/.index.json: 更新知识库索引 ## 前端功能 - api.js: 完善API服务层 - knowledge.js: 优化知识库服务 - onlyoffice.js: 新增OnlyOffice文档服务集成 - TopBar.vue: 优化顶部导航栏 - PoliciesView.vue: 完善策略视图 - AppShellRouteView.vue: 新增应用外壳路由视图 - views/scripts/PoliciesView.js: 优化策略脚本 - policiesPreviewFormatters.js: 新增策略预览格式化工具 ## 样式 - policies-view.css: 完善策略页样式 ## 测试 - api-request.test.mjs: API请求测试 - onlyoffice-service.test.mjs: OnlyOffice服务测试 - policies-preview-formatters.test.mjs: 策略预览格式化测试
100 lines
2.2 KiB
JavaScript
100 lines
2.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
|
|
import { apiRequest } from '../src/services/api.js'
|
|
|
|
async function testUsesCustomContentTypeHeader() {
|
|
let capturedOptions = null
|
|
|
|
global.fetch = async (_url, options) => {
|
|
capturedOptions = options
|
|
return {
|
|
ok: true,
|
|
async json() {
|
|
return { ok: true }
|
|
}
|
|
}
|
|
}
|
|
|
|
await apiRequest('/knowledge/documents', {
|
|
method: 'POST',
|
|
body: 'payload',
|
|
contentType: 'application/octet-stream'
|
|
})
|
|
|
|
assert.equal(capturedOptions.headers['Content-Type'], 'application/octet-stream')
|
|
}
|
|
|
|
async function testSupportsBlobResponses() {
|
|
const blob = new Blob(['preview'])
|
|
|
|
global.fetch = async () => ({
|
|
ok: true,
|
|
async blob() {
|
|
return blob
|
|
},
|
|
async json() {
|
|
throw new Error('json parser should not be used for blob responses')
|
|
}
|
|
})
|
|
|
|
const payload = await apiRequest('/knowledge/documents/demo/content', {
|
|
responseType: 'blob',
|
|
contentType: null
|
|
})
|
|
|
|
assert.equal(payload, blob)
|
|
}
|
|
|
|
async function testInjectsAuthenticatedUserHeaders() {
|
|
const sessionStorage = new Map([
|
|
[
|
|
'x-financial-auth-user',
|
|
JSON.stringify({
|
|
username: 'admin',
|
|
name: '系统管理员',
|
|
roleCodes: ['manager'],
|
|
isAdmin: true
|
|
})
|
|
]
|
|
])
|
|
|
|
global.window = {
|
|
sessionStorage: {
|
|
getItem(key) {
|
|
return sessionStorage.get(key) ?? null
|
|
}
|
|
}
|
|
}
|
|
|
|
let capturedOptions = null
|
|
|
|
global.fetch = async (_url, options) => {
|
|
capturedOptions = options
|
|
return {
|
|
ok: true,
|
|
async json() {
|
|
return { ok: true }
|
|
}
|
|
}
|
|
}
|
|
|
|
await apiRequest('/knowledge/library')
|
|
|
|
assert.equal(capturedOptions.headers['x-auth-username'], 'admin')
|
|
assert.equal(capturedOptions.headers['x-auth-name'], '系统管理员')
|
|
assert.equal(capturedOptions.headers['x-auth-role-codes'], 'manager')
|
|
assert.equal(capturedOptions.headers['x-auth-is-admin'], 'true')
|
|
}
|
|
|
|
async function run() {
|
|
await testUsesCustomContentTypeHeader()
|
|
await testSupportsBlobResponses()
|
|
await testInjectsAuthenticatedUserHeaders()
|
|
console.log('api-request tests passed')
|
|
}
|
|
|
|
run().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|