122 lines
7.3 KiB
TypeScript
122 lines
7.3 KiB
TypeScript
import test from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readSource } from './helpers.ts'
|
||
import {
|
||
eligibleGroupLeaders,
|
||
eligibleGroupMembers,
|
||
groupMemberCandidateHint,
|
||
} from '../src/pages/account/shop-group-model.ts'
|
||
|
||
/** 对齐 admin.js:3020-3028 getEligibleShopManageGroupUsers 与 3179-3182 帮助文案;组长候选为 2026-11-18 新增口径。 */
|
||
|
||
const USERS = [
|
||
{ id: 1, username: '组长A', role: 'admin', createdById: null },
|
||
{ id: 2, username: '员工A1', role: 'normal', createdById: 1 },
|
||
{ id: 3, username: '员工A2', role: 'normal', createdById: 1 },
|
||
{ id: 4, username: '别人员工', role: 'normal', createdById: 9 },
|
||
{ id: 5, username: '另一个管理员', role: 'admin', createdById: null },
|
||
{ id: 6, username: '超管本人', role: 'super_admin', createdById: null },
|
||
{ id: 7, username: '别家公司超管', role: 'company_super_admin', createdById: null },
|
||
]
|
||
|
||
test('align_group_eligible_super_admin_sees_all_except_leader_and_super_roles', () => {
|
||
// 站点超管操作者:候选 = 全部账号(除组长本人),但超管两档永不入组(2026-10-07 收口)。
|
||
// 以前这里 return true 放行一切,别的公司的 company_super_admin 会被拉进本公司分组当组员。
|
||
const result = eligibleGroupMembers(USERS, 1, 'super_admin')
|
||
assert.deepEqual(result.map((u) => u.id), [2, 3, 4, 5])
|
||
})
|
||
|
||
test('align_group_eligible_excludes_both_super_admin_flavours_for_non_super_too', () => {
|
||
// 非超管分支本来就只放 normal,两档超管同样进不来——反向钉住「收紧不许只落在一侧」。
|
||
const result = eligibleGroupMembers(USERS, null, 'company_super_admin')
|
||
assert.deepEqual(result.map((u) => u.id), [])
|
||
})
|
||
|
||
test('align_group_eligible_non_super_only_own_normal_employees', () => {
|
||
// 管理员/组长:候选 = created_by=组长本人的普通账号,别人名下/管理员/超管不可选。
|
||
const result = eligibleGroupMembers(USERS, 1, 'admin')
|
||
assert.deepEqual(result.map((u) => u.id), [2, 3])
|
||
})
|
||
|
||
test('align_group_eligible_excludes_leader_self', () => {
|
||
// 组长本人永不进候选(即使是 normal 且归属自己)。
|
||
const withSelf = [{ id: 1, username: '组长', role: 'normal', createdById: 1 }, ...USERS]
|
||
const result = eligibleGroupMembers(withSelf, 1, 'super_admin')
|
||
assert.equal(result.some((u) => u.id === 1), false)
|
||
})
|
||
|
||
test('align_group_eligible_null_leader_means_own_created_only_for_non_super', () => {
|
||
// 组长 id 缺失时按字符串比较兜底,不误匹配。
|
||
const result = eligibleGroupMembers(USERS, null, 'admin')
|
||
assert.equal(result.length, 0)
|
||
})
|
||
|
||
test('align_group_candidate_hint_with_candidates', () => {
|
||
assert.match(groupMemberCandidateHint(3, 'admin'), /可添加当前组长创建的普通员工账号/)
|
||
})
|
||
|
||
test('align_group_candidate_hint_empty_for_normal', () => {
|
||
assert.match(groupMemberCandidateHint(0, 'normal'), /普通账号没有下属普通员工时,这里会为空;当前账号只能作为组长使用。/)
|
||
})
|
||
|
||
test('align_group_candidate_hint_empty_for_admin', () => {
|
||
assert.match(groupMemberCandidateHint(0, 'admin'), /当前组长名下暂无可添加的普通员工账号。/)
|
||
})
|
||
|
||
test('align_group_editor_dialog_ui_wiring', () => {
|
||
// UI 接线:候选请求 page_size=999;组长默认当前登录用户,新建+站点超管出改选下拉
|
||
// (2026-11-18 用户口径「新建分组组长要能下拉选」),编辑与非超管仍只读;候选/提示走新模型。
|
||
const dialog = readSource('src/pages/account/GroupEditorDialog.vue')
|
||
assert.match(dialog, /pageSize:\s*999/, '候选列表按参考 page_size=999 拉取')
|
||
assert.match(dialog, /canPickLeader/, '组长下拉按「新建+站点超管」条件渲染')
|
||
assert.match(dialog, /v-if="canPickLeader"/, '下拉分支挂在 canPickLeader 上')
|
||
assert.match(dialog, /eligibleGroupLeaders/, '组长候选走 eligibleGroupLeaders 过滤')
|
||
assert.match(dialog, /v-else :model-value="leaderUsername" readonly/, '编辑与非超管新建仍走只读回显')
|
||
assert.match(dialog, /当前登录用户/, '只读回显保留当前登录用户兜底')
|
||
assert.match(dialog, /memberIds\.value\.filter/, '组长改选后把该人从组员里摘掉(后端拒绝组长重复入组)')
|
||
assert.match(dialog, /createShopGroup\(groupName\.value, memberIds\.value, leaderId/,
|
||
'创建提交 createdById=所选组长(站点超管改选通道,后端 validateLeaderOperator 放行)')
|
||
assert.match(dialog, /eligibleGroupMembers/, '组员候选走归属过滤')
|
||
assert.match(dialog, /groupMemberCandidateHint/, '候选提示文案走对齐逻辑')
|
||
assert.match(dialog, /companyId:\s*session\.user\?\.companyId \?\? null/,
|
||
'候选必须按操作者那家取人:组长必须与操作者同公司(后端 ensureLeaderSharesOperatorCompany),不带时站点超管会拿到全平台账号')
|
||
assert.doesNotMatch(dialog, /companyTab/, '分组候选不能按公司 tab 取人——超管停在别家 tab 时会列出那家的人,保存必被后端打回')
|
||
const page = readSource('src/pages/account/GroupsPage.vue')
|
||
assert.match(page, /创建时间/, '列表补创建时间列')
|
||
assert.doesNotMatch(page, /slice\(0,\s*10\)/, '组员 chips 全量渲染不再收 +N')
|
||
})
|
||
|
||
test('align_group_leader_candidates_site_super_keeps_self_drops_company_super', () => {
|
||
// 组长候选:公司超管永不领衔;站点超管只保留操作者本人(保持 admin 自建组的既有能力)。
|
||
const result = eligibleGroupLeaders(USERS, 'super_admin', 6)
|
||
assert.deepEqual(result.map((u) => u.id), [1, 2, 3, 4, 5, 6])
|
||
})
|
||
|
||
test('align_group_leader_candidates_non_super_operator_drops_all_supers', () => {
|
||
// 非站点超管操作者:两档超管全部出局(弹窗此时不出下拉,这里是同池复用方的兜底口径)。
|
||
const result = eligibleGroupLeaders(USERS, 'admin', 1)
|
||
assert.deepEqual(result.map((u) => u.id), [1, 2, 3, 4, 5])
|
||
})
|
||
|
||
test('align_group_leader_candidates_normal_accounts_can_lead', () => {
|
||
// 普通账号可领衔(既有文案背书:「当前账号只能作为组长使用」)。
|
||
const normals = USERS.filter((u) => u.role === 'normal')
|
||
const result = eligibleGroupLeaders(normals, 'super_admin', 6)
|
||
assert.deepEqual(result.map((u) => u.id), [2, 3, 4])
|
||
})
|
||
|
||
test('align_group_backend_gate_super_never_joins_and_leader_shares_company', () => {
|
||
// 界面收窄只是少踩一次;这两条 403 才是出口。锚在调用点与抛出语句,不锚注释。
|
||
const java = readSource(
|
||
'../backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/service/ShopManageGroupService.java',
|
||
)
|
||
assert.match(java, /"超级管理员不属于任何分组"/)
|
||
assert.match(java, /if \(siteSuper \|\| "company_super_admin"\.equals\(memberRole\)\)/,
|
||
'站点超管走 DeviceSessionPolicy 唯一出口,公司超管比 resolveRole 的结果——都不在本文件里写 super_admin 字面量')
|
||
assert.match(java, /if \(leaderCompanyId != null && !leaderCompanyId\.equals\(user\.getCompanyId\(\)\)\)/,
|
||
'组员必须与组长同公司(分组表没有 company_id 列,归属只能从组长推)')
|
||
assert.match(java, /ensureLeaderSharesOperatorCompany\(createdById, operatorId\);/, '新建:组长必须与操作者同公司')
|
||
assert.match(java, /ensureLeaderSharesOperatorCompany\(resolveGroupLeaderUserId\(entity\), normalizedOperatorId\);/,
|
||
'改删:站点超管也按组长公司收窄,不能只靠"读侧藏起来"')
|
||
})
|