build / task (16.x, npm, macOS-latest) (push) Canceled after 0s
build / task (16.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, npm, windows-latest) (push) Canceled after 0s
build / task (16.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (16.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (16.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (16.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, yarn, windows-latest) (push) Canceled after 0s
build / task (18.x, npm, macOS-latest) (push) Canceled after 0s
build / task (18.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, npm, windows-latest) (push) Canceled after 0s
build / task (18.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (18.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (18.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (18.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, yarn, windows-latest) (push) Canceled after 0s
build / task (20.x, npm, macOS-latest) (push) Canceled after 0s
build / task (20.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, npm, windows-latest) (push) Canceled after 0s
build / task (20.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (20.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (20.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (20.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, yarn, windows-latest) (push) Canceled after 0s
57 lines
2.8 KiB
JavaScript
57 lines
2.8 KiB
JavaScript
const { test } = require("node:test")
|
|
const assert = require("node:assert/strict")
|
|
const fs = require("node:fs")
|
|
const path = require("node:path")
|
|
const ts = require("typescript")
|
|
|
|
// 项目尚未配置前端测试框架,使用现有 TypeScript 与 Node 测试业务状态判断。
|
|
const source = fs.readFileSync(path.join(__dirname, "../src/views/hard/hard-third-order/order.ts"), "utf8")
|
|
const compiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }).outputText
|
|
const loaded = { exports: {} }
|
|
new Function("module", "exports", compiled)(loaded, loaded.exports)
|
|
const { orderState, refundState, refundDisabledReason, remainingPrice, apiResult, refundTime } = loaded.exports
|
|
const paid = {
|
|
id: "90071992547409931",
|
|
orderType: "6",
|
|
orderStatus: "5",
|
|
payType: "3",
|
|
walletId: "123",
|
|
payTime: "2026-10-21 10:00:00",
|
|
payPrice: 1000,
|
|
refundPrice: 0,
|
|
}
|
|
|
|
test("共享退款状态码仍区分部分退款与全额退款", () => {
|
|
const partial = { ...paid, orderStatus: "10", refundPrice: 200 }
|
|
const full = { ...partial, refundPrice: 1000 }
|
|
assert.equal(orderState(partial).label, "已部分退款")
|
|
assert.equal(orderState(full).label, "已全额退款")
|
|
assert.equal(remainingPrice(partial), 800)
|
|
assert.equal(refundDisabledReason(partial), "")
|
|
assert.equal(refundDisabledReason(full), "订单已全额退款")
|
|
})
|
|
|
|
test("待支付订单和其他业务订单不提供钱包退款", () => {
|
|
assert.equal(remainingPrice({ ...paid, orderStatus: "1", payTime: undefined }), 0)
|
|
assert.equal(refundDisabledReason({ ...paid, orderStatus: "1", payTime: undefined }), "订单尚未完成支付")
|
|
assert.equal(refundDisabledReason({ ...paid, orderType: "1" }), "仅支持第三方应用支付底单")
|
|
assert.equal(refundDisabledReason({ ...paid, payType: "10" }), "该支付方式不支持底单钱包退款")
|
|
})
|
|
|
|
test("售后申请中即使底单状态尚未同步也不能重复退款", () => {
|
|
assert.equal(refundDisabledReason(paid, [{ id: "456", status: "10" }]), "存在处理中的退款")
|
|
assert.equal(refundState({ ...paid, refundStatus: "10", refundPrice: 200 }).label, "退款处理中")
|
|
})
|
|
|
|
test("历史售后无退款时间时使用审核时间", () => {
|
|
assert.equal(refundTime({ status: "50", auditTime: "2026-10-21 10:02:00", createTime: "2026-10-21 10:01:00" }), "2026-10-21 10:02:00")
|
|
assert.equal(refundTime({ status: "10", auditTime: "2026-10-21 10:02:00", createTime: "2026-10-21 10:01:00" }), "2026-10-21 10:01:00")
|
|
})
|
|
|
|
test("接口 HTTP 成功与业务支付成功分别判断,坏日志不误报成功", () => {
|
|
assert.equal(apiResult({ res: '{"code":200}' }).type, "success")
|
|
assert.equal(apiResult({ res: '{"code":505,"message":"用户余额不足"}' }).label, "用户余额不足")
|
|
assert.equal(apiResult({ error: "timeout", res: '{"code":200}' }).type, "danger")
|
|
assert.equal(apiResult({ res: "invalid-json" }).label, "查看响应")
|
|
})
|