78 lines
4.5 KiB
JavaScript
78 lines
4.5 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-ledger.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/credits-wallet-ledger.php')
|
|
const wallet = read('inc/helpers/user-center-renderers/credits-wallet.php') + read('inc/helpers/user-center-renderers/credits-wallet-ledger.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'\]/)
|
|
}
|
|
})
|
|
|
|
test('user withdrawal history uses one paginated ten-item endpoint', () => {
|
|
const controller = read('src/Payment/CommissionLedger.php')
|
|
const renderer = read('inc/helpers/user-center-renderers/credits-wallet.php')
|
|
const script = read('assets/js/credits.js')
|
|
const styles = read('assets/css/routes/user-center/credits.css')
|
|
|
|
assert.match(controller, /\$withdrawal_args\['per_page'\]\['default'\]\s*=\s*10/)
|
|
assert.match(controller, /\$withdrawal_args\['per_page'\]\['maximum'\]\s*=\s*10/)
|
|
assert.match(controller, /'total'\s*=>\s*\$total/)
|
|
assert.match(controller, /'max_pages'\s*=>\s*\$max_pages/)
|
|
assert.match(controller, /'user_id'\s*=>\s*\$user_id/)
|
|
assert.doesNotMatch(renderer, /get_user_withdrawals\(/)
|
|
assert.doesNotMatch(renderer, /withdraw_history/)
|
|
assert.match(renderer, /data-aksrt-withdraw-history-list/)
|
|
assert.match(script, /\/earnings\/withdrawals\?page=/)
|
|
assert.match(script, /&per_page=10/)
|
|
assert.match(script, /data-aksrt-withdraw-history-page/)
|
|
assert.match(styles, /\.uc-withdraw-history-modal__dialog\s*\{[\s\S]*?max-width: min\(860px/)
|
|
assert.match(styles, /\.uc-withdraw-history__item\s*\{[\s\S]*?display: flex/)
|
|
assert.match(styles, /\.uc-withdraw-history-modal__dialog\s*\{[\s\S]*?overflow: hidden/)
|
|
})
|