56 lines
3.2 KiB
JavaScript
56 lines
3.2 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
|
|
const root = path.resolve(__dirname, '../..')
|
|
const read = file => fs.readFileSync(path.join(root, file), 'utf8')
|
|
|
|
test('financial flow and withdrawal numbers use the new-only schema', () => {
|
|
const schema = read('src/Core/DBMigratorPart2.php')
|
|
assert.match(schema, /CREATE TABLE \{\$prefix\}aksrt_financial_flow \([\s\S]*?UNIQUE KEY uniq_flow_number \(flow_number\)/)
|
|
assert.match(schema, /UNIQUE KEY uniq_flow_operation \(operation_key\)/)
|
|
assert.match(schema, /CREATE TABLE \{\$prefix\}aksrt_financial_flow_entry \([\s\S]*?UNIQUE KEY uniq_flow_line \(flow_id, line_no\)/)
|
|
assert.match(schema, /CREATE TABLE \{\$prefix\}aksrt_withdrawal \([\s\S]*?withdrawal_number VARCHAR\(32\) NOT NULL[\s\S]*?UNIQUE KEY uniq_withdrawal_number \(withdrawal_number\)/)
|
|
})
|
|
|
|
test('order settings expose strict flow and withdrawal prefixes', () => {
|
|
const schema = read('assets/admin/src/schema/sections/payment/order.js')
|
|
const provider = read('src/Admin/SchemaProvider.php')
|
|
assert.match(schema, /key:\s*'payment_flow_prefix'[^{\n]*sanitize_type:\s*'business_prefix'[^{\n]*default:\s*'AK'/)
|
|
assert.match(schema, /key:\s*'payment_withdrawal_prefix'[^{\n]*sanitize_type:\s*'business_prefix'[^{\n]*default:\s*'TX'/)
|
|
assert.match(provider, /business_prefix[\s\S]*?BusinessNumber::normalize_prefix/)
|
|
})
|
|
|
|
test('ledger and business state write their flow before commit', () => {
|
|
const ledger = read('src/Ledger/LedgerService.php')
|
|
const order = read('src/Payment/OrderRepositoryCore.php')
|
|
const withdrawal = read('src/Payment/Withdrawal.php')
|
|
assert.ok(ledger.indexOf('record_ledger(') < ledger.indexOf("query('COMMIT')"))
|
|
assert.match(order, /record_order_payment\(\$paid_order, true\)/)
|
|
assert.match(order, /record_order_refund\(\$refunded_order, true\)/)
|
|
assert.match(withdrawal, /record_withdrawal_payout\([\s\S]*?true[\s\S]*?query\('COMMIT'\)/)
|
|
})
|
|
|
|
test('native and front-end surfaces expose immutable business numbers', () => {
|
|
assert.match(read('src/Admin/Native/PayMenus.php'), /PayFlows::PAGE_SLUG/)
|
|
assert.match(read('src/Admin/Native/PayFlows.php'), /流水明细/)
|
|
assert.match(read('src/Admin/Native/PayOrders.php'), /支付流水号/)
|
|
assert.match(read('src/Admin/Native/PayWithdrawals.php'), /提现单号/)
|
|
assert.match(read('src/Payment/UserOrders.php'), /\$view\['flow_number'\]/)
|
|
assert.match(read('assets/js/order-center.js'), /\["流水号", order\.flow_number \|\| "—"\]/)
|
|
assert.match(read('inc/helpers/user-center-renderers/credits-wallet.php'), /withdrawal_number/)
|
|
})
|
|
|
|
test('balance history renders withdrawal numbers from the committed flow', () => {
|
|
const query = read('src/Ledger/LedgerQuery.php')
|
|
const profile = read('inc/helpers/user-center-renderers/profile-credits.php')
|
|
const wallet = read('inc/helpers/user-center-renderers/credits-wallet.php')
|
|
assert.match(query, /LEFT JOIN \{\$flow_table\} f ON f\.ledger_transaction_id = t\.id/)
|
|
assert.match(query, /'withdrawal_number'\s*=>\s*\(string\)/)
|
|
for (const source of [profile, wallet]) {
|
|
assert.match(source, /\['withdraw_hold', 'withdraw_refund'\]/)
|
|
assert.match(source, /\$row\['withdrawal_number'\]/)
|
|
}
|
|
})
|