From f30c3ff6333b73cd0c87245f32c90db158bccd64 Mon Sep 17 00:00:00 2001 From: chen Date: Thu, 17 Sep 2026 15:52:27 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=B1=86?= =?UTF-8?q?=E5=85=A8=E9=93=BE=E8=B7=AF=E6=95=B4=E6=95=B0=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=B8=8E=E5=A4=A7=E7=9B=98=E4=BB=B7=E5=80=BC=E6=B1=87=E7=8E=87?= =?UTF-8?q?=E6=A0=B8=E7=AE=97=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...verify_madow_dashboard_and_integer_spec.js | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/verify_madow_dashboard_and_integer_spec.js diff --git a/tests/verify_madow_dashboard_and_integer_spec.js b/tests/verify_madow_dashboard_and_integer_spec.js new file mode 100644 index 0000000..934f32d --- /dev/null +++ b/tests/verify_madow_dashboard_and_integer_spec.js @@ -0,0 +1,161 @@ +const fs = require('fs'); +const path = require('path'); +const vm = require('vm'); + +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(" 马豆全链路整数展示与大盘价值汇率核算自动化测试"); +console.log("========================================================\n"); + +// 1. 验证后端核心服务 IdentityService formatMadow 为纯整数格式 +const identityServicePath = path.resolve(__dirname, '../addons/shopro/service/partner/IdentityService.php'); +assert(fs.existsSync(identityServicePath), 'IdentityService.php 文件存在'); +const identityServiceContent = fs.readFileSync(identityServicePath, 'utf-8'); + +assert( + identityServiceContent.includes("number_format((float) $value, 0, '.', '')"), + 'IdentityService::formatMadow() 精度设置为 0 位小数(纯整数输出)' +); +assert( + identityServiceContent.includes("'madow' => '0'"), + 'IdentityService::attachProfile() 兜底马豆默认值为字符整型 \'0\'' +); + +// 2. 验证模型层获取器已覆盖整数输出 +const rewardModelPath = path.resolve(__dirname, '../application/admin/model/shopro/partner/Reward.php'); +assert(fs.existsSync(rewardModelPath), 'Reward.php 模型存在'); +const rewardModelContent = fs.readFileSync(rewardModelPath, 'utf-8'); +assert( + rewardModelContent.includes('function getMadowAttr') && rewardModelContent.includes('IdentityService::formatMadow'), + 'Reward 模型定义了 getMadowAttr 自动使用 IdentityService::formatMadow 格式化' +); + +const dailyReportModelPath = path.resolve(__dirname, '../application/admin/model/shopro/partner/DailyReport.php'); +assert(fs.existsSync(dailyReportModelPath), 'DailyReport.php 模型存在'); +const dailyReportModelContent = fs.readFileSync(dailyReportModelPath, 'utf-8'); +assert( + dailyReportModelContent.includes('function getMadowPoolAttr') && dailyReportModelContent.includes('IdentityService::formatMadow'), + 'DailyReport 模型定义了 getMadowPoolAttr 自动格式化马豆池' +); + +// 3. 验证财务报表导出台账中的马豆格式化 +const rewardControllerPath = path.resolve(__dirname, '../application/admin/controller/shopro/partner/Reward.php'); +assert(fs.existsSync(rewardControllerPath), 'Reward.php 控制器存在'); +const rewardControllerContent = fs.readFileSync(rewardControllerPath, 'utf-8'); +assert( + rewardControllerContent.includes('IdentityService::formatMadow($reward[\'madow\'])'), + 'Excel 台账导出单行马豆使用 IdentityService::formatMadow 纯整数输出' +); +assert( + rewardControllerContent.includes('IdentityService::formatMadow($totalMadow)'), + 'Excel 台账导出合计汇总行马豆使用 IdentityService::formatMadow 纯整数输出' +); + +// 4. 验证订单详情中的马豆发放格式 +const orderControllerPath = path.resolve(__dirname, '../application/admin/controller/shopro/order/Order.php'); +assert(fs.existsSync(orderControllerPath), 'Order.php 控制器存在'); +const orderControllerContent = fs.readFileSync(orderControllerPath, 'utf-8'); +assert( + orderControllerContent.includes("IdentityService::formatMadow($first->madow ?? 0)"), + '订单详情中的每单发放马豆使用 IdentityService::formatMadow 纯整数输出' +); + +// 5. 验证后台大盘后端接口 Dashboard.php 包含马豆价值与汇率核算指标 +const dashboardControllerPath = path.resolve(__dirname, '../application/admin/controller/shopro/Dashboard.php'); +assert(fs.existsSync(dashboardControllerPath), 'Dashboard.php 控制器存在'); +const dashboardControllerContent = fs.readFileSync(dashboardControllerPath, 'utf-8'); +assert( + dashboardControllerContent.includes("'total_madow' => IdentityService::formatMadow($totalMadow)"), + '大盘接口输出 total_madow 采用整数' +); +assert( + dashboardControllerContent.includes("'current_rate' => number_format($currentRate, 10, '.', '')"), + '大盘接口输出 10 位高精度 current_rate 汇率' +); +assert( + dashboardControllerContent.includes("'rate_per_wan' => number_format($currentRate * 10000, 4, '.', '')"), + '大盘接口输出每万豆价值 rate_per_wan' +); +assert( + dashboardControllerContent.includes("'total_madow_cny' => number_format($totalMadowCny, 2, '.', '')"), + '大盘接口输出当前折合总价值 total_madow_cny' +); +assert( + dashboardControllerContent.includes("'history_order_n' => $historyOrderN"), + '大盘接口输出历史累计完成订单数 history_order_n' +); + +// 6. 验证前端仪表盘模板 application/admin/view/shopro/dashboard/index.html 卡片设计 +const dashboardViewPath = path.resolve(__dirname, '../application/admin/view/shopro/dashboard/index.html'); +assert(fs.existsSync(dashboardViewPath), 'dashboard/index.html 视图存在'); +const dashboardViewContent = fs.readFileSync(dashboardViewPath, 'utf-8'); + +assert( + dashboardViewContent.includes('马豆价值与汇率核算'), + '大盘视图包含「马豆价值与汇率核算」卡片标题' +); +assert( + dashboardViewContent.includes('汇率动态增值'), + '大盘视图标签标注「汇率动态增值」' +); +assert( + dashboardViewContent.includes('{{ state.madow.total_madow_cny }}'), + '大盘视图展示当前折合总价值 total_madow_cny' +); +assert( + dashboardViewContent.includes('{{ state.madow.total_madow }} 豆'), + '大盘视图展示全网持豆总量 total_madow' +); +assert( + dashboardViewContent.includes('{{ state.madow.current_rate }}'), + '大盘视图展示 1 豆汇率单价 current_rate' +); +assert( + dashboardViewContent.includes('{{ state.madow.rate_per_wan }}'), + '大盘视图展示每万豆价值 rate_per_wan' +); +assert( + dashboardViewContent.includes('0.00000075 × {{ state.madow.history_order_n }} 单'), + '大盘视图直观呈现汇率计算公式 (0.00000075 × N 单)' +); +assert( + dashboardViewContent.includes('日结池明细 →'), + '大盘卡片底栏包含快捷跳转日结池明细' +); + +// 7. 验证 UniApp 端显示逻辑 +const walletCardPath = path.resolve(__dirname, '../uniapp/sheep/components/s-wallet-card/s-wallet-card.vue'); +assert(fs.existsSync(walletCardPath), 's-wallet-card.vue 组件存在'); +const walletCardContent = fs.readFileSync(walletCardPath, 'utf-8'); +assert( + walletCardContent.includes('Math.floor(parseFloat(value) || 0)'), + 'UniApp 钱包卡片 displayMadow 采用 Math.floor 向下取整显示整数' +); + +const madowPagePath = path.resolve(__dirname, '../uniapp/pages/commission/madow.vue'); +assert(fs.existsSync(madowPagePath), 'madow.vue 页面存在'); +const madowPageContent = fs.readFileSync(madowPagePath, 'utf-8'); +assert( + madowPageContent.includes('formatInt'), + 'UniApp 马豆明细页面声明并应用 formatInt 辅助方法' +); + +console.log("\n--------------------------------------------------------"); +console.log(`测试执行结果: 通过 ${passed} 项, 失败 ${failed} 项`); +console.log("========================================================\n"); + +if (failed > 0) { + process.exit(1); +}