驳回
This commit is contained in:
110
scripts/tests/agentRechargeActions.test.mjs
Normal file
110
scripts/tests/agentRechargeActions.test.mjs
Normal file
@@ -0,0 +1,110 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtemp, rm, stat } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import * as esbuild from 'esbuild'
|
||||
|
||||
async function resolveSrcAlias(path) {
|
||||
const resolvedPath = join(process.cwd(), 'src', path.slice(2))
|
||||
|
||||
try {
|
||||
if ((await stat(resolvedPath)).isDirectory()) {
|
||||
return join(resolvedPath, 'index.ts')
|
||||
}
|
||||
} catch {
|
||||
// Let esbuild report the original resolution failure.
|
||||
}
|
||||
|
||||
return resolvedPath
|
||||
}
|
||||
|
||||
async function importBundledActions() {
|
||||
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-actions-'))
|
||||
const bundlePath = join(tempDir, 'agentRechargeActions.mjs')
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: ['src/views/finance/agent-recharge/agentRechargeActions.ts'],
|
||||
bundle: true,
|
||||
outfile: bundlePath,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
absWorkingDir: process.cwd(),
|
||||
plugins: [
|
||||
{
|
||||
name: 'alias-src',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^@\// }, async (args) => ({
|
||||
path: await resolveSrcAlias(args.path)
|
||||
}))
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const module = await import(pathToFileURL(bundlePath).href)
|
||||
return {
|
||||
module,
|
||||
cleanup: () => rm(tempDir, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
test('pending agent recharge exposes reject action for admins with rejection permission', async () => {
|
||||
const { module, cleanup } = await importBundledActions()
|
||||
const { buildAgentRechargeActions } = module
|
||||
const row = {
|
||||
id: 42,
|
||||
status: 1,
|
||||
payment_method: 'wechat',
|
||||
payment_voucher_key: []
|
||||
}
|
||||
const handledRows = []
|
||||
|
||||
try {
|
||||
const actions = buildAgentRechargeActions(row, {
|
||||
hasAuth: (permission) => permission === 'agent_recharge:reject',
|
||||
onViewPaymentVoucher: () => {},
|
||||
onConfirmPayment: () => {},
|
||||
onReject: (recharge) => handledRows.push(recharge)
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
actions.map((action) => action.label),
|
||||
['拒绝']
|
||||
)
|
||||
|
||||
actions[0].handler()
|
||||
|
||||
assert.deepEqual(handledRows, [row])
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test('non-pending agent recharge does not expose reject action', async () => {
|
||||
const { module, cleanup } = await importBundledActions()
|
||||
const { buildAgentRechargeActions } = module
|
||||
const row = {
|
||||
id: 42,
|
||||
status: 2,
|
||||
payment_method: 'wechat',
|
||||
payment_voucher_key: []
|
||||
}
|
||||
|
||||
try {
|
||||
const actions = buildAgentRechargeActions(row, {
|
||||
hasAuth: (permission) => permission === 'agent_recharge:reject',
|
||||
onViewPaymentVoucher: () => {},
|
||||
onConfirmPayment: () => {},
|
||||
onReject: () => {}
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
actions.map((action) => action.label),
|
||||
[]
|
||||
)
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
49
scripts/tests/agentRechargeDisplay.test.mjs
Normal file
49
scripts/tests/agentRechargeDisplay.test.mjs
Normal file
@@ -0,0 +1,49 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import * as esbuild from 'esbuild'
|
||||
|
||||
async function importBundledDisplay() {
|
||||
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-display-'))
|
||||
const bundlePath = join(tempDir, 'agentRechargeDisplay.mjs')
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: ['src/views/finance/agent-recharge/agentRechargeDisplay.ts'],
|
||||
bundle: true,
|
||||
outfile: bundlePath,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
absWorkingDir: process.cwd()
|
||||
})
|
||||
|
||||
const module = await import(pathToFileURL(bundlePath).href)
|
||||
return {
|
||||
module,
|
||||
cleanup: () => rm(tempDir, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
test('agent recharge rejection reason display uses backend rejection_reason when present', async () => {
|
||||
const { module, cleanup } = await importBundledDisplay()
|
||||
|
||||
try {
|
||||
assert.equal(module.formatRejectionReason('凭证不清晰'), '凭证不清晰')
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
test('agent recharge rejection reason display falls back to dash when absent', async () => {
|
||||
const { module, cleanup } = await importBundledDisplay()
|
||||
|
||||
try {
|
||||
assert.equal(module.formatRejectionReason(''), '-')
|
||||
assert.equal(module.formatRejectionReason(null), '-')
|
||||
assert.equal(module.formatRejectionReason(undefined), '-')
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
69
scripts/tests/agentRechargeService.test.mjs
Normal file
69
scripts/tests/agentRechargeService.test.mjs
Normal file
@@ -0,0 +1,69 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import * as esbuild from 'esbuild'
|
||||
|
||||
test('agent recharge rejection posts the rejection reason to the order rejection endpoint', async () => {
|
||||
const calls = []
|
||||
const tempDir = await mkdtemp(join(tmpdir(), 'agent-recharge-service-'))
|
||||
const bundlePath = join(tempDir, 'agentRechargeService.mjs')
|
||||
const httpMockPath = join(tempDir, 'httpMock.mjs')
|
||||
|
||||
await writeFile(
|
||||
httpMockPath,
|
||||
`
|
||||
export const calls = globalThis.__agentRechargeHttpCalls
|
||||
export default {
|
||||
post(options) {
|
||||
calls.push(options)
|
||||
return Promise.resolve({ code: 0, data: undefined })
|
||||
}
|
||||
}
|
||||
`,
|
||||
'utf8'
|
||||
)
|
||||
|
||||
globalThis.__agentRechargeHttpCalls = calls
|
||||
|
||||
try {
|
||||
await esbuild.build({
|
||||
entryPoints: ['src/api/modules/agentRecharge.ts'],
|
||||
bundle: true,
|
||||
outfile: bundlePath,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
absWorkingDir: process.cwd(),
|
||||
plugins: [
|
||||
{
|
||||
name: 'mock-http-boundary',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^@\/utils\/http$/ }, () => ({
|
||||
path: httpMockPath
|
||||
}))
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const { AgentRechargeService } = await import(pathToFileURL(bundlePath).href)
|
||||
|
||||
await AgentRechargeService.rejectAgentRecharge(42, {
|
||||
reject_reason: '支付凭证不符合要求'
|
||||
})
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
{
|
||||
url: '/api/admin/agent-recharges/42/reject',
|
||||
data: {
|
||||
reject_reason: '支付凭证不符合要求'
|
||||
}
|
||||
}
|
||||
])
|
||||
} finally {
|
||||
delete globalThis.__agentRechargeHttpCalls
|
||||
await rm(tempDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user