feat:拼单订单新增一个取消部分的按钮功能,点击之后,打手进行中和待接单的都会取消订单
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
resolveSharingPartCancelPlan,
|
||||
resolveSharingPartCancelRefund,
|
||||
} from './work-order-sharing-part-cancel.js'
|
||||
|
||||
test('取消部分:保留已验收份数,取消进行中 + 待接单份数', () => {
|
||||
const plan = resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'open',
|
||||
totalQuantity: 10,
|
||||
acceptedQuantity: 8,
|
||||
})
|
||||
assert.deepEqual(plan, { nextTotalQuantity: 8, cancelledQuantity: 2, failureReason: null })
|
||||
})
|
||||
|
||||
test('取消部分:一份都没验收时整单取消(总量归零)', () => {
|
||||
const plan = resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'pending_acceptance',
|
||||
totalQuantity: 10,
|
||||
acceptedQuantity: 0,
|
||||
})
|
||||
assert.deepEqual(plan, { nextTotalQuantity: 0, cancelledQuantity: 10, failureReason: null })
|
||||
})
|
||||
|
||||
test('取消部分:全部份额已验收时没有可取消份数', () => {
|
||||
const plan = resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'accepted',
|
||||
totalQuantity: 8,
|
||||
acceptedQuantity: 8,
|
||||
})
|
||||
// accepted 不在允许状态里,优先报状态非法
|
||||
assert.equal(plan.failureReason, 'status_invalid')
|
||||
|
||||
const openPlan = resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'open',
|
||||
totalQuantity: 8,
|
||||
acceptedQuantity: 8,
|
||||
})
|
||||
assert.deepEqual(openPlan, {
|
||||
nextTotalQuantity: 8,
|
||||
cancelledQuantity: 0,
|
||||
failureReason: 'nothing_to_cancel',
|
||||
})
|
||||
})
|
||||
|
||||
test('取消部分:问题单允许操作,已取消/已验收单不允许', () => {
|
||||
assert.equal(
|
||||
resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'problem',
|
||||
totalQuantity: 3,
|
||||
acceptedQuantity: 1,
|
||||
}).failureReason,
|
||||
null,
|
||||
)
|
||||
for (const status of ['cancelled', 'accepted', 'unassigned']) {
|
||||
assert.equal(
|
||||
resolveSharingPartCancelPlan({
|
||||
workOrderStatus: status,
|
||||
totalQuantity: 3,
|
||||
acceptedQuantity: 0,
|
||||
}).failureReason,
|
||||
'status_invalid',
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('取消部分:已验收份数异常时按总量截断', () => {
|
||||
const plan = resolveSharingPartCancelPlan({
|
||||
workOrderStatus: 'open',
|
||||
totalQuantity: 5,
|
||||
acceptedQuantity: 9,
|
||||
})
|
||||
assert.deepEqual(plan, {
|
||||
nextTotalQuantity: 5,
|
||||
cancelledQuantity: 0,
|
||||
failureReason: 'nothing_to_cancel',
|
||||
})
|
||||
})
|
||||
|
||||
test('取消部分退款:按实付金额比例计算并四舍五入到分', () => {
|
||||
assert.equal(
|
||||
resolveSharingPartCancelRefund({
|
||||
paidAmountFen: 20000,
|
||||
totalQuantity: 10,
|
||||
cancelledQuantity: 9,
|
||||
}),
|
||||
18000,
|
||||
)
|
||||
assert.equal(
|
||||
resolveSharingPartCancelRefund({ paidAmountFen: 999, totalQuantity: 3, cancelledQuantity: 1 }),
|
||||
333,
|
||||
)
|
||||
assert.equal(
|
||||
resolveSharingPartCancelRefund({ paidAmountFen: 0, totalQuantity: 10, cancelledQuantity: 10 }),
|
||||
0,
|
||||
)
|
||||
// 取消份数超过总量时按总量截断
|
||||
assert.equal(
|
||||
resolveSharingPartCancelRefund({ paidAmountFen: 5000, totalQuantity: 5, cancelledQuantity: 8 }),
|
||||
5000,
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user