本仓 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,未来以本仓历史为主
95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
/**
|
|
* unit/dbLinkId.test.ts — resolveDbLinkId 别名解析单测
|
|
*
|
|
* 覆盖场景:
|
|
* - 'default' (小写) → ctx.dbLinkId
|
|
* - 'DEFAULT' (大写, case-insensitive) → ctx.dbLinkId
|
|
* - 'Default' (混合大小写) → ctx.dbLinkId
|
|
* - '主库' (中文别名) → ctx.dbLinkId
|
|
* - '业务库' (中文别名) → ctx.dbLinkId
|
|
* - undefined / '' (空) → ctx.dbLinkId
|
|
* - '0' (主库标识) → ctx.dbLinkId
|
|
* - 显式数字 id (如 '2068901937849257984') → 原值透传
|
|
* - ctx 缺失时 → '0' 兜底
|
|
* - ctx 缺失 + 有 input (显式 id) → 原值透传
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { resolveDbLinkId } from '../../src/core/dbLinkId.ts'
|
|
import type { AppContext } from '../../src/core/types.ts'
|
|
|
|
const baseCtx: AppContext = {
|
|
appCode: 'jxcj',
|
|
dbLinkId: '2068901937849257984',
|
|
tokenStatus: 'valid',
|
|
existingEnCodes: [],
|
|
unreleasedForms: [],
|
|
releasedForms: [],
|
|
modifiedAfterPublishForms: [],
|
|
workflowList: [],
|
|
topLevelMenus: [],
|
|
currentSystemId: '',
|
|
existingTables: [],
|
|
menus: [],
|
|
currentVersion: '0.11',
|
|
warnings: [],
|
|
}
|
|
|
|
describe('resolveDbLinkId', () => {
|
|
it("'default' 小写别名 → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('default', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'DEFAULT' 大写别名 (case-insensitive) → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('DEFAULT', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'Default' 混合大小写 → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('Default', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'主库' 中文别名 → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('主库', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'业务库' 中文别名 → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('业务库', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it('undefined 输入 → ctx.dbLinkId', () => {
|
|
expect(resolveDbLinkId(undefined, baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'' 空字符串 → ctx.dbLinkId", () => {
|
|
expect(resolveDbLinkId('', baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
|
|
it("'0' 主库标识 → 原值透传 (BS-1 由 guard 拦截)", () => {
|
|
// '0' 不是别名, 是合法的"主库"标识, 由 BS-1 guard 在业务表场景拦截
|
|
expect(resolveDbLinkId('0', baseCtx)).toBe('0')
|
|
})
|
|
|
|
it('显式数字 id → 原值透传 (向后兼容)', () => {
|
|
expect(resolveDbLinkId('664077319056394183', baseCtx)).toBe('664077319056394183')
|
|
})
|
|
|
|
it('ctx=null + 无 input → 兜底 "0"', () => {
|
|
expect(resolveDbLinkId(undefined, null)).toBe('0')
|
|
})
|
|
|
|
it('ctx=null + "default" → 兜底 "0"', () => {
|
|
expect(resolveDbLinkId('default', null)).toBe('0')
|
|
})
|
|
|
|
it('ctx=null + 显式 id → 原值透传', () => {
|
|
expect(resolveDbLinkId('664077319056394183', null)).toBe('664077319056394183')
|
|
})
|
|
|
|
it('ctx=undefined (缺省) + "default" → 兜底 "0"', () => {
|
|
expect(resolveDbLinkId('default', undefined)).toBe('0')
|
|
})
|
|
|
|
it('null 输入 (旧客户端代码) → ctx.dbLinkId', () => {
|
|
expect(resolveDbLinkId(null, baseCtx)).toBe('2068901937849257984')
|
|
})
|
|
})
|