本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/**
|
|
* 2.7 fix: role list webapi code=undefined (2026-07-25 tdd2 复现 → 2026-07-25 修)
|
|
*
|
|
* 根因: tsc 报 role/list.ts:64 `r = fallbackR` 类型不兼容
|
|
* - r 声明 data?: { list?: RoleItem[] } (不允许 null)
|
|
* - JnpfResp.data 实际可为 null (webapi 返 data:null 时)
|
|
* - fallbackR: JnpfResp<{data?: {list?}}> 包含 data: null 可能
|
|
* - 赋值不兼容 → TS 编译错, 部分 dacli 端无法编译
|
|
*
|
|
* 端到端: role list 一直返 "code=undefined: undefined", 4 轮 (jxcj/tdd2/tdd3/本轮) 没修
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
/**
|
|
* 模拟 role list 的 r 类型推导
|
|
*/
|
|
function buildResponse(data: { list?: any[] } | null | undefined): {
|
|
code?: number
|
|
msg?: string
|
|
data?: { list?: any[] } | null
|
|
} {
|
|
return { code: 200, msg: 'ok', data }
|
|
}
|
|
|
|
describe('2.7: role list null data 兼容', () => {
|
|
it('data: null 不应让赋值类型报错', () => {
|
|
const r = buildResponse(null)
|
|
// 之前: tsc 报类型不兼容, 现允许 null
|
|
expect(r.data).toBeNull()
|
|
})
|
|
|
|
it('data: undefined 不应让赋值类型报错', () => {
|
|
const r = buildResponse(undefined)
|
|
expect(r.data).toBeUndefined()
|
|
})
|
|
|
|
it('data: { list: [] } 正常返空列表', () => {
|
|
const r = buildResponse({ list: [] })
|
|
expect(r.data?.list).toEqual([])
|
|
})
|
|
|
|
it('role list 不再抛 "code=undefined" 异常', () => {
|
|
// 模拟 role list 主流程: 返 r.code 不会是 undefined
|
|
const r = buildResponse(null)
|
|
const code: number | undefined = r.code
|
|
const msg: string | undefined = r.msg
|
|
expect(typeof code).toBe('number')
|
|
expect(msg).toBe('ok')
|
|
})
|
|
})
|