97 行
3.9 KiB
JavaScript
97 行
3.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
function assert(condition, testName, detail = '') {
|
|
if (condition) {
|
|
console.log(` [PASS] ${testName}`);
|
|
passed++;
|
|
} else {
|
|
console.error(` [FAIL] ${testName} - ${detail}`);
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
console.log("========================================================");
|
|
console.log(" 订单/分润数据清理与dmepa汇率回归初始值规范自动化测试");
|
|
console.log("========================================================\n");
|
|
|
|
// 1. 验证控制台清理命令 PartnerClean.php 存在且逻辑完整
|
|
const cleanCmdPath = path.resolve(__dirname, '../addons/shopro/console/PartnerClean.php');
|
|
assert(fs.existsSync(cleanCmdPath), 'PartnerClean.php 控制台命令文件存在');
|
|
const cleanCmdContent = fs.readFileSync(cleanCmdPath, 'utf-8');
|
|
|
|
assert(
|
|
cleanCmdContent.includes("shopro:partner:clean"),
|
|
'命令名称定义为 shopro:partner:clean'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("shopro_order") && cleanCmdContent.includes("shopro_order_item") && cleanCmdContent.includes("shopro_order_aftersale"),
|
|
'涵盖清理商城订单主表、明细表与售后表'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("shopro_partner_reward") && cleanCmdContent.includes("shopro_commission_order") && cleanCmdContent.includes("shopro_commission_reward"),
|
|
'涵盖清理二开合伙人流水与分销佣金明细'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("shopro_partner_rate_log") && cleanCmdContent.includes("shopro_partner_daily_report") && cleanCmdContent.includes("shopro_partner_voucher_plan"),
|
|
'涵盖清理dmepa汇率大盘快照、日结对账报表与兑换券释放计划'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("`madow` = 0.00000000") && cleanCmdContent.includes("`direct_order_seq` = 0") && cleanCmdContent.includes("`voucher_total` = 0.00"),
|
|
'涵盖重置分销商持仓dmepa、推三返一序号、兑换券资产归零'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("cache('partner_madow_current_rate', null)"),
|
|
'命令执行后清除dmepa汇率缓存 partner_madow_current_rate'
|
|
);
|
|
assert(
|
|
cleanCmdContent.includes("Db::startTrans()") && cleanCmdContent.includes("Db::commit()"),
|
|
'命令具备严谨的事务控制与异常回滚机制'
|
|
);
|
|
|
|
// 2. 验证 Shopro.php 已注册该 CLI 命令
|
|
const shoproPath = path.resolve(__dirname, '../addons/shopro/Shopro.php');
|
|
assert(fs.existsSync(shoproPath), 'Shopro.php 文件存在');
|
|
const shoproContent = fs.readFileSync(shoproPath, 'utf-8');
|
|
assert(
|
|
shoproContent.includes("'addons\\shopro\\console\\PartnerClean'"),
|
|
'Shopro.php 中已自动注册 PartnerClean CLI 控制台命令'
|
|
);
|
|
|
|
// 3. 验证归档 SQL 文件
|
|
const sqlPath = path.resolve(__dirname, '../docs/sql/clean_order_and_partner_data.sql');
|
|
assert(fs.existsSync(sqlPath), 'clean_order_and_partner_data.sql 归档文件存在');
|
|
const sqlContent = fs.readFileSync(sqlPath, 'utf-8');
|
|
|
|
assert(
|
|
sqlContent.includes("TRUNCATE TABLE `fa_shopro_order`") && sqlContent.includes("TRUNCATE TABLE `fa_shopro_order_item`"),
|
|
'SQL 脚本包含清空订单表与订单项表'
|
|
);
|
|
assert(
|
|
sqlContent.includes("TRUNCATE TABLE `fa_shopro_partner_reward`"),
|
|
'SQL 脚本包含清空二开收益中心流水表'
|
|
);
|
|
assert(
|
|
sqlContent.includes("TRUNCATE TABLE `fa_shopro_partner_rate_log`"),
|
|
'SQL 脚本包含清空dmepa汇率历史快照日志'
|
|
);
|
|
assert(
|
|
sqlContent.includes("`madow` = 0.00000000") && sqlContent.includes("`direct_order_seq` = 0"),
|
|
'SQL 脚本包含重置分销商dmepa与推三返一序号'
|
|
);
|
|
assert(
|
|
sqlContent.includes("START TRANSACTION;") && sqlContent.includes("COMMIT;"),
|
|
'SQL 脚本具备严格的事务包裹'
|
|
);
|
|
|
|
console.log("\n--------------------------------------------------------");
|
|
console.log(`测试执行结果: 通过 ${passed} 项, 失败 ${failed} 项`);
|
|
console.log("========================================================\n");
|
|
|
|
if (failed > 0) {
|
|
process.exit(1);
|
|
}
|