Files
dacli/tests/unit/user-tree.test.ts
T

78 lines
2.5 KiB
TypeScript

/**
* user-tree.test.ts — user 父命令命令树烟囱测试
*
* 不依赖 JNPF, 只验证 18 个 user 子命令都注册成功 + --help 描述正确
*/
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const CLI = resolve(__dirname, '../../src/cli.ts')
function run(args: string[]): string {
try {
return execFileSync('npx', ['tsx', CLI, ...args], {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
})
} catch (e) {
const err = e as { stdout?: Buffer | string; status?: number }
return (err.stdout?.toString() || '')
}
}
describe('user command tree (v18)', () => {
it('user --help 列出全部 18 个子命令', () => {
const out = run(['user', '--help'])
const expected = [
'list', 'create', 'update', 'delete', 'resetPwd', 'unlock',
'batch-state', 'batch-delete', 'batch-set-position',
'get-position', 'set-position',
'workHandover', 'socials-unbind', 'online-kick',
'changepwd', 'baseinfo',
'auth-groups', 'auth-list',
]
for (const cmd of expected) {
expect(out, `缺少子命令 ${cmd}`).toContain(cmd)
}
})
it('user create --help 包含 --account 和 --organizeId', () => {
const out = run(['user', 'create', '--help'])
expect(out).toContain('--account')
expect(out).toContain('--organizeId')
})
it('user batch-state --help 包含 --ids 和 --state', () => {
const out = run(['user', 'batch-state', '--help'])
expect(out).toContain('--ids')
expect(out).toContain('--state')
})
it('user changepwd --help 包含 --oldPassword 和 --newPassword', () => {
const out = run(['user', 'changepwd', '--help'])
expect(out).toContain('--oldPassword')
expect(out).toContain('--newPassword')
})
it('user baseinfo --help 包含 --fields', () => {
const out = run(['user', 'baseinfo', '--help'])
expect(out).toContain('--fields')
})
it('user auth-list --help 包含 --userId 和 --objectId 和 --objectType', () => {
const out = run(['user', 'auth-list', '--help'])
expect(out).toContain('--userId')
expect(out).toContain('--objectId')
expect(out).toContain('--objectType')
})
it('user online-kick --help 包含 --token', () => {
const out = run(['user', 'online-kick', '--help'])
expect(out).toContain('--token')
})
})