9293cd0976
新增 shop-group-model.ts(ShopManageGroupItemVo 下拉项解析) 并在 shop-manage-api.ts 增加 fetchShopManageGroups(GET /api/admin/shop-manages/groups, 后端限定普通管理员可访问分组)。 TDD: task-90.test.ts 8 用例先 RED 后 GREEN。
73 lines
3.2 KiB
TypeScript
73 lines
3.2 KiB
TypeScript
import test from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readSource } from './helpers.ts'
|
||
import { parseShopManageGroups, toShopGroupOption } from '../src/pages/shop/shop-group-model.ts'
|
||
|
||
test('test_task_090_shop_group_options_load_normal_primary_path', () => {
|
||
// 正常主路径:Java ShopManageGroupItemVo 数组封包解析为分组下拉项。
|
||
const options = parseShopManageGroups({
|
||
success: true,
|
||
data: [
|
||
{ id: 1, groupName: '华东组', memberCount: 3, leaderUsername: '张' },
|
||
{ id: 2, groupName: '华南组', memberCount: 5 },
|
||
],
|
||
})
|
||
assert.equal(options.length, 2)
|
||
assert.equal(options[0].id, 1)
|
||
assert.equal(options[0].groupName, '华东组')
|
||
assert.equal(options[0].memberCount, 3)
|
||
assert.equal(options[0].leaderUsername, '张')
|
||
assert.equal(options[1].id, 2)
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_normal_variant_input', () => {
|
||
// 正常变体:可选字段缺失时下拉仍可用。
|
||
const option = toShopGroupOption({ id: 7, groupName: '备用组' })
|
||
assert.ok(option)
|
||
assert.equal(option.id, 7)
|
||
assert.equal(option.groupName, '备用组')
|
||
assert.equal(option.memberCount, undefined)
|
||
assert.equal(option.leaderUsername, undefined)
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_repeated_is_idempotent', () => {
|
||
// 正常重复:解析同一负载结果稳定、不改输入。
|
||
const payload = { data: [{ id: 1, groupName: 'A', memberCount: 1 }] }
|
||
assert.deepEqual(parseShopManageGroups(payload), parseShopManageGroups(payload))
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_boundary_empty_input', () => {
|
||
// 边界空值:空数组/空负载返回空下拉选项。
|
||
assert.deepEqual(parseShopManageGroups({ data: [] }), [])
|
||
assert.deepEqual(parseShopManageGroups({}), [])
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_boundary_single_item', () => {
|
||
// 边界单元素:单分组可下拉。
|
||
const options = parseShopManageGroups([{ id: 4, groupName: '单组' }])
|
||
assert.equal(options.length, 1)
|
||
assert.equal(options[0].groupName, '单组')
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_boundary_limit_or_missing_field', () => {
|
||
// 边界上限/缺字段:成员数为非数字按缺省处理。
|
||
const option = toShopGroupOption({ id: 2, groupName: '组', memberCount: 'x' })
|
||
assert.equal(option!.memberCount, undefined)
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_invalid_input_rejected', () => {
|
||
// 异常输入:缺 id 的分组不进入下拉;success=false 抛后端 message。
|
||
assert.equal(toShopGroupOption('garbage'), null)
|
||
assert.equal(toShopGroupOption({ groupName: 'no id' }), null)
|
||
assert.throws(() => parseShopManageGroups({ success: false, message: '无权访问分组' }), /无权访问/)
|
||
})
|
||
|
||
test('test_task_090_shop_group_options_load_dependency_failure_returns_actionable_message', () => {
|
||
// 依赖失败/加载走 adapter:GET /api/admin/shop-manages/groups + http.get + 解析。
|
||
const api = readSource('src/pages/shop/shop-manage-api.ts')
|
||
assert.match(api, /\/api\/admin\/shop-manages\/groups/)
|
||
assert.match(api, /fetchShopManageGroups/)
|
||
const model = readSource('src/pages/shop/shop-group-model.ts')
|
||
assert.equal(/axios|http\./.test(model), false, '分组解析保持纯逻辑')
|
||
})
|