813ab5db7b
新增 shop-manage-edit-form.ts(店铺行预填编辑字段,密码掩码不回填需重录),
补充 toShopManageUpdateRequest(不含 createdById),并在 shop-manage-api.ts 增加
submitUpdateShopManage(PUT /api/admin/shop-manages/{id})。
TDD: task-92.test.ts 8 用例先 RED 后 GREEN。
87 lines
4.1 KiB
TypeScript
87 lines
4.1 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import { buildShopManageEditForm } from '../src/pages/shop/shop-manage-edit-form.ts'
|
|
import { toShopManageUpdateRequest, validateShopManageForm } from '../src/pages/shop/shop-manage-form-model.ts'
|
|
import type { ShopSummary } from '../src/pages/shop/shop-dto.ts'
|
|
|
|
function row(id: number, over: Partial<ShopSummary> = {}): ShopSummary {
|
|
return { id, groupId: 3, groupName: '华东组', shopName: '', mallName: '', znUsername: '', account: '', ...over }
|
|
}
|
|
|
|
test('test_task_092_shop_manage_edit_form_normal_primary_path', () => {
|
|
// 正常主路径:由店铺行预填可编辑字段;密码需重新录入(掩码不回填)。
|
|
const form = buildShopManageEditForm(row(9, { groupId: 3, shopName: 'BlueWave', mallName: 'M', znUsername: 'robot', account: 'a@b.c', passwordMasked: '******' }))
|
|
assert.ok(form)
|
|
assert.equal(form!.groupId, 3)
|
|
assert.equal(form!.shopName, 'BlueWave')
|
|
assert.equal(form!.mallName, 'M')
|
|
assert.equal(form!.znUsername, 'robot')
|
|
assert.equal(form!.account, 'a@b.c')
|
|
assert.equal(form!.password, '', '掩码不回填为明文')
|
|
const filled = { ...form!, password: 'new-pw' }
|
|
const { valid } = validateShopManageForm(filled)
|
|
assert.equal(valid, true)
|
|
const request = toShopManageUpdateRequest(filled)
|
|
assert.equal(request.groupId, 3)
|
|
assert.equal(request.password, 'new-pw')
|
|
assert.equal('createdById' in request, false, '更新请求体不带 createdById')
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_normal_variant_input', () => {
|
|
// 正常变体:无分组行回填为空分组待重选。
|
|
const form = buildShopManageEditForm(row(4, { groupId: null, shopName: 'RedSun' }))
|
|
assert.ok(form)
|
|
assert.equal(form!.groupId, null)
|
|
assert.equal(form!.shopName, 'RedSun')
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_repeated_is_idempotent', () => {
|
|
// 正常重复:预填不改原记录、结果稳定。
|
|
const item = row(2, { shopName: 'S', account: 'a' })
|
|
const first = buildShopManageEditForm(item)
|
|
const second = buildShopManageEditForm(item)
|
|
assert.deepEqual(first, second)
|
|
assert.equal(item.shopName, 'S')
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_boundary_empty_input', () => {
|
|
// 边界空值:缺省可选字段回填为空串且结构完整。
|
|
const form = buildShopManageEditForm(row(1))
|
|
assert.ok(form)
|
|
assert.equal(form!.znUsername, '')
|
|
assert.equal(form!.mallName, '')
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_boundary_single_item', () => {
|
|
// 边界单元素:仅 id/店铺名的最小行仍可预填。
|
|
const form = buildShopManageEditForm({ id: 6, groupId: 1, groupName: 'g', shopName: 'X', mallName: '', znUsername: '', account: '', createdAt: 't' } as ShopSummary)
|
|
assert.ok(form)
|
|
assert.equal(form!.shopName, 'X')
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_boundary_limit_or_missing_field', () => {
|
|
// 边界上限/缺字段:账号名/店铺名按行值保留,不因掩码显示而截断。
|
|
const longAccount = 'u'.repeat(200)
|
|
const form = buildShopManageEditForm(row(7, { account: longAccount, shopName: '长店名'.repeat(30) }))
|
|
assert.ok(form)
|
|
assert.equal(form!.account, longAccount)
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_invalid_input_rejected', () => {
|
|
// 异常输入:空记录/缺 id 无法构建编辑表单。
|
|
assert.equal(buildShopManageEditForm(null as unknown as ShopSummary), null)
|
|
assert.equal(buildShopManageEditForm({ id: Number.NaN } as unknown as ShopSummary), null)
|
|
})
|
|
|
|
test('test_task_092_shop_manage_edit_form_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败/提交走 adapter:编辑模型纯逻辑,adapter PUT /api/admin/shop-manages/{id}。
|
|
const model = readSource('src/pages/shop/shop-manage-edit-form.ts')
|
|
assert.equal(/axios|http\.|vue/.test(model), false, '编辑模型保持纯逻辑')
|
|
assert.match(model, /掩码|敏感/)
|
|
const api = readSource('src/pages/shop/shop-manage-api.ts')
|
|
assert.match(api, /submitUpdateShopManage/)
|
|
assert.match(api, /http\.put/)
|
|
assert.match(api, /\/api\/admin\/shop-manages/)
|
|
})
|