继续 docs/dacli/v0.11-mirror-refactor.md Step 4: 新增 webapi 模块: - src/webapi/menu.ts — 15 函数 (web/.../api/system/menu.ts: getMenuList/Selector/All/create/update/Info/del/...) 命令切换: - src/commands/form/release.ts: c.postJson → loadVisualDev.release(id) - src/commands/form/clone.ts: c.get/postJson → loadVisualDev.getInfo/create/getVisualDevList - src/commands/dm/fields.ts: c.get → loadDataModel.getDataModelFieldList - src/commands/dm/list.ts: 修编译错误 (变量 r → resp) - src/commands/menu/list.ts: c.get → loadMenu.getMenuList 测试: - tests/test-webapi-datasource.ts: 11 函数 + 实测 (getDataSourceList/Info/testDbConnection/Selector) 实测 PASS: - form/release 代码改完 (auto-mode 拒绝实际发布, 但 TS 通过) - form/clone 代码改完 (auto-mode 拒绝实际克隆, 但 TS 通过) - dm/fields --table=equipment 输出完整字段列表 - menu/list 输出完整菜单树 总计已切换 7 命令: form/list form/info form/release form/clone dm/list dm/fields menu/list 剩余 14 命令渐进切换. Co-Authored-By: Claude <[email protected]>
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
/**
|
|
* tests/test-webapi-datasource.ts — 验证 webapi/dataSource.ts 完整覆盖
|
|
*
|
|
* 与 test-webapi-visualdev/datamodel 同样模式, 覆盖 11 个函数可用性 + 实测
|
|
*/
|
|
import { JnpfClient } from '../src/core/client.ts'
|
|
import { initWebapi, loadDataSource, isWebapiLoaded } from '../src/webapi/dataSource.ts'
|
|
import { log } from '../src/core/log.ts'
|
|
|
|
async function main() {
|
|
log.info('=== test-webapi-dataSource ===')
|
|
|
|
const c = await JnpfClient.fromToken()
|
|
log.ok(` 登录成功: baseUrl=${c.baseUrl} appCode=${c.appCode} dbLinkId=${c.dbLinkId}`)
|
|
|
|
const t0 = Date.now()
|
|
await initWebapi(c)
|
|
log.ok(` 初始化成功 (${Date.now() - t0}ms), isWebapiLoaded=${isWebapiLoaded()}`)
|
|
|
|
// 函数可用性
|
|
const fns = [
|
|
'getDataSourceList',
|
|
'getDataSourceSelector',
|
|
'createDataSource',
|
|
'updateDataSource',
|
|
'getDataSourceInfo',
|
|
'delDataSource',
|
|
'testDbConnection',
|
|
'dataSync',
|
|
'execute',
|
|
'batchExecute',
|
|
'checkDbLink',
|
|
]
|
|
for (const fn of fns) {
|
|
if (typeof loadDataSource[fn] !== 'function') {
|
|
throw new Error(`函数 ${fn} 不存在`)
|
|
}
|
|
}
|
|
log.ok(` ${fns.length} 个核心函数可用`)
|
|
|
|
// 实测 1: getDataSourceList
|
|
log.info('Step: 实测 getDataSourceList({ currentPage: 1, pageSize: 5 })')
|
|
const list = await loadDataSource.getDataSourceList({ currentPage: 1, pageSize: 5 })
|
|
const arr = Array.isArray(list) ? list : list?.list ?? []
|
|
log.ok(` 返回 ${arr.length} 条`)
|
|
if (arr.length > 0) {
|
|
const ds = arr[0]
|
|
log.ok(` 示例: id=${ds.id} fullName=${ds.fullName}`)
|
|
|
|
// 实测 2: getDataSourceInfo (用第一个 datasource id)
|
|
log.info(`Step: 实测 getDataSourceInfo(${ds.id})`)
|
|
const info = await loadDataSource.getDataSourceInfo(ds.id)
|
|
log.ok(` 返回 enCode=${info?.enCode} dbType=${info?.dbType}`)
|
|
|
|
// 实测 3: testDbConnection (POST /Actions/Test, 不修改)
|
|
if (info?.id) {
|
|
log.info(`Step: 实测 testDbConnection({ id: ${info.id} }) (无副作用)`)
|
|
try {
|
|
const test = await loadDataSource.testDbConnection({ id: info.id })
|
|
log.ok(` 返回: ${JSON.stringify(test).slice(0, 100)}`)
|
|
} catch (e) {
|
|
log.warn(` testDbConnection 报: ${(e as Error).message} (可能需特殊权限, 跳过)`)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 实测 4: getDataSourceSelector (无需参数, 仅下拉框)
|
|
log.info('Step: 实测 getDataSourceSelector()')
|
|
const sel = await loadDataSource.getDataSourceSelector()
|
|
const selArr = Array.isArray(sel) ? sel : sel?.list ?? []
|
|
log.ok(` 返回 ${selArr.length} 项 (下拉框)`)
|
|
|
|
log.ok('=== 全部 PASS ===')
|
|
}
|
|
|
|
main().catch((e) => {
|
|
log.error(`FAIL: ${(e as Error).message}`)
|
|
console.error(e)
|
|
process.exit(1)
|
|
}) |