898e8a5ea9
- BatchDeleteActions margin-left:auto 右对齐、不再独占一行,14 页迁入各自筛选/工具行(Users/Groups/Menus/UserSecrets/QueryAsin/AsinInvalid/SkipPrice/DedupeRegistry/ProductCategory/DeviceLogs/DigitalHuman/ShopManage/ShopKeys/BrandGating);主按钮沿用全局 34px 同高,align-batch-toolbar-inline.test.ts 钉形状防回归
- 公司删除:DELETE /api/admin/companies/{id}(仅超管,名下有账号拒并带数量),只收公司行+columns 菜单树(PermissionMenuService.deleteTreeByCompany 与 copyTreeFromTemplate 对称),业务数据不级联;列表 VO 带 user_count 供前端置灰勾选/删除按钮;批量删除按用户管理同形走前端逐条循环
- CompaniesPage 加勾选列+行删除按钮(ops-cell 补 flex-wrap 过 ops-cell-must-wrap),删除后 refreshCompanyDirectory 同步 tab 条
- 测试:CompanyServiceDeleteTest 6+PermissionMenuServiceDeleteTreeTest 2+CompanyVoTest user_count 契约+CompanyControllerEndpointTest 翻转 exposesNoDeleteEndpoint→点名 DELETE 端点+CompanyReadPathMenuGateTest ensureSuperAdmin 3→4(delete 入册)+company-directory/row-buttons 补例;source-pin 基线重生成(265 文件/1859 例)
- 验证:admin-vue vue-tsc rc=0、node --test 1976 全绿、vitest mount 247 全绿;backend test-compile rc=0、Company*/PermissionMenu*/跨切守卫点名全绿(CatchSilenceRatchet 红因=另一路在飞件 JdPublishFillAiService 3 个 catch,归属京东窗不代抬)
90 lines
4.2 KiB
TypeScript
90 lines
4.2 KiB
TypeScript
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { parseCompanyList, parseCompany } from '../src/api/companies-model.ts'
|
||
import {
|
||
COMPANY_NAME_MAX_LENGTH,
|
||
toCompanyPayload,
|
||
validateCompanyDraft,
|
||
} from '../src/api/companies-dto.ts'
|
||
|
||
/** 公司目录(设计文档 §2.3)前端侧:Java VO 是 snake_case,请求 DTO 是 camelCase。 */
|
||
|
||
test('parseCompanyList 按 snake_case 线上字段解析公司列表', () => {
|
||
const payload = {
|
||
success: true,
|
||
data: [
|
||
{ id: 1, company_name: '厦门米椿花', status: 1, remark: '初始公司', created_at: '2026-10-04 01:00:00', updated_at: '2026-10-04 02:00:00' },
|
||
{ id: 2, company_name: '福州数富', status: 0, remark: null },
|
||
],
|
||
}
|
||
assert.deepEqual(parseCompanyList(payload), [
|
||
{ id: 1, companyName: '厦门米椿花', status: 1, remark: '初始公司', createdAt: '2026-10-04 01:00:00', updatedAt: '2026-10-04 02:00:00' },
|
||
{ id: 2, companyName: '福州数富', status: 0, remark: null, createdAt: null, updatedAt: null },
|
||
])
|
||
})
|
||
|
||
test('parseCompanyList 不认 camelCase:证明上一条不是在测兜底', () => {
|
||
const rows = parseCompanyList({ success: true, data: [{ id: 3, companyName: '某某公司', status: 1 }] })
|
||
assert.equal(rows.length, 1)
|
||
assert.equal(rows[0].companyName, '', '线上字段是 company_name,camelCase 不该被读出来')
|
||
})
|
||
|
||
test('parseCompanyList 丢弃无 id 的行并把未知 status 当停用', () => {
|
||
const rows = parseCompanyList({ success: true, data: [
|
||
{ company_name: '没有 id', status: 1 },
|
||
{ id: 4, company_name: '状态未知', status: null },
|
||
] })
|
||
assert.deepEqual(rows, [{ id: 4, companyName: '状态未知', status: 0, remark: null, createdAt: null, updatedAt: null }])
|
||
})
|
||
|
||
test('parseCompanyList 对空/异常负载返回空数组', () => {
|
||
for (const payload of [null, undefined, {}, { success: true, data: null }, 'x']) {
|
||
assert.deepEqual(parseCompanyList(payload), [], `负载 ${JSON.stringify(payload)} 应解析为空列表`)
|
||
}
|
||
})
|
||
|
||
test('parseCompanyList 把 success=false 的后端文案抛出来', () => {
|
||
assert.throws(() => parseCompanyList({ success: false, message: '无权限访问公司目录' }), /无权限访问公司目录/)
|
||
})
|
||
|
||
test('parseCompany 解析单条(新建/改名回包)', () => {
|
||
const item = parseCompany({ success: true, data: { id: 5, company_name: '厦门米椿花', status: 1 } })
|
||
assert.ok(item)
|
||
assert.equal(item.id, 5)
|
||
assert.equal(item.companyName, '厦门米椿花')
|
||
assert.equal(parseCompany({ success: true, data: { company_name: '无 id' } }), null)
|
||
})
|
||
|
||
test('user_count 仅列表解析进 userCount:非零即「名下有账号、删不得」(2026-11-23)', () => {
|
||
const rows = parseCompanyList({ success: true, data: [
|
||
{ id: 1, company_name: '厦门米椿花', status: 1, user_count: 3 },
|
||
{ id: 2, company_name: '福州数富', status: 1, user_count: 0 },
|
||
{ id: 3, company_name: '旧负载', status: 1 },
|
||
{ id: 4, company_name: '脏值', status: 1, user_count: -1 },
|
||
{ id: 5, company_name: '脏值2', status: 1, user_count: 'x' },
|
||
] })
|
||
assert.equal(rows[0].userCount, 3)
|
||
assert.equal(rows[1].userCount, 0, '零账号=可删,字段照带')
|
||
assert.ok(!('userCount' in rows[2]), '旧负载不带该键(按 0 读是消费方的事)')
|
||
assert.ok(!('userCount' in rows[3]), '负数不是合法计数,丢弃')
|
||
assert.ok(!('userCount' in rows[4]), '非数字丢弃')
|
||
// 新建/改名回包不带 user_count:单条解析同样不凭空造键
|
||
const saved = parseCompany({ success: true, data: { id: 6, company_name: '厦门米椿花', status: 1 } })
|
||
assert.ok(saved && !('userCount' in saved))
|
||
})
|
||
|
||
test('公司名必填、去空格后不得为空,且不超过列宽', () => {
|
||
assert.equal(validateCompanyDraft({ companyName: ' ' }), '公司名称不能为空')
|
||
assert.equal(validateCompanyDraft({ companyName: ' 厦门米椿花 ' }), '')
|
||
const tooLong = 'x'.repeat(COMPANY_NAME_MAX_LENGTH + 1)
|
||
assert.match(validateCompanyDraft({ companyName: tooLong }), /长度/)
|
||
})
|
||
|
||
test('toCompanyPayload 发 camelCase 且 trim 公司名', () => {
|
||
assert.deepEqual(toCompanyPayload({ companyName: ' 福州数富 ', status: 1, remark: ' ' }), {
|
||
companyName: '福州数富',
|
||
status: 1,
|
||
remark: null,
|
||
})
|
||
})
|