This commit is contained in:
2026-09-01 11:38:42 +08:00
parent 68b584128c
commit 9a3b408de0
7 changed files with 82 additions and 46 deletions
+13 -18
View File
@@ -29,13 +29,7 @@ export const PRODUCT_CATALOG = [
{ cargoName: '宠物橡胶玩具', cargoNameEn: 'Pet rubber toy', hsCode: '4016999090', material: '天然橡胶 / Natural rubber', usage: '宠物玩耍 / Pet play', brand: 'PETTEST', modelPrefix: 'PET', lengthCm: 46, widthCm: 36, heightCm: 34, unitsPerPackage: 48, cartonGrossWeightKg: 15.6, unitDeclaredValue: 3.4, productLengthCm: 12, productWidthCm: 7, productHeightCm: 7 },
]
// Local test-environment settings. Keep PASSWORD empty in committed code.
const CONFIG = {
GATEWAY: 'http://8.163.30.128:9000',
USERNAME: '17512095155',
PASSWORD: 'M4mmp4YWcH5DiYPT',
COUNT: 50,
}
const DEFAULT_COUNT = 50
export function parseArguments(values) {
const options = {}
@@ -58,7 +52,7 @@ export function parseArguments(values) {
}
export function validateCount(value) {
const count = Number(value ?? CONFIG.COUNT)
const count = Number(value ?? DEFAULT_COUNT)
if (!Number.isInteger(count) || count < 1 || count > MAX_COUNT) {
throw new Error(`--count must be an integer between 1 and ${MAX_COUNT}`)
}
@@ -342,12 +336,13 @@ function printHelp() {
node scripts/create-pending-review-orders.mjs --gateway <url> --count <1-${MAX_COUNT}> [--same-channel]
Environment:
CLIENT_TEST_GATEWAY Test environment Gateway URL
ADMIN_TEST_GATEWAY Test environment Gateway URL
MERCHANT_TEST_PASSWORD Password for the configured fixed account
MERCHANT_TEST_USERNAME Optional username override
MERCHANT_TEST_USERNAME Username for the configured fixed account
PENDING_REVIEW_ORDER_COUNT Optional order count, defaults to ${DEFAULT_COUNT}
PENDING_ORDER_REPORT Optional JSON report path
The GATEWAY, USERNAME, PASSWORD, and COUNT fields can also be filled in CONFIG at the top of this file.`)
Command-line arguments override environment variables. Credentials must not be written into this file.`)
}
export async function main(argv = process.argv.slice(2)) {
@@ -356,13 +351,13 @@ export async function main(argv = process.argv.slice(2)) {
printHelp()
return 0
}
const gateway = trimSlash(args.gateway ?? process.env.CLIENT_TEST_GATEWAY ?? CONFIG.GATEWAY)
if (!gateway) throw new Error('Gateway is required via CONFIG.GATEWAY, --gateway, or CLIENT_TEST_GATEWAY')
const count = validateCount(args.count)
const username = args.username ?? process.env.MERCHANT_TEST_USERNAME ?? CONFIG.USERNAME
const password = args.password ?? process.env.MERCHANT_TEST_PASSWORD ?? CONFIG.PASSWORD
if (!username) throw new Error('Fixed merchant username is required in CONFIG.USERNAME')
if (!password) throw new Error('Merchant password is required in CONFIG.PASSWORD or MERCHANT_TEST_PASSWORD')
const gateway = trimSlash(args.gateway ?? process.env.ADMIN_TEST_GATEWAY)
if (!gateway) throw new Error('Gateway is required via --gateway or ADMIN_TEST_GATEWAY')
const count = validateCount(args.count ?? process.env.PENDING_REVIEW_ORDER_COUNT)
const username = args.username ?? process.env.MERCHANT_TEST_USERNAME
const password = args.password ?? process.env.MERCHANT_TEST_PASSWORD
if (!username) throw new Error('Merchant username is required via --username or MERCHANT_TEST_USERNAME')
if (!password) throw new Error('Merchant password is required via --password or MERCHANT_TEST_PASSWORD')
const timeoutMs = Number(args['timeout-ms'] ?? process.env.CLIENT_TEST_TIMEOUT_MS ?? 30_000)
if (!Number.isFinite(timeoutMs) || timeoutMs < 1_000) throw new Error('--timeout-ms must be at least 1000')