108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
/**
|
|
* role-user-org.test.ts — 权限三角 3 父命令烟囱测试
|
|
*/
|
|
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('role command tree (W10-D1)', () => {
|
|
it('role --help 列出 4 个子命令', () => {
|
|
const out = run(['role', '--help'])
|
|
expect(out).toContain('list')
|
|
expect(out).toContain('create')
|
|
expect(out).toContain('delete')
|
|
expect(out).toContain('assign')
|
|
})
|
|
it('role list --ai-help 提示决策 7', () => {
|
|
const out = run(['role', 'list', '--ai-help'])
|
|
expect(out).toContain('决策 7')
|
|
expect(out).toContain('/api/permission/Role')
|
|
})
|
|
it('role create --help 包含 --fullName/--enCode', () => {
|
|
const out = run(['role', 'create', '--help'])
|
|
expect(out).toContain('--fullName')
|
|
expect(out).toContain('--enCode')
|
|
})
|
|
it('role delete --help 包含 --yes', () => {
|
|
const out = run(['role', 'delete', '--help'])
|
|
expect(out).toContain('--yes')
|
|
})
|
|
it('role assign --help 包含 --userIds/--action', () => {
|
|
const out = run(['role', 'assign', '--help'])
|
|
expect(out).toContain('--userIds')
|
|
expect(out).toContain('--action')
|
|
})
|
|
it('顶层 --help 包含 role', () => {
|
|
const out = run(['--help'])
|
|
expect(out).toContain('role')
|
|
})
|
|
})
|
|
|
|
describe('user command tree (W10-D2)', () => {
|
|
it('user --help 列出 4 个子命令', () => {
|
|
const out = run(['user', '--help'])
|
|
expect(out).toContain('list')
|
|
expect(out).toContain('create')
|
|
expect(out).toContain('delete')
|
|
expect(out).toContain('resetPwd')
|
|
})
|
|
it('user list --ai-help 提示决策 7', () => {
|
|
const out = run(['user', 'list', '--ai-help'])
|
|
expect(out).toContain('决策 7')
|
|
expect(out).toContain('/api/permission/Users')
|
|
})
|
|
it('user create --help 包含 --organizeId/--gender', () => {
|
|
const out = run(['user', 'create', '--help'])
|
|
expect(out).toContain('--organizeId')
|
|
expect(out).toContain('--gender')
|
|
})
|
|
it('user resetpwd --help 包含 --password', () => {
|
|
const out = run(['user', 'resetPwd', '--help'])
|
|
expect(out).toContain('--password')
|
|
})
|
|
it('顶层 --help 包含 user', () => {
|
|
const out = run(['--help'])
|
|
expect(out).toContain('user')
|
|
})
|
|
})
|
|
|
|
describe('org command tree (W10-D3)', () => {
|
|
it('org --help 列出 3 个子命令', () => {
|
|
const out = run(['org', '--help'])
|
|
expect(out).toContain('list')
|
|
expect(out).toContain('tree')
|
|
expect(out).toContain('create')
|
|
})
|
|
it('org list --ai-help 提示决策 7', () => {
|
|
const out = run(['org', 'list', '--ai-help'])
|
|
expect(out).toContain('决策 7')
|
|
expect(out).toContain('/api/permission/Organize/Selector')
|
|
})
|
|
it('org create --help 包含 --parentId/--category', () => {
|
|
const out = run(['org', 'create', '--help'])
|
|
expect(out).toContain('--parentId')
|
|
expect(out).toContain('--category')
|
|
})
|
|
it('顶层 --help 包含 org', () => {
|
|
const out = run(['--help'])
|
|
expect(out).toContain('org')
|
|
})
|
|
})
|