- 新增后台人工充值模块,支持上传支付凭证 - 新增支付结果查询接口及页面 - 新增订单支付成功跳转结果页逻辑 - 更新钱包流水类型标签区分充值方式 - 新增插件路由 PHP 8 兼容错误报告设置
39 行
2.3 KiB
JavaScript
39 行
2.3 KiB
JavaScript
const assert = require('assert');
|
|
const { execFileSync } = require('child_process');
|
|
const http = require('http');
|
|
const mysql = process.env.MYSQL_BIN;
|
|
const base = process.env.API_BASE || 'http://yjyf:9560/api';
|
|
function sql(query) {
|
|
return execFileSync(mysql, ['-h127.0.0.1', '-u' + process.env.DB_USER, '-D' + process.env.DB_NAME, '-N', '-B', '-e', query], { encoding: 'utf8' }).trim();
|
|
}
|
|
function request(path, data, token) {
|
|
return new Promise((resolve, reject) => {
|
|
const body = data && new URLSearchParams(data).toString();
|
|
const url = new URL(base + path);
|
|
const req = http.request(url, { method: body ? 'POST' : 'GET', headers: { ...(body ? {'content-type': 'application/x-www-form-urlencoded', 'content-length': Buffer.byteLength(body)} : {}), ...(token ? {token} : {}) } }, res => {
|
|
let text = ''; res.on('data', chunk => text += chunk); res.on('end', () => { try { resolve(JSON.parse(text)); } catch (e) { reject(e); } });
|
|
});
|
|
req.on('error', reject); if (body) req.write(body); req.end();
|
|
});
|
|
}
|
|
(async () => {
|
|
const login = await request('/auth/login', {mobile: process.env.TEST_MOBILE, password: process.env.TEST_PASSWORD});
|
|
assert.strictEqual(login.code, 1, 'login failed');
|
|
const {token, userinfo} = login.data;
|
|
const uid = Number(userinfo.id);
|
|
assert(Number.isInteger(uid) && uid > 0);
|
|
for (const type of ['all', 'recharge', 'consume', 'refund']) {
|
|
const filter = type === 'all' ? '' : ` AND type='${type}'`;
|
|
const expected = sql(`SELECT id FROM fa_wallet_log WHERE user_type='user' AND user_id=${uid}${filter} ORDER BY id DESC`);
|
|
const ids = expected ? expected.split(/\s+/).map(Number) : [];
|
|
for (const page of [1, 2]) {
|
|
const res = await request(`/user/walletLogs?type=${type}&page=${page}&limit=3`, null, token);
|
|
assert.strictEqual(res.code, 1, `${type} page ${page} request failed`);
|
|
assert.strictEqual(res.data.total, ids.length, `${type} total`);
|
|
assert.deepStrictEqual(res.data.list.map(row => row.id), ids.slice((page - 1) * 3, page * 3), `${type} page ${page} must contain only matching user records`);
|
|
assert.strictEqual(res.data.has_more, page * 3 < ids.length, `${type} has_more`);
|
|
}
|
|
}
|
|
console.log('Wallet bill user, type, count and pagination checks passed');
|
|
})().catch(err => { console.error(err); process.exitCode = 1; });
|