align(用户管理): 超管新建普通账号补所属管理员(createdBy)下拉,payload 仅 normal+已选时带 createdById(对齐 admin.js created_by_id 语义)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
import {
|
||||
createEmptyCreateUserForm,
|
||||
toCreateUserRequest,
|
||||
type CreateUserForm,
|
||||
} from '../src/pages/account/user-create-model.ts'
|
||||
|
||||
/** 对齐 admin.js:904-923,1020:超管创建普通账号时可指定所属管理员(created_by_id)。 */
|
||||
|
||||
test('align_user_created_by_normal_with_created_by_in_payload', () => {
|
||||
// 主路径:超管建 normal 并选了所属管理员 → 请求体带 createdById。
|
||||
const form: CreateUserForm = { username: '张三', password: '123456', role: 'normal', columnIds: [], createdBy: 7 }
|
||||
const payload = toCreateUserRequest(form)
|
||||
assert.equal(payload.createdById, 7)
|
||||
})
|
||||
|
||||
test('align_user_created_by_normal_without_selection_omits_field', () => {
|
||||
// 未选归属(null/undefined)时不发 createdById,与参考"未选则不发 created_by_id"一致。
|
||||
const form: CreateUserForm = { username: '张三', password: '123456', role: 'normal', columnIds: [] }
|
||||
const payload = toCreateUserRequest(form)
|
||||
assert.equal('createdById' in payload, false)
|
||||
})
|
||||
|
||||
test('align_user_created_by_admin_role_never_sends_created_by', () => {
|
||||
// 角色为 admin 时即使选了归属也不发 createdById(参考仅 role=normal 且超管时发送)。
|
||||
const form: CreateUserForm = { username: '李四', password: '123456', role: 'admin', columnIds: [], createdBy: 7 }
|
||||
const payload = toCreateUserRequest(form)
|
||||
assert.equal('createdById' in payload, false)
|
||||
})
|
||||
|
||||
test('align_user_created_by_empty_form_factory_resets_created_by', () => {
|
||||
// 空表单工厂:createdBy 初始为空,保证弹窗重开时归属下拉清空。
|
||||
const form = createEmptyCreateUserForm()
|
||||
assert.equal(form.createdBy, null)
|
||||
})
|
||||
|
||||
test('align_user_created_by_serialization_is_pure', () => {
|
||||
// 序列化纯函数:不改输入、幂等。
|
||||
const form: CreateUserForm = { username: '王五', password: '123456', role: 'normal', columnIds: [1, 2], createdBy: 3 }
|
||||
assert.deepEqual(toCreateUserRequest(form), toCreateUserRequest(form))
|
||||
assert.equal(form.createdBy, 3)
|
||||
})
|
||||
|
||||
test('align_user_created_by_dialog_ui_wiring', () => {
|
||||
// UI 接线:弹窗仅在"超管 + 普通账号"时显示所属管理员下拉,选项来自父页传参。
|
||||
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
||||
assert.match(dialog, /adminOptions|admin-options/i, '弹窗接收父页管理员候选')
|
||||
assert.match(dialog, /operatorSuper\s*&&\s*form\.role\s*===\s*'normal'/, '仅超管建普通账号时显示归属下拉')
|
||||
assert.match(dialog, /请选择管理员/, '占位文案与参考一致')
|
||||
const page = readSource('src/pages/account/UsersPage.vue')
|
||||
assert.match(page, /:admin-options="admins"/, '父页传入列表响应的 admins')
|
||||
})
|
||||
Reference in New Issue
Block a user