Bläddra i källkod

test: add v3 API test scripts for NEW fix verification

Sisyphus Agent 4 månader sedan
förälder
incheckning
b08f189d39

+ 45 - 0
tests/TEST-RESULTS-v3.md

@@ -0,0 +1,45 @@
+# API 测试报告 v3 — 2026/7/3 08:02:37
+
+| 结果 | 数量 |
+|------|------|
+| ✅ PASS | 0 |
+| ❌ FAIL | 3 |
+| ⏭️ SKIP | 9 |
+| 总计 | 12 |
+
+## FAIL 明细
+
+- **Admin登录**: raw: <html>
+<head><title>502 Bad Gateway</title></head>
+<body>
+<center><h1>502 Bad Gateway</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
+
+- **文章列表(公开)**: code=undefined
+- **活动列表(公开)**: status=502
+
+## 完整结果
+
+| 用例 | 结果 | 详情 |
+|------|------|------|
+| Admin登录 | FAIL | raw: <html>
+<head><title>502 Bad Gateway</title></head>
+<body>
+<center><h1>502 Bad Gateway</h1></center>
+<hr><center>openresty</center>
+</body>
+</html>
+ |
+| Parent登录(手机验证码) | SKIP | 测试环境无法发短信,parent端需手动测试 |
+| 文章列表(公开) | FAIL | code=undefined |
+| 活动列表(公开) | FAIL | status=502 |
+| NEW-01 能量规则创建 | SKIP | 无admin token |
+| NEW-02 SKU列表 | SKIP | 无admin token |
+| NEW-03 活动发布 | SKIP | 无admin token |
+| ISSUE-001 供应商下架 | SKIP | 无admin token |
+| ISSUE-002/003 | SKIP | 无admin token |
+| 能量规则维度查询 | SKIP | 无admin token |
+| 后台管理核心接口 | SKIP | 无admin token |
+| 新增API测试 | SKIP | 无admin token |

+ 171 - 0
tests/run-api-tests-v3-file.js

@@ -0,0 +1,171 @@
+/**
+ * CFC API v3 快速测试 - 文件输出版
+ * 运行: node tests/run-api-tests-v3-file.js
+ */
+const fs = require('fs');
+const path = require('path');
+
+const BASE = 'http://cfc.iwintrue.com:80';
+const ADMIN = { phone: '13800138000', userId: 7 };
+
+let adminToken = null;
+const results = [];
+
+function log(msg) { results.push(`[LOG] ${msg}`); }
+function pass(name, detail) { results.push(`PASS|${name}|${detail || ''}`); }
+function fail(name, err, detail) { results.push(`FAIL|${name}|${err.message}${detail ? '|' + detail : ''}`); }
+function skip(name, reason) { results.push(`SKIP|${name}|${reason}`); }
+
+async function api(path, body, headers = {}) {
+  try {
+    const resp = await fetch(`${BASE}${path}`, {
+      method: 'POST',
+      headers: { 'Content-Type': 'application/json', ...headers },
+      body: body ? JSON.stringify(body) : undefined,
+    });
+    const text = await resp.text();
+    let data;
+    try { data = JSON.parse(text); } catch { data = null; }
+    return { status: resp.status, data, ok: resp.ok, raw: text.substring(0, 200) };
+  } catch (err) {
+    return { ok: false, data: null, error: err.message };
+  }
+}
+
+async function adminApi(path, body) {
+  if (!adminToken) return { ok: false, data: null, error: '无token' };
+  return api(path, body, { Authorization: `Bearer ${adminToken}` });
+}
+
+async function main() {
+  log('=== 登录 ===');
+  await api('/api/admin-auth/send-code', { phone: ADMIN.phone });
+  const loginResp = await api('/api/admin-auth/login', { phone: ADMIN.phone, code: '123456' });
+  if (loginResp.data?.data?.token) {
+    adminToken = loginResp.data.data.token;
+    pass('Admin登录', `userId=${loginResp.data.data.adminId}`);
+  } else {
+    fail('Admin登录', new Error('无token'), loginResp.raw);
+  }
+
+  // NEW-01: 能量规则创建
+  log('=== NEW-01: 能量规则创建 ===');
+  let ruleId = null;
+  const er = await adminApi('/api/admin/energy-rule/create', {
+    ruleName: '自动化测试规则_NEW01_' + Date.now(),
+    dimensionCode: 'body', eventType: 'checkin', energyValue: 5, status: 1,
+  });
+  if (er.ok || er.data?.code === 200) {
+    ruleId = er.data?.data?.id || er.data?.id;
+    pass('NEW-01 创建能量规则', `id=${ruleId}`);
+  } else {
+    fail('NEW-01 创建能量规则', new Error(`code=${er.data?.code} msg=${er.data?.message || ''}`));
+  }
+
+  // NEW-02: SKU列表
+  log('=== NEW-02: SKU列表 ===');
+  const sku = await adminApi('/api/admin/product/sku/list', { productId: 1 });
+  if (sku.ok || sku.data?.code === 200) {
+    const count = Array.isArray(sku.data?.data) ? sku.data.data.length : 0;
+    pass('NEW-02 SKU列表', `count=${count}`);
+  } else {
+    fail('NEW-02 SKU列表', new Error(`code=${sku.data?.code} msg=${sku.data?.message || ''}`));
+  }
+
+  // NEW-03: 活动发布
+  log('=== NEW-03: 活动发布 ===');
+  let actId = null;
+  const act = await adminApi('/api/activity/create', {
+    title: '自动化E2E测试活动_NEW03_' + Date.now(),
+    description: 'NEW-03修复验证',
+    dimensionCode: 'body',
+    startTime: new Date(Date.now() + 86400000 * 7).toISOString().replace('T', ' ').split('.')[0],
+    endTime: new Date(Date.now() + 86400000 * 8).toISOString().replace('T', ' ').split('.')[0],
+    location: '线上直播', maxParticipants: 30,
+  });
+  if (act.ok || act.data?.code === 200) {
+    actId = act.data?.data?.id || act.data?.id;
+    pass('创建测试活动', `id=${actId}`);
+  } else {
+    fail('创建测试活动', new Error(`code=${act.data?.code} msg=${act.data?.message || ''}`));
+  }
+  if (actId) {
+    const pub = await adminApi('/api/activity/publish', { id: actId });
+    if (pub.ok || pub.data?.code === 200) {
+      pass('NEW-03 发布活动', `id=${actId}`);
+    } else {
+      fail('NEW-03 发布活动', new Error(`code=${pub.data?.code} msg=${pub.data?.message || ''}`));
+    }
+  }
+
+  // ISSUE-001: 供应商下架
+  log('=== ISSUE-001: 供应商下架 ===');
+  const vs = await api('/api/product/shelve', { productId: 7, action: 'unshelve' }, { 'X-User-Id': '81069' });
+  if (vs.ok || vs.data?.code === 200) {
+    pass('ISSUE-001 供应商下架', 'ok');
+  } else {
+    fail('ISSUE-001 供应商下架', new Error(`code=${vs.data?.code} msg=${vs.data?.message || ''}`));
+  }
+
+  // ISSUE-003: 创建用户
+  log('=== ISSUE-003: 创建用户 ===');
+  const phone = '139' + String(Math.floor(Math.random() * 1e9)).padStart(9, '0');
+  const cu = await adminApi('/api/admin/users/create', {
+    phone, password: 'Test123456', name: '自动化测试用户', role: 'parent',
+  });
+  if (cu.ok || cu.data?.code === 200) {
+    pass('ISSUE-003 创建用户', `userId=${cu.data?.data?.id || cu.data?.id}`);
+  } else {
+    fail('ISSUE-003 创建用户', new Error(`code=${cu.data?.code} msg=${cu.data?.message || ''}`));
+  }
+
+  // 新API: grantEnergy
+  log('=== 新增API: energy.grantEnergy ===');
+  const ge = await adminApi('/api/energy/grantEnergy', { childId: 1, taskId: 1, amount: 10, dimensionCode: 'body' });
+  if (ge.ok || ge.data?.code === 200) {
+    pass('energy.grantEnergy', 'ok');
+  } else {
+    fail('energy.grantEnergy', new Error(`code=${ge.data?.code} msg=${ge.data?.message || ''}`));
+  }
+
+  // 新API: points.checkAndGrantReward
+  log('=== 新增API: points.checkAndGrantReward ===');
+  const pr = await adminApi('/api/points/checkAndGrantReward', { childId: 1, amount: 5 });
+  if (pr.ok || pr.data?.code === 200 || pr.data?.data === -1) {
+    pass('points.checkAndGrantReward', `result=${pr.data?.data}`);
+  } else {
+    fail('points.checkAndGrantReward', new Error(`code=${pr.data?.code} msg=${pr.data?.message || ''}`));
+  }
+
+  // 新API: growth.getRecordsByChild
+  log('=== 新增API: growth.getRecordsByChild ===');
+  const gr = await adminApi('/api/growth/record/child/1', {});
+  if (gr.ok || gr.data?.code === 200) {
+    const count = Array.isArray(gr.data?.data) ? gr.data.data.length : 0;
+    pass('growth.getRecordsByChild', `count=${count}`);
+  } else {
+    fail('growth.getRecordsByChild', new Error(`code=${gr.data?.code} msg=${gr.data?.message || ''}`));
+  }
+
+  // 生成报告
+  const passed = results.filter(r => r.startsWith('PASS')).length;
+  const failed = results.filter(r => r.startsWith('FAIL')).length;
+  const skipped = results.filter(r => r.startsWith('SKIP')).length;
+
+  let report = `API 测试结果 - ${new Date().toLocaleString()}\n`;
+  report += `========================================\n\n`;
+  results.forEach(r => { report += r + '\n'; });
+  report += `\n========================================\n`;
+  report += `总计: ${passed} PASS / ${failed} FAIL / ${skipped} SKIP\n`;
+
+  const reportPath = path.join(__dirname, 'v3_results.txt');
+  fs.writeFileSync(reportPath, report, 'utf8');
+  console.log('Report: ' + reportPath);
+  console.log('PASS=' + passed + ' FAIL=' + failed + ' SKIP=' + skipped);
+}
+
+main().catch(err => {
+  const msg = 'ERROR: ' + err.message;
+  console.log(msg);
+  fs.writeFileSync(path.join(__dirname, 'v3_results.txt'), msg, 'utf8');
+});

+ 560 - 0
tests/run-api-tests-v3.js

@@ -0,0 +1,560 @@
+/**
+ * CFC API Integration Test Runner v3
+ * 环境: http://cfc.iwintrue.com:80
+ * 覆盖: NEW-01/02/03修复验证 + ISSUE-001/002/003回归 + 新增API测试
+ *
+ * 运行: node tests/run-api-tests-v3.js
+ */
+
+const BASE = 'http://cfc.iwintrue.com:80';
+
+const ADMIN = { phone: '13800138000', userId: 7, role: 'admin', name: '管理员' };
+const PARENT = { phone: '13701366188', userId: 8, familyId: 2, role: 'parent', name: '家长' };
+
+let adminToken = null;
+let testResults = [];
+let testStartTime = Date.now();
+
+function log(msg) { console.log(`[${new Date().toISOString()}] ${msg}`); }
+
+function pass(name, detail = '') {
+  testResults.push({ name, result: 'PASS', detail, time: Date.now() });
+  console.log(`  ✅ PASS | ${name}${detail ? ' | ' + detail : ''}`);
+}
+
+function fail(name, err, detail = '') {
+  testResults.push({ name, result: 'FAIL', detail: detail || err.message, time: Date.now() });
+  console.log(`  ❌ FAIL | ${name} | ${err.message}${detail ? ' | ' + detail : ''}`);
+}
+
+function skip(name, reason) {
+  testResults.push({ name, result: 'SKIP', detail: reason, time: Date.now() });
+  console.log(`  ⏭️  SKIP | ${name} | ${reason}`);
+}
+
+async function api(path, body, headers = {}) {
+  const url = `${BASE}${path}`;
+  const opts = {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json', ...headers },
+    body: body ? JSON.stringify(body) : undefined,
+  };
+  try {
+    const resp = await fetch(url, opts);
+    const text = await resp.text();
+    let data;
+    try { data = JSON.parse(text); } catch { data = null; }
+    return { status: resp.status, data, ok: resp.ok, raw: text.substring(0, 300) };
+  } catch (err) {
+    throw new Error(`网络错误: ${err.message}`);
+  }
+}
+
+async function adminApi(path, body) {
+  if (!adminToken) throw new Error('无admin token');
+  return api(path, body, { Authorization: `Bearer ${adminToken}` });
+}
+
+async function publicApi(path, body) {
+  return api(path, body, {});
+}
+
+// ─────────────────────────────────────────
+// 1. 登录
+// ─────────────────────────────────────────
+async function login() {
+  log('=== 1. 登录测试 ===');
+
+  try {
+    // 发送验证码(skip-captcha 已启用,任意验证码均可)
+    await api('/api/admin-auth/send-code', { phone: ADMIN.phone });
+
+    // 登录获取 token
+    const resp = await api('/api/admin-auth/login', { phone: ADMIN.phone, code: '123456' });
+    if (resp.data?.data?.token) {
+      adminToken = resp.data.data.token;
+      pass('Admin登录', `userId=${resp.data.data.adminId || ADMIN.userId}`);
+    } else {
+      fail('Admin登录', new Error('未获取到token'), `raw: ${resp.raw}`);
+    }
+  } catch (err) {
+    fail('Admin登录', err);
+  }
+
+  skip('Parent登录(手机验证码)', '测试环境无法发短信,parent端需手动测试');
+}
+
+// ─────────────────────────────────────────
+// 2. 公共端点(无需认证)
+// ─────────────────────────────────────────
+async function testPublicEndpoints() {
+  log('=== 2. 公共端点测试 ===');
+
+  // 文章列表
+  try {
+    const resp = await publicApi('/api/articles/list', { page: 1, size: 5 });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('文章列表(公开)', 'ok');
+    } else {
+      fail('文章列表(公开)', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('文章列表(公开)', err); }
+
+  // 活动列表
+  try {
+    const resp = await publicApi('/api/activity/list', { page: 1, size: 5 });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('活动列表(公开)', 'ok');
+    } else {
+      fail('活动列表(公开)', new Error(`status=${resp.status}`));
+    }
+  } catch (err) { fail('活动列表(公开)', err); }
+}
+
+// ─────────────────────────────────────────
+// 3. NEW-01 验证:能量规则创建
+// 修复: AdminEnergyRuleController.create() 改用 Map<String,Object>
+// ─────────────────────────────────────────
+async function testNEW01_EnergyRuleCreate() {
+  log('=== 3. NEW-01 验证:能量规则创建 ===');
+
+  if (!adminToken) { skip('NEW-01 能量规则创建', '无admin token'); return; }
+
+  // 先查看能量规则列表(确保维度存在)
+  let dimensions = [];
+  try {
+    const resp = await adminApi('/api/admin/energy-rule/dimensions', {});
+    if (resp.ok || resp.data?.code === 200) {
+      dimensions = resp.data?.data || [];
+      pass('能量维度列表', `count=${dimensions.length}`);
+    } else {
+      fail('能量维度列表', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('能量维度列表', err); return; }
+
+  // 创建能量规则(使用正确的 Map 参数格式)
+  let ruleId = null;
+  try {
+    const resp = await adminApi('/api/admin/energy-rule/create', {
+      ruleName: '自动化测试规则_NEW01_' + Date.now(),
+      dimensionCode: 'body',
+      eventType: 'checkin',
+      energyValue: 5,
+      status: 1,
+      action: 'increase',
+      priority: 0,
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      // 插入后 EnergyRule.id 会回填到 data
+      ruleId = resp.data?.data?.id || resp.data?.id;
+      pass('NEW-01 创建能量规则', `id=${ruleId} ✅ NEW-01已修复`);
+    } else {
+      fail('NEW-01 创建能量规则', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('NEW-01 创建能量规则', err); }
+
+  if (!ruleId) return;
+
+  // 切换状态
+  try {
+    const resp = await adminApi('/api/admin/energy-rule/toggle', { id: ruleId });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('能量规则切换状态', `id=${ruleId}`);
+    } else {
+      fail('能量规则切换状态', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('能量规则切换状态', err); }
+}
+
+// ─────────────────────────────────────────
+// 4. NEW-02 验证:SKU列表
+// 修复: ProductSkuController.listByProduct 改用 Map + null检查
+// ─────────────────────────────────────────
+async function testNEW02_SkuList() {
+  log('=== 4. NEW-02 验证:SKU列表 ===');
+
+  if (!adminToken) { skip('NEW-02 SKU列表', '无admin token'); return; }
+
+  // productId=1 在之前测试中应该是已存在的商品
+  try {
+    const resp = await adminApi('/api/admin/product/sku/list', { productId: 1 });
+    if (resp.ok || resp.data?.code === 200) {
+      const skus = resp.data?.data || [];
+      pass('NEW-02 SKU列表', `count=${skus.length} ✅ NEW-02已修复`);
+    } else if (resp.data?.code === 500) {
+      fail('NEW-02 SKU列表', new Error('500 Internal Server Error'), '⚠️ NEW-02可能回归');
+    } else {
+      fail('NEW-02 SKU列表', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('NEW-02 SKU列表', err); }
+}
+
+// ─────────────────────────────────────────
+// 5. NEW-03 验证:活动发布
+// 修复: ActivityController.publish() 改用 Map + try-catch
+// ─────────────────────────────────────────
+async function testNEW03_ActivityPublish() {
+  log('=== 5. NEW-03 验证:活动发布 ===');
+
+  if (!adminToken) { skip('NEW-03 活动发布', '无admin token'); return; }
+
+  // 创建活动
+  let activityId = null;
+  try {
+    const resp = await adminApi('/api/activity/create', {
+      title: '自动化E2E测试活动_NEW03_' + Date.now(),
+      description: 'NEW-03修复验证测试',
+      dimensionCode: 'body',
+      startTime: new Date(Date.now() + 86400000 * 7).toISOString().replace('T', ' ').split('.')[0],
+      endTime: new Date(Date.now() + 86400000 * 8).toISOString().replace('T', ' ').split('.')[0],
+      location: '线上直播',
+      maxParticipants: 30,
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      activityId = resp.data?.data?.id || resp.data?.id;
+      pass('创建测试活动', `id=${activityId}`);
+    } else {
+      fail('创建测试活动', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('创建测试活动', err); }
+
+  if (!activityId) return;
+
+  // 发布活动(NEW-03 核心测试)
+  try {
+    const resp = await adminApi('/api/activity/publish', { id: activityId });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('NEW-03 发布活动', `id=${activityId} ✅ NEW-03已修复`);
+    } else if (resp.data?.code === 500) {
+      fail('NEW-03 发布活动', new Error('500 Internal Server Error'), '⚠️ NEW-03可能回归');
+    } else {
+      fail('NEW-03 发布活动', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('NEW-03 发布活动', err); }
+}
+
+// ─────────────────────────────────────────
+// 6. ISSUE-001 验证:供应商下架商品
+// ─────────────────────────────────────────
+async function testISSUE001() {
+  log('=== 6. ISSUE-001 验证:供应商下架商品 ===');
+
+  if (!adminToken) { skip('ISSUE-001 供应商下架', '无admin token'); return; }
+
+  // 1) 审核供应商 81069(如尚未批准)
+  try {
+    const resp = await adminApi('/api/admin/vendor/review', {
+      userId: 81069,
+      action: 'approve',
+      reason: '自动化测试',
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('审核供应商81069', 'approved');
+    } else {
+      fail('审核供应商81069', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('审核供应商81069', err); }
+
+  // 2) 审核商品(如尚未批准)
+  try {
+    const resp = await adminApi('/api/admin/product/review', {
+      productId: 7,
+      action: 'approve',
+      reason: '自动化测试',
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('审核商品7', 'approved');
+    } else {
+      fail('审核商品7', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('审核商品7', err); }
+
+  // 3) 上架商品
+  try {
+    const resp = await adminApi('/api/admin/product/shelve', { productId: 7, shelve: true });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('上架商品7', 'on_shelf');
+    } else {
+      fail('上架商品7', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('上架商品7', err); }
+
+  // 4) 供应商下架商品(核心验证)
+  try {
+    const resp = await api('/api/product/shelve', { productId: 7, action: 'unshelve' }, { 'X-User-Id': '81069' });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('ISSUE-001 供应商下架商品', 'unshelved ✅ ISSUE-001已修复');
+    } else if (resp.data?.message?.includes('未通过审核')) {
+      fail('ISSUE-001 供应商下架商品', new Error('商品未通过审核/状态异常'), '需检查商品状态');
+    } else {
+      fail('ISSUE-001 供应商下架商品', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('ISSUE-001 供应商下架商品', err); }
+}
+
+// ─────────────────────────────────────────
+// 7. ISSUE-002/003 回归验证
+// ─────────────────────────────────────────
+async function testIssue002_003() {
+  log('=== 7. ISSUE-002/003 回归验证 ===');
+
+  if (!adminToken) { skip('ISSUE-002/003', '无admin token'); return; }
+
+  // ISSUE-003: 创建用户
+  const phone = '139' + String(Math.floor(Math.random() * 1e9)).padStart(9, '0');
+  let newUserId = null;
+  try {
+    const resp = await adminApi('/api/admin/users/create', {
+      phone: phone,
+      password: 'Test123456',
+      name: '自动化测试用户_' + Date.now(),
+      role: 'parent',
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      newUserId = resp.data?.data?.id || resp.data?.id;
+      pass('ISSUE-003 创建用户', `userId=${newUserId} ✅ ISSUE-003稳定`);
+    } else if (resp.data?.code === 500) {
+      fail('ISSUE-003 创建用户', new Error('500 - ISSUE-003回归'), '⚠️ 需紧急修复');
+    } else {
+      fail('ISSUE-003 创建用户', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('ISSUE-003 创建用户', err); }
+
+  // ISSUE-002: 文章发布(检查 articleId=13 是否仍可发布)
+  try {
+    const resp = await adminApi('/api/article/13/publish', {});
+    if (resp.ok || resp.data?.code === 200) {
+      pass('ISSUE-002 文章发布', 'articleId=13 ✅ ISSUE-002稳定');
+    } else {
+      fail('ISSUE-002 文章发布', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('ISSUE-002 文章发布', err); }
+}
+
+// ─────────────────────────────────────────
+// 8. 新增API测试(来自 recent commits)
+// dfcc285: 心愿兑换积分检查和扣除
+// 3e44f18: grantEnergy + deductForWish 接口
+// 8212e25: getRecordsByChild 成长记录
+// ─────────────────────────────────────────
+async function testNewAPIs() {
+  log('=== 8. 新增API测试(recent commits)===');
+
+  if (!adminToken) { skip('新增API测试', '无admin token'); return; }
+
+  // 8a. EnergyService.grantEnergy + deductForWish
+  // POST /api/energy/grantEnergy
+  try {
+    const resp = await adminApi('/api/energy/grantEnergy', {
+      childId: 1,
+      taskId: 1,
+      amount: 10,
+      dimensionCode: 'body',
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('energy.grantEnergy', 'ok');
+    } else {
+      fail('energy.grantEnergy', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('energy.grantEnergy', err); }
+
+  // POST /api/energy/deductForWish
+  try {
+    const resp = await adminApi('/api/energy/deductForWish', {
+      childId: 1,
+      wishId: 1,
+      amount: 5,
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('energy.deductForWish', 'ok');
+    } else {
+      fail('energy.deductForWish', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('energy.deductForWish', err); }
+
+  // 8b. PointsService.checkAndGrantReward + deductForWish (dfcc285)
+  // POST /api/points/checkAndGrantReward
+  try {
+    const resp = await adminApi('/api/points/checkAndGrantReward', {
+      childId: 1,
+      amount: 5,
+    });
+    // 可能返回 -1(余额不足)或成功
+    if (resp.ok || resp.data?.code === 200 || resp.data?.data === -1) {
+      pass('points.checkAndGrantReward', `result=${resp.data?.data}`);
+    } else {
+      fail('points.checkAndGrantReward', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('points.checkAndGrantReward', err); }
+
+  // POST /api/points/deductForWish
+  try {
+    const resp = await adminApi('/api/points/deductForWish', {
+      childId: 1,
+      amount: 5,
+    });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('points.deductForWish', `result=${resp.data?.data}`);
+    } else {
+      fail('points.deductForWish', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('points.deductForWish', err); }
+
+  // 8c. GrowthRecord - getRecordsByChild (8212e25)
+  // GET /api/growth/record/child/{childId} 或 POST
+  try {
+    const resp = await adminApi('/api/growth/record/child/1', {});
+    if (resp.ok || resp.data?.code === 200) {
+      const records = resp.data?.data || [];
+      pass('growth.getRecordsByChild', `count=${Array.isArray(records) ? records.length : 0}`);
+    } else {
+      fail('growth.getRecordsByChild', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('growth.getRecordsByChild', err); }
+
+  // 8d. Activity end
+  try {
+    const resp = await adminApi('/api/activity/end', { id: 18 });
+    if (resp.ok || resp.data?.code === 200 || resp.data?.message?.includes('不存在')) {
+      pass('activity.end', 'ok');
+    } else {
+      fail('activity.end', new Error(`code=${resp.data?.code} msg=${resp.data?.message || ''}`));
+    }
+  } catch (err) { fail('activity.end', err); }
+}
+
+// ─────────────────────────────────────────
+// 9. 能量规则维度查询
+// ─────────────────────────────────────────
+async function testEnergyRuleDimensions() {
+  log('=== 9. 能量规则维度查询 ===');
+
+  if (!adminToken) { skip('能量规则维度查询', '无admin token'); return; }
+
+  try {
+    const resp = await adminApi('/api/admin/energy-rule/dimensions', {});
+    if (resp.ok || resp.data?.code === 200) {
+      const dims = resp.data?.data || [];
+      pass('能量规则维度列表', `count=${dims.length}`);
+      dims.forEach(d => {
+        console.log(`    - ${d.dimensionCode || d.code}: ${d.name || d.dimensionName || JSON.stringify(d)}`);
+      });
+    } else {
+      fail('能量规则维度列表', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('能量规则维度列表', err); }
+}
+
+// ─────────────────────────────────────────
+// 10. 后台管理核心接口
+// ─────────────────────────────────────────
+async function testAdminCore() {
+  log('=== 10. 后台管理核心接口 ===');
+
+  if (!adminToken) { skip('后台管理核心接口', '无admin token'); return; }
+
+  // 用户列表
+  try {
+    const resp = await adminApi('/api/admin/users', { page: 1, size: 10 });
+    if (resp.ok || resp.data?.code === 200) {
+      pass('用户列表', 'ok');
+    } else {
+      fail('用户列表', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('用户列表', err); }
+
+  // 供应商列表
+  try {
+    const resp = await adminApi('/api/admin/vendor/list', {});
+    if (resp.ok || resp.data?.code === 200) {
+      pass('供应商列表', 'ok');
+    } else {
+      fail('供应商列表', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('供应商列表', err); }
+
+  // 规划师申请列表
+  try {
+    const resp = await adminApi('/api/admin/guide/applications/pending', {});
+    if (resp.ok || resp.data?.code === 200) {
+      const apps = resp.data?.data || [];
+      pass('规划师申请列表', `pending=${apps.length}`);
+    } else {
+      fail('规划师申请列表', new Error(`code=${resp.data?.code}`));
+    }
+  } catch (err) { fail('规划师申请列表', err); }
+}
+
+// ─────────────────────────────────────────
+// 报告生成
+// ─────────────────────────────────────────
+async function generateReport() {
+  const duration = Date.now() - testStartTime;
+  const passed = testResults.filter(r => r.result === 'PASS').length;
+  const failed = testResults.filter(r => r.result === 'FAIL').length;
+  const skipped = testResults.filter(r => r.result === 'SKIP').length;
+  const total = testResults.length;
+
+  console.log('\n' + '='.repeat(60));
+  console.log(`  API 测试报告 v3  —  ${new Date().toLocaleString()}`);
+  console.log(`  耗时: ${Math.round(duration / 1000)}s`);
+  console.log(`  结果: ${passed} PASS / ${failed} FAIL / ${skipped} SKIP / ${total} TOTAL`);
+  console.log('='.repeat(60));
+
+  if (failed > 0) {
+    console.log('\n❌ FAIL 明细:');
+    testResults.filter(r => r.result === 'FAIL').forEach(r => {
+      console.log(`  - ${r.name}: ${r.detail}`);
+    });
+  }
+
+  const report = {
+    version: 'v3',
+    timestamp: new Date().toISOString(),
+    duration_ms: duration,
+    summary: { total, passed, failed, skipped },
+    results: testResults,
+  };
+
+  const fs = require('fs');
+  const path = require('path');
+  const reportPath = path.join(__dirname, 'TEST-RESULTS-v3.md');
+  let md = `# API 测试报告 v3 — ${new Date().toLocaleString()}\n\n`;
+  md += `| 结果 | 数量 |\n|------|------|\n`;
+  md += `| ✅ PASS | ${passed} |\n| ❌ FAIL | ${failed} |\n| ⏭️ SKIP | ${skipped} |\n| 总计 | ${total} |\n\n`;
+  md += `## FAIL 明细\n\n`;
+  testResults.filter(r => r.result === 'FAIL').forEach(r => {
+    md += `- **${r.name}**: ${r.detail}\n`;
+  });
+  md += `\n## 完整结果\n\n`;
+  md += `| 用例 | 结果 | 详情 |\n|------|------|------|\n`;
+  testResults.forEach(r => {
+    md += `| ${r.name} | ${r.result} | ${r.detail} |\n`;
+  });
+
+  fs.writeFileSync(reportPath, md, 'utf8');
+  console.log(`\n报告已保存: ${reportPath}`);
+}
+
+// ─────────────────────────────────────────
+// 主流程
+// ─────────────────────────────────────────
+async function main() {
+  log('CFC API 测试 Runner v3 开始');
+  log(`目标环境: ${BASE}`);
+
+  await login();
+  await testPublicEndpoints();
+  await testNEW01_EnergyRuleCreate();
+  await testNEW02_SkuList();
+  await testNEW03_ActivityPublish();
+  await testISSUE001();
+  await testIssue002_003();
+  await testEnergyRuleDimensions();
+  await testAdminCore();
+  await testNewAPIs();
+
+  await generateReport();
+}
+
+main().catch(console.error);

+ 134 - 0
tests/run_v3_http.js

@@ -0,0 +1,134 @@
+const fs = require('fs');
+const http = require('http');
+
+const BASE = 'cfc.iwintrue.com';
+let out = 'CFC API v3 Results\n==================\n\n';
+let adminToken = null;
+
+function api(path, body, headers) {
+  return new Promise((resolve) => {
+    const data = body ? JSON.stringify(body) : '';
+    const options = {
+      hostname: BASE,
+      port: 80,
+      path: path,
+      method: 'POST',
+      headers: { 'Content-Type': 'application/json', ...headers, 'Content-Length': Buffer.byteLength(data) },
+    };
+    const req = http.request(options, (res) => {
+      let d = '';
+      res.on('data', c => d += c);
+      res.on('end', () => {
+        try { resolve({ status: res.statusCode, data: JSON.parse(d) }); }
+        catch { resolve({ status: res.statusCode, data: null, raw: d.slice(0, 100) }); }
+      });
+    });
+    req.on('error', () => resolve({ error: 'network' }));
+    if (data) req.write(data);
+    req.end();
+  });
+}
+
+async function admin(path, body) {
+  if (!adminToken) return { error: 'notoken' };
+  return api(path, body, { Authorization: 'Bearer ' + adminToken });
+}
+
+async function run() {
+  // 1. Login
+  await api('/api/admin-auth/send-code', { phone: '13800138000' });
+  const lr = await api('/api/admin-auth/login', { phone: '13800138000', code: '123456' });
+  if (lr.data?.data?.token) {
+    adminToken = lr.data.data.token;
+    out += '[PASS] Admin login userId=' + (lr.data.data.adminId || 7) + '\n';
+  } else {
+    out += '[FAIL] Admin login: ' + (lr.raw || JSON.stringify(lr.data)) + '\n';
+  }
+
+  // 2. NEW-01 Energy rule create
+  const er = await admin('/api/admin/energy-rule/create', {
+    ruleName: 'Auto_NEW01_' + Date.now(), dimensionCode: 'body', eventType: 'checkin', energyValue: 5, status: 1,
+  });
+  if (er.error) {
+    out += '[FAIL] NEW-01 energy-rule create: ' + er.error + '\n';
+  } else if (er.status === 200 || er.data?.code === 200) {
+    const id = er.data?.data?.id || er.data?.id;
+    out += '[PASS] NEW-01 energy-rule create id=' + id + '\n';
+  } else {
+    out += '[FAIL] NEW-01 energy-rule create code=' + er.status + ' msg=' + (er.data?.message || '') + '\n';
+  }
+
+  // 3. NEW-02 SKU list
+  const sku = await admin('/api/admin/product/sku/list', { productId: 1 });
+  if (sku.error) {
+    out += '[FAIL] NEW-02 sku/list: ' + sku.error + '\n';
+  } else if (sku.status === 200 || sku.data?.code === 200) {
+    out += '[PASS] NEW-02 sku/list count=' + (Array.isArray(sku.data?.data) ? sku.data.data.length : '?') + '\n';
+  } else {
+    out += '[FAIL] NEW-02 sku/list code=' + sku.status + ' msg=' + (sku.data?.message || '') + '\n';
+  }
+
+  // 4. NEW-03 Activity publish
+  const act = await admin('/api/activity/create', {
+    title: 'Auto_NEW03_' + Date.now(), dimensionCode: 'body',
+    startTime: '2026-07-15 10:00:00', endTime: '2026-07-15 12:00:00',
+    location: 'test', maxParticipants: 10,
+  });
+  const actId = act.data?.data?.id || act.data?.id;
+  if (actId) {
+    out += '[INFO] Activity created id=' + actId + '\n';
+    const pub = await admin('/api/activity/publish', { id: actId });
+    if (pub.status === 200 || pub.data?.code === 200) {
+      out += '[PASS] NEW-03 activity publish id=' + actId + '\n';
+    } else {
+      out += '[FAIL] NEW-03 activity publish code=' + pub.status + ' msg=' + (pub.data?.message || '') + '\n';
+    }
+  } else {
+    out += '[FAIL] NEW-03 activity create code=' + act.status + '\n';
+  }
+
+  // 5. ISSUE-001 vendor unshelve
+  const vs = await api('/api/product/shelve', { productId: 7, action: 'unshelve' }, { 'X-User-Id': '81069' });
+  if (vs.status === 200 || vs.data?.code === 200) {
+    out += '[PASS] ISSUE-001 vendor unshelve product 7\n';
+  } else {
+    out += '[FAIL] ISSUE-001 vendor unshelve code=' + vs.status + ' msg=' + (vs.data?.message || '') + '\n';
+  }
+
+  // 6. ISSUE-003 create user
+  const phone = '139' + String(Math.floor(Math.random() * 1e9)).padStart(9, '0');
+  const cu = await admin('/api/admin/users/create', { phone, password: 'Test123456', name: 'AutoTest', role: 'parent' });
+  if (cu.error) {
+    out += '[FAIL] ISSUE-003 create user: ' + cu.error + '\n';
+  } else if (cu.status === 200 || cu.data?.code === 200) {
+    out += '[PASS] ISSUE-003 create user id=' + (cu.data?.data?.id || cu.data?.id) + '\n';
+  } else {
+    out += '[FAIL] ISSUE-003 create user code=' + cu.status + '\n';
+  }
+
+  // 7. New API grantEnergy
+  const ge = await admin('/api/energy/grantEnergy', { childId: 1, taskId: 1, amount: 10, dimensionCode: 'body' });
+  if (ge.error) {
+    out += '[FAIL] energy.grantEnergy: ' + ge.error + '\n';
+  } else if (ge.status === 200 || ge.data?.code === 200) {
+    out += '[PASS] energy.grantEnergy\n';
+  } else {
+    out += '[FAIL] energy.grantEnergy code=' + ge.status + ' msg=' + (ge.data?.message || '') + '\n';
+  }
+
+  // 8. New API growth.getRecordsByChild
+  const gr = await admin('/api/growth/record/child/1', {});
+  if (gr.error) {
+    out += '[FAIL] growth.getRecordsByChild: ' + gr.error + '\n';
+  } else if (gr.status === 200 || gr.data?.code === 200) {
+    out += '[PASS] growth.getRecordsByChild count=' + (Array.isArray(gr.data?.data) ? gr.data.data.length : '?') + '\n';
+  } else {
+    out += '[FAIL] growth.getRecordsByChild code=' + gr.status + '\n';
+  }
+
+  fs.writeFileSync('C:/code/cfc/tests/v3_http_result.txt', out, 'utf8');
+}
+
+run().catch(e => {
+  fs.writeFileSync('C:/code/cfc/tests/v3_http_result.txt', 'ERROR: ' + e.message, 'utf8');
+});

+ 146 - 0
tests/run_v3_minimal.js

@@ -0,0 +1,146 @@
+const fs = require('fs');
+const path = require('path');
+
+const BASE = 'http://cfc.iwintrue.com:80';
+const results = [];
+let adminToken = null;
+
+async function api(p, body, h = {}) {
+  try {
+    const r = await fetch(BASE + p, {
+      method: 'POST',
+      headers: { 'Content-Type': 'application/json', ...h },
+      body: body ? JSON.stringify(body) : undefined,
+    });
+    const t = await r.text();
+    let d;
+    try { d = JSON.parse(t); } catch {}
+    return { ok: r.ok, status: r.status, data: d, raw: t.slice(0, 200) };
+  } catch (e) {
+    return { ok: false, data: null, error: e.message };
+  }
+}
+
+async function admin(p, body) {
+  if (!adminToken) return { ok: false, data: null, error: 'notoken' };
+  return api(p, body, { Authorization: 'Bearer ' + adminToken });
+}
+
+async function run() {
+  let out = '=== CFC API v3 Test Results ===\n';
+  out += 'Time: ' + new Date().toISOString() + '\n\n';
+
+  // Login
+  out += '[1] Login\n';
+  await api('/api/admin-auth/send-code', { phone: '13800138000' });
+  const lr = await api('/api/admin-auth/login', { phone: '13800138000', code: '123456' });
+  if (lr.data?.data?.token) {
+    adminToken = lr.data.data.token;
+    out += '  PASS: Admin login, userId=' + (lr.data.data.adminId || 7) + '\n';
+  } else {
+    out += '  FAIL: Admin login failed - ' + (lr.raw || 'no token') + '\n';
+  }
+
+  // NEW-01 Energy Rule Create
+  out += '[2] NEW-01 Energy Rule Create\n';
+  const er = await admin('/api/admin/energy-rule/create', {
+    ruleName: 'AutoTest_NEW01_' + Date.now(),
+    dimensionCode: 'body', eventType: 'checkin', energyValue: 5, status: 1,
+  });
+  if (er.ok || er.data?.code === 200) {
+    const id = er.data?.data?.id || er.data?.id;
+    out += '  PASS: Energy rule created, id=' + id + '\n';
+  } else {
+    out += '  FAIL: code=' + er.data?.code + ' msg=' + (er.data?.message || '') + '\n';
+  }
+
+  // NEW-02 SKU List
+  out += '[3] NEW-02 SKU List\n';
+  const sku = await admin('/api/admin/product/sku/list', { productId: 1 });
+  if (sku.ok || sku.data?.code === 200) {
+    const cnt = Array.isArray(sku.data?.data) ? sku.data.data.length : 0;
+    out += '  PASS: SKU list, count=' + cnt + '\n';
+  } else {
+    out += '  FAIL: code=' + sku.data?.code + ' msg=' + (sku.data?.message || '') + '\n';
+  }
+
+  // NEW-03 Activity Publish
+  out += '[4] NEW-03 Activity Publish\n';
+  const act = await admin('/api/activity/create', {
+    title: 'AutoTest_NEW03_' + Date.now(),
+    dimensionCode: 'body',
+    startTime: '2026-07-15 10:00:00',
+    endTime: '2026-07-15 12:00:00',
+    location: 'test',
+    maxParticipants: 10,
+  });
+  const actId = act.data?.data?.id || act.data?.id;
+  if (actId) {
+    out += '  INFO: Activity created, id=' + actId + '\n';
+    const pub = await admin('/api/activity/publish', { id: actId });
+    if (pub.ok || pub.data?.code === 200) {
+      out += '  PASS: Activity published\n';
+    } else {
+      out += '  FAIL: code=' + pub.data?.code + ' msg=' + (pub.data?.message || '') + '\n';
+    }
+  } else {
+    out += '  FAIL: Activity creation failed - code=' + act.data?.code + '\n';
+  }
+
+  // ISSUE-001 Vendor unshelve
+  out += '[5] ISSUE-001 Vendor unshelve\n';
+  const vs = await api('/api/product/shelve', { productId: 7, action: 'unshelve' }, { 'X-User-Id': '81069' });
+  if (vs.ok || vs.data?.code === 200) {
+    out += '  PASS: Vendor unshelved product 7\n';
+  } else {
+    out += '  FAIL: code=' + vs.data?.code + ' msg=' + (vs.data?.message || '') + '\n';
+  }
+
+  // ISSUE-003 Create user
+  out += '[6] ISSUE-003 Create user\n';
+  const phone = '139' + String(Math.floor(Math.random() * 1e9)).padStart(9, '0');
+  const cu = await admin('/api/admin/users/create', {
+    phone, password: 'Test123456', name: 'AutoTestUser', role: 'parent',
+  });
+  if (cu.ok || cu.data?.code === 200) {
+    const uid = cu.data?.data?.id || cu.data?.id;
+    out += '  PASS: User created, id=' + uid + '\n';
+  } else {
+    out += '  FAIL: code=' + cu.data?.code + ' msg=' + (cu.data?.message || '') + '\n';
+  }
+
+  // New APIs
+  out += '[7] New API: energy.grantEnergy\n';
+  const ge = await admin('/api/energy/grantEnergy', { childId: 1, taskId: 1, amount: 10, dimensionCode: 'body' });
+  if (ge.ok || ge.data?.code === 200) {
+    out += '  PASS: grantEnergy ok\n';
+  } else {
+    out += '  FAIL: code=' + ge.data?.code + ' msg=' + (ge.data?.message || '') + '\n';
+  }
+
+  out += '[8] New API: points.checkAndGrantReward\n';
+  const pr = await admin('/api/points/checkAndGrantReward', { childId: 1, amount: 5 });
+  if (pr.ok || pr.data?.code === 200 || pr.data?.data === -1) {
+    out += '  PASS: checkAndGrantReward, result=' + pr.data?.data + '\n';
+  } else {
+    out += '  FAIL: code=' + pr.data?.code + ' msg=' + (pr.data?.message || '') + '\n';
+  }
+
+  out += '[9] New API: growth.getRecordsByChild\n';
+  const gr = await admin('/api/growth/record/child/1', {});
+  if (gr.ok || gr.data?.code === 200) {
+    const cnt = Array.isArray(gr.data?.data) ? gr.data.data.length : 0;
+    out += '  PASS: getRecordsByChild, count=' + cnt + '\n';
+  } else {
+    out += '  FAIL: code=' + gr.data?.code + ' msg=' + (gr.data?.message || '') + '\n';
+  }
+
+  fs.writeFileSync(path.join(__dirname, 'v3_test_output.txt'), out, 'utf8');
+}
+
+run().then(() => {
+  process.exit(0);
+}).catch(e => {
+  fs.writeFileSync(path.join(__dirname, 'v3_test_output.txt'), 'ERROR: ' + e.message, 'utf8');
+  process.exit(1);
+});

+ 3 - 0
tests/simple_write.js

@@ -0,0 +1,3 @@
+const fs = require('fs');
+fs.writeFileSync('C:/code/cfc/tests/simple_out.txt', 'TEST OK\n');
+console.log('Wrote file');

+ 106 - 0
tests/test_cfc_api.js

@@ -0,0 +1,106 @@
+const http = require('http');
+const fs = require('fs');
+
+const BASE = 'cfc.iwintrue.com';
+const PORT = 80;
+let adminToken = null;
+let out = '';
+
+function post(path, body, headers) {
+  return new Promise((resolve) => {
+    const data = JSON.stringify(body);
+    const h = { 'Content-Type': 'application/json', ...headers, 'Content-Length': Buffer.byteLength(data) };
+    const req = http.request({ hostname: BASE, port: PORT, path, method: 'POST', headers: h }, (res) => {
+      let d = '';
+      res.on('data', c => d += c);
+      res.on('end', () => {
+        try { resolve({ ok: res.statusCode === 200, status: res.statusCode, data: JSON.parse(d) }); }
+        catch { resolve({ ok: false, status: res.statusCode, raw: d.slice(0, 100) }); }
+      });
+    });
+    req.on('error', () => resolve({ ok: false, error: 'network' }));
+    req.write(data); req.end();
+  });
+}
+
+async function admin(path, body) {
+  if (!adminToken) return { ok: false, error: 'notoken' };
+  return post(path, body, { Authorization: 'Bearer ' + adminToken });
+}
+
+async function run() {
+  out += '=== CFC API v3 Results ===\n\n';
+
+  // Login
+  await post('/api/admin-auth/send-code', { phone: '13800138000' });
+  const lr = await post('/api/admin-auth/login', { phone: '13800138000', code: '123456' });
+  if (lr.data?.data?.token) {
+    adminToken = lr.data.data.token;
+    out += '[PASS] Admin login userId=' + (lr.data.data.adminId || 7) + '\n';
+  } else {
+    out += '[FAIL] Admin login - ' + (lr.raw || JSON.stringify(lr.data)) + '\n';
+    fs.writeFileSync('C:/code/cfc/tests/v3_out.txt', out);
+    return;
+  }
+
+  // NEW-01: Energy rule create
+  const er = await admin('/api/admin/energy-rule/create', {
+    ruleName: 'Auto_NEW01_' + Date.now(), dimensionCode: 'body', eventType: 'checkin', energyValue: 5, status: 1,
+  });
+  if (er.ok) out += '[PASS] NEW-01 energy-rule create id=' + (er.data?.data?.id || er.data?.id) + '\n';
+  else out += '[FAIL] NEW-01 energy-rule create code=' + er.status + ' msg=' + (er.data?.message || '') + '\n';
+
+  // NEW-02: SKU list
+  const sku = await admin('/api/admin/product/sku/list', { productId: 1 });
+  if (sku.ok) out += '[PASS] NEW-02 sku/list count=' + (Array.isArray(sku.data?.data) ? sku.data.data.length : 0) + '\n';
+  else out += '[FAIL] NEW-02 sku/list code=' + sku.status + ' msg=' + (sku.data?.message || '') + '\n';
+
+  // NEW-03: Activity create + publish
+  const act = await admin('/api/activity/create', {
+    title: 'Auto_NEW03_' + Date.now(), dimensionCode: 'body',
+    startTime: '2026-07-15 10:00:00', endTime: '2026-07-15 12:00:00',
+    location: 'test', maxParticipants: 10,
+  });
+  const actId = act.data?.data?.id || act.data?.id;
+  if (actId) {
+    out += '[INFO] Activity created id=' + actId + '\n';
+    const pub = await admin('/api/activity/publish', { id: actId });
+    if (pub.ok) out += '[PASS] NEW-03 activity publish id=' + actId + '\n';
+    else out += '[FAIL] NEW-03 activity publish code=' + pub.status + ' msg=' + (pub.data?.message || '') + '\n';
+  } else {
+    out += '[FAIL] NEW-03 activity create code=' + act.status + '\n';
+  }
+
+  // ISSUE-001: Vendor unshelve
+  const vs = await post('/api/product/shelve', { productId: 7, action: 'unshelve' }, { 'X-User-Id': '81069' });
+  if (vs.ok) out += '[PASS] ISSUE-001 vendor unshelve product 7\n';
+  else out += '[FAIL] ISSUE-001 vendor unshelve code=' + vs.status + ' msg=' + (vs.data?.message || '') + '\n';
+
+  // ISSUE-003: Create user
+  const phone = '139' + String(Math.floor(Math.random() * 1e9)).padStart(9, '0');
+  const cu = await admin('/api/admin/users/create', { phone, password: 'Test123456', name: 'AutoTest', role: 'parent' });
+  if (cu.ok) out += '[PASS] ISSUE-003 create user id=' + (cu.data?.data?.id || cu.data?.id) + '\n';
+  else out += '[FAIL] ISSUE-003 create user code=' + cu.status + '\n';
+
+  // New API: grantEnergy
+  const ge = await admin('/api/energy/grantEnergy', { childId: 1, taskId: 1, amount: 10, dimensionCode: 'body' });
+  if (ge.ok) out += '[PASS] energy.grantEnergy\n';
+  else out += '[FAIL] energy.grantEnergy code=' + ge.status + ' msg=' + (ge.data?.message || '') + '\n';
+
+  // New API: points.checkAndGrantReward
+  const pr = await admin('/api/points/checkAndGrantReward', { childId: 1, amount: 5 });
+  if (pr.ok || pr.data?.data === -1) out += '[PASS] points.checkAndGrantReward result=' + pr.data?.data + '\n';
+  else out += '[FAIL] points.checkAndGrantReward code=' + pr.status + '\n';
+
+  // New API: getRecordsByChild
+  const gr = await admin('/api/growth/record/child/1', {});
+  if (gr.ok) out += '[PASS] growth.getRecordsByChild count=' + (Array.isArray(gr.data?.data) ? gr.data.data.length : 0) + '\n';
+  else out += '[FAIL] growth.getRecordsByChild code=' + gr.status + '\n';
+
+  fs.writeFileSync('C:/code/cfc/tests/v3_out.txt', out);
+  console.log('DONE'); // won't be seen but whatever
+}
+
+run().catch(e => {
+  fs.writeFileSync('C:/code/cfc/tests/v3_out.txt', 'ERROR: ' + e.message);
+});