fix(consignment): 寄售价支持低于1元并按分类校验寄售数量上限
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
resolveConsignmentPriceMinYuan,
|
||||
resolveConsignmentQuantityLimit,
|
||||
} from '../src/utils/consignment-publish-limits.ts'
|
||||
|
||||
test('寄售价允许低于1元:未配置最低价时输入框下限为0.01元', () => {
|
||||
assert.equal(resolveConsignmentPriceMinYuan(0), 0.01)
|
||||
assert.equal(resolveConsignmentPriceMinYuan(null), 0.01)
|
||||
assert.equal(resolveConsignmentPriceMinYuan(73), 0.73)
|
||||
assert.equal(resolveConsignmentPriceMinYuan(100), 1)
|
||||
})
|
||||
|
||||
test('寄售数量上限按当前分类的 activeQuantity 计算剩余额度', () => {
|
||||
const config = { inventoryLimit: { enabled: true, maxActiveQuantity: 10 } }
|
||||
const remaining = resolveConsignmentQuantityLimit(config, 3)
|
||||
assert.equal(remaining.enabled, true)
|
||||
assert.equal(remaining.activeQuantity, 3)
|
||||
assert.equal(remaining.remainingQuantity, 7)
|
||||
assert.equal(remaining.blocked, false)
|
||||
|
||||
const full = resolveConsignmentQuantityLimit(config, 10)
|
||||
assert.equal(full.remainingQuantity, 0)
|
||||
assert.equal(full.blocked, true)
|
||||
|
||||
const over = resolveConsignmentQuantityLimit(config, 12)
|
||||
assert.equal(over.remainingQuantity, 0)
|
||||
assert.equal(over.blocked, true)
|
||||
})
|
||||
|
||||
test('寄售数量限制关闭时不校验剩余额度', () => {
|
||||
const disabled = resolveConsignmentQuantityLimit(
|
||||
{ inventoryLimit: { enabled: false, maxActiveQuantity: 10 } },
|
||||
100,
|
||||
)
|
||||
assert.equal(disabled.enabled, false)
|
||||
assert.equal(disabled.remainingQuantity, 0)
|
||||
assert.equal(disabled.blocked, false)
|
||||
})
|
||||
|
||||
test('打手端发布页:价格与数量限制必须走同一套规则', () => {
|
||||
const page = readFileSync(
|
||||
fileURLToPath(new URL('../src/pages/worker/WorkerConsignmentPage.tsx', import.meta.url)),
|
||||
'utf8',
|
||||
)
|
||||
assert.ok(page.includes('resolveConsignmentPriceMinYuan('), '价格下限必须走配置解析函数')
|
||||
assert.ok(page.includes('min={priceMinYuan}'), '价格输入框必须使用配置最低价')
|
||||
assert.ok(!page.includes('Math.max(100, minPriceFen)'), '提交校验不得再强制最低 1 元')
|
||||
assert.ok(!page.includes("message.error('寄售价格不能少于1元')"), '不得再提示最低 1 元')
|
||||
assert.ok(
|
||||
page.includes('resolveConsignmentQuantityLimit('),
|
||||
'数量上限必须按当前分类的 activeQuantity 计算',
|
||||
)
|
||||
assert.ok(page.includes('quantityLimit.remainingQuantity'), '必须展示剩余可寄卖数量')
|
||||
assert.ok(page.includes('quantityLimit.blocked'), '达到上限时必须禁用提交')
|
||||
assert.ok(page.includes('quantityLimit.activeQuantity'), '必须带入当前在售/待审核件数')
|
||||
})
|
||||
@@ -26,11 +26,15 @@ test('打手端:数量字段必须始终渲染,关闭时禁用并灰显 1',
|
||||
page.includes('const quantityLocked = selectedProfile?.config.fields.quantity === false'),
|
||||
'必须由 fields.quantity === false 推导锁定状态',
|
||||
)
|
||||
assert.ok(page.includes('disabled={quantityLocked}'), '锁定时输入框必须禁用')
|
||||
assert.ok(
|
||||
page.includes("extra={quantityLocked ? '该分类数量固定为 1,不可修改' : undefined}"),
|
||||
page.includes('disabled={quantityLocked || quantityLimit.blocked}'),
|
||||
'锁定时或达到数量上限时输入框必须禁用',
|
||||
)
|
||||
assert.ok(
|
||||
page.includes("quantityLocked ? '该分类数量固定为 1,不可修改' : ''"),
|
||||
'锁定时要给出固定 1 的提示',
|
||||
)
|
||||
assert.ok(page.includes('extra={quantityExtra}'), '数量提示必须走统一文案')
|
||||
assert.ok(
|
||||
!page.includes('selectedProfile?.config.fields.quantity !== false ? ('),
|
||||
'不能再按开关隐藏数量字段',
|
||||
|
||||
Reference in New Issue
Block a user