flow-l1-tests.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. /**
  2. * ================================================================
  3. * FLOW-LEVEL L1 TEST SUITE — 流程级一级测试用例
  4. * ================================================================
  5. * Based on docs/flows/*.md flow diagrams
  6. * Tests each flow's key endpoints per role
  7. *
  8. * Roles: parent, child, teacher, admin, vendor
  9. *
  10. * Usage:
  11. * node tests/e2e/flow-l1-tests.js
  12. * ================================================================
  13. */
  14. var http = require('http');
  15. var https = require('https');
  16. var querystring = require('querystring');
  17. var path = require('path');
  18. var child_process = require('child_process');
  19. // ================================================================
  20. // Configuration
  21. // ================================================================
  22. var BASE_URL = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
  23. var MYSQL_HOST = process.env.MYSQL_HOST || '192.168.16.251';
  24. var MYSQL_USER = process.env.MYSQL_USER || 'zxyj';
  25. var MYSQL_PASS = process.env.MYSQL_PASS || 'zxyj@123';
  26. var MYSQL_DB = process.env.MYSQL_DB || 'zxyj';
  27. // ================================================================
  28. // Test Results Collector
  29. // ================================================================
  30. var results = {
  31. passed: 0,
  32. failed: 0,
  33. skipped: 0,
  34. issues: [],
  35. details: []
  36. };
  37. // Store last API response for debug output on failure
  38. var lastApiResponse = null;
  39. function log(msg) {
  40. console.log('[TEST] ' + msg);
  41. }
  42. function record(flow, role, step, passed, detail) {
  43. var icon = passed ? '✅' : '❌';
  44. var line = icon + ' [' + flow + '] ' + role + ' | ' + step + (detail ? ' — ' + detail : '');
  45. if (!passed && lastApiResponse) {
  46. // Show actual error response for debugging
  47. var respPreview = JSON.stringify(lastApiResponse).substring(0, 300);
  48. line += ' | RESP: ' + respPreview;
  49. }
  50. console.log(line);
  51. results.details.push({ flow: flow, role: role, step: step, passed: passed, detail: detail });
  52. if (passed) results.passed++;
  53. else results.failed++;
  54. }
  55. function skip(flow, role, step, reason) {
  56. var line = '⏭️ [' + flow + '] ' + role + ' | ' + step + ' — SKIPPED: ' + reason;
  57. console.log(line);
  58. results.details.push({ flow: flow, role: role, step: step, passed: null, detail: 'SKIP: ' + reason });
  59. results.skipped++;
  60. }
  61. function issue(flow, role, step, desc) {
  62. results.issues.push({ flow: flow, role: role, step: step, description: desc });
  63. }
  64. // ================================================================
  65. // HTTP Request Helper (plain Node.js, no deps)
  66. // ================================================================
  67. function apiCall(method, endpoint, data, token) {
  68. return new Promise(function(resolve) {
  69. var url = new URL(endpoint, BASE_URL);
  70. var options = {
  71. hostname: url.hostname,
  72. port: url.port || (url.protocol === 'https:' ? 443 : 80),
  73. path: url.pathname + url.search,
  74. method: method,
  75. headers: {
  76. 'Content-Type': 'application/json'
  77. },
  78. timeout: 15000
  79. };
  80. if (token) {
  81. options.headers['Authorization'] = 'Bearer ' + token;
  82. }
  83. var body = data ? JSON.stringify(data) : null;
  84. if (body) {
  85. options.headers['Content-Length'] = Buffer.byteLength(body);
  86. }
  87. var transport = url.protocol === 'https:' ? https : http;
  88. var req = transport.request(options, function(res) {
  89. var chunks = [];
  90. res.on('data', function(chunk) { chunks.push(chunk); });
  91. res.on('end', function() {
  92. var rawBody = Buffer.concat(chunks).toString();
  93. var parsed = null;
  94. try { parsed = JSON.parse(rawBody); } catch(e) { parsed = null; }
  95. lastApiResponse = parsed || rawBody;
  96. resolve({
  97. status: res.statusCode,
  98. body: parsed,
  99. raw: rawBody
  100. });
  101. });
  102. });
  103. req.on('error', function(err) {
  104. resolve({ status: 0, body: null, raw: err.message });
  105. });
  106. req.on('timeout', function() {
  107. req.destroy();
  108. resolve({ status: 0, body: null, raw: 'TIMEOUT' });
  109. });
  110. if (body) req.write(body);
  111. req.end();
  112. });
  113. }
  114. // ================================================================
  115. // DB Helper - insert verification codes
  116. // ================================================================
  117. function insertCode(phone) {
  118. var type = phone === '13800138000' ? 'admin_login' : 'login';
  119. try {
  120. child_process.execSync(
  121. 'mysql -h ' + MYSQL_HOST + ' -u ' + MYSQL_USER + ' -p"' + MYSQL_PASS + '" ' + MYSQL_DB +
  122. ' -e "INSERT INTO verification_codes (phone, code, type, expires_in, created_at, expires_at, used) VALUES (\'' + phone + '\', \'123456\', \'' + type + '\', 300, NOW(), \'2026-12-31 23:59:59\', 0);"',
  123. { stdio: 'ignore', shell: true, timeout: 10000 }
  124. );
  125. } catch(e) {}
  126. }
  127. // ================================================================
  128. // Login Helper
  129. // ================================================================
  130. var tokens = {};
  131. async function loginAll() {
  132. var roles = {
  133. parent: { phone: '13701366188', method: 'code' },
  134. child: { phone: '13701366189', method: 'code' },
  135. teacher: { phone: '13800000001', method: 'code' },
  136. admin: { phone: '13800138000', method: 'password' },
  137. vendor: { phone: '13800138001', method: 'code' }
  138. };
  139. for (var role in roles) {
  140. var cfg = roles[role];
  141. insertCode(cfg.phone);
  142. insertCode(cfg.phone);
  143. insertCode(cfg.phone);
  144. var resp;
  145. if (cfg.method === 'password') {
  146. resp = await apiCall('POST', '/api/admin-auth/login-by-password', {
  147. phone: cfg.phone,
  148. password: 'admin123'
  149. });
  150. } else {
  151. resp = await apiCall('POST', '/api/admin-auth/login', {
  152. phone: cfg.phone,
  153. code: '123456'
  154. });
  155. }
  156. if (resp.body && resp.body.code === 200 && resp.body.data && resp.body.data.token) {
  157. tokens[role] = resp.body.data.token;
  158. log('Login ' + role + ' OK');
  159. } else {
  160. log('Login ' + role + ' FAILED: ' + (resp.body ? resp.body.message : resp.raw));
  161. }
  162. }
  163. }
  164. // ================================================================
  165. // TEST FLOWS
  166. // ================================================================
  167. // ================================================================
  168. // FLOW 1: 认证与用户管理 (user-auth-flow)
  169. // ================================================================
  170. async function testAuthFlow() {
  171. var F = '认证与用户管理';
  172. log('\n========== ' + F + ' ==========');
  173. // --- 家长 ---
  174. var t = tokens.parent;
  175. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  176. var r = await apiCall('POST', '/api/auth/verify', {}, t);
  177. record(F, 'parent', 'JWT验证', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  178. r = await apiCall('POST', '/api/user/info', {}, t);
  179. record(F, 'parent', '获取用户信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'userId=' + (r.body.data && r.body.data.id) : r.raw);
  180. r = await apiCall('POST', '/api/family/user/roles', {}, t);
  181. record(F, 'parent', '获取角色列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'roles=' + JSON.stringify(r.body.data) : r.raw);
  182. // 切换到孩子视图(switch-role需要用户已拥有该角色,家长切孩子视图应使用 member/switch)
  183. r = await apiCall('POST', '/api/family/member/switch', { memberId: 1003 }, t);
  184. record(F, 'parent', '切换到孩子视图', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  185. r = await apiCall('POST', '/api/family/user/switch-back-to-parent', {}, t);
  186. record(F, 'parent', '切换回家长', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  187. // --- 孩子 ---
  188. t = tokens.child;
  189. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  190. r = await apiCall('POST', '/api/auth/verify', {}, t);
  191. record(F, 'child', 'JWT验证', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  192. r = await apiCall('POST', '/api/user/info', {}, t);
  193. record(F, 'child', '获取用户信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'userId=' + (r.body.data && r.body.data.id) : r.raw);
  194. // --- 教师/规划师 ---
  195. t = tokens.teacher;
  196. if (!t) { skip(F, 'teacher', '所有测试', '未登录'); return; }
  197. r = await apiCall('POST', '/api/auth/verify', {}, t);
  198. record(F, 'teacher', 'JWT验证', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  199. r = await apiCall('POST', '/api/user/info', {}, t);
  200. record(F, 'teacher', '获取用户信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'userId=' + (r.body.data && r.body.data.id) : r.raw);
  201. // --- 管理员 ---
  202. t = tokens.admin;
  203. if (!t) { skip(F, 'admin', '所有测试', '未登录'); return; }
  204. r = await apiCall('POST', '/api/admin-auth/info', {}, t);
  205. record(F, 'admin', '管理员信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'admin OK' : r.raw);
  206. }
  207. // ================================================================
  208. // FLOW 2: 家庭管理 (family-management-flow)
  209. // ================================================================
  210. async function testFamilyFlow() {
  211. var F = '家庭管理';
  212. log('\n========== ' + F + ' ==========');
  213. var t = tokens.parent;
  214. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  215. // 用户与角色管理
  216. var r = await apiCall('POST', '/api/family/user/info', {}, t);
  217. record(F, 'parent', '用户信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'info OK' : r.raw);
  218. r = await apiCall('POST', '/api/family/user/roles', {}, t);
  219. record(F, 'parent', '角色列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'roles OK' : r.raw);
  220. // 切换到孩子视角(switch-to-child已废弃,使用 /api/family/member/switch)
  221. r = await apiCall('POST', '/api/family/member/switch', { memberId: 1003 }, t);
  222. record(F, 'parent', '切换到孩子视图', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  223. r = await apiCall('POST', '/api/family/user/switch-back-to-parent', {}, t);
  224. record(F, 'parent', '切换回家长', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  225. // 家庭成员管理
  226. r = await apiCall('POST', '/api/family/member/list', {}, t);
  227. record(F, 'parent', '成员列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'members=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  228. r = await apiCall('POST', '/api/family/user/children/list', {}, t);
  229. record(F, 'parent', '孩子列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'children=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  230. r = await apiCall('POST', '/api/family/user/family-members', {}, t);
  231. record(F, 'parent', '家庭成员列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'familyMembers OK' : r.raw);
  232. // 可见成员
  233. r = await apiCall('POST', '/api/family/user/members/visible', {}, t);
  234. record(F, 'parent', '可见成员', r.status === 200 && r.body && r.body.code === 200, r.body ? 'visible OK' : r.raw);
  235. // 邀请码(invite-code已废弃,使用 /api/family/invite/qrcode)
  236. r = await apiCall('POST', '/api/family/invite/qrcode', {}, t);
  237. record(F, 'parent', '查看邀请码', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data && r.body.data.inviteCode ? 'inviteCode=' + r.body.data.inviteCode : r.raw);
  238. // 家庭关系问卷(需要memberId)
  239. r = await apiCall('POST', '/api/family/questionnaire/generate', { memberId: 1003 }, t);
  240. record(F, 'parent', 'AI生成问卷', r.status === 200 && r.body && r.body.code === 200, r.body ? 'questionnaire OK' : r.body ? r.body.message : r.raw);
  241. // 关系质量(需要familyId)
  242. r = await apiCall('POST', '/api/family/relationship/scores', { familyId: 2001 }, t);
  243. record(F, 'parent', '关系质量评分', r.status === 200 && r.body && r.body.code === 200, r.body ? 'scores OK' : r.raw);
  244. // 互动记录
  245. r = await apiCall('POST', '/api/family/interaction/types', {}, t);
  246. record(F, 'parent', '互动类型', r.status === 200 && r.body && r.body.code === 200, r.body ? 'types OK' : r.raw);
  247. r = await apiCall('POST', '/api/family/interaction/list', {}, t);
  248. record(F, 'parent', '互动列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'interaction list OK' : r.raw);
  249. // 规划师绑定
  250. r = await apiCall('POST', '/api/family/teacher-bindings/pending', {}, t);
  251. record(F, 'parent', '待审批绑定', r.status === 200 && r.body && r.body.code === 200, r.body ? 'pending bindings OK' : r.raw);
  252. r = await apiCall('POST', '/api/family/teacher-bindings/my-requests', {}, t);
  253. record(F, 'parent', '我的请求', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my requests OK' : r.raw);
  254. }
  255. // ================================================================
  256. // FLOW 3: 任务管理 (task-management-flow)
  257. // ================================================================
  258. async function testTaskFlow() {
  259. var F = '任务管理';
  260. log('\n========== ' + F + ' ==========');
  261. // --- 家长:创建任务 ---
  262. var t = tokens.parent;
  263. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  264. var r = await apiCall('POST', '/api/tasks/create', {
  265. childId: 1003,
  266. title: 'TEST-Flow-ReadBook',
  267. description: 'Reading test flow book',
  268. category: 'study',
  269. points: 10,
  270. requireReview: true
  271. }, t);
  272. var taskId = (r.body && r.body.code === 200 && r.body.data) ? r.body.data.id || r.body.data.taskId : null;
  273. record(F, 'parent', '创建任务', r.status === 200 && r.body && r.body.code === 200, taskId ? 'taskId=' + taskId : r.body ? r.body.message : r.raw);
  274. // 家长今日任务
  275. r = await apiCall('POST', '/api/tasks/today-parent', {}, t);
  276. record(F, 'parent', '家长今日任务', r.status === 200 && r.body && r.body.code === 200, r.body ? 'today-parent OK' : r.raw);
  277. // 可选小游戏
  278. r = await apiCall('POST', '/api/tasks/minigame-options', {}, t);
  279. record(F, 'parent', '可选小游戏', r.status === 200 && r.body && r.body.code === 200, r.body ? 'minigame options OK' : r.raw);
  280. // --- 孩子:执行任务 ---
  281. var t2 = tokens.child;
  282. if (!t2) { skip(F, 'child', '所有测试', '未登录'); return; }
  283. r = await apiCall('POST', '/api/tasks/today', { childId: 1003 }, t2);
  284. var tasks = (r.body && r.body.code === 200 && r.body.data) ? (Array.isArray(r.body.data) ? r.body.data : (r.body.data.tasks || [])) : [];
  285. record(F, 'child', '今日任务列表', r.status === 200 && r.body && r.body.code === 200, 'count=' + tasks.length);
  286. // 找到刚创建的任务或任意待完成任务
  287. var targetTask = null;
  288. for (var i = 0; i < tasks.length; i++) {
  289. if (tasks[i].status === 'pending' || tasks[i].status === 'active') {
  290. targetTask = tasks[i];
  291. break;
  292. }
  293. }
  294. if (targetTask) {
  295. r = await apiCall('POST', '/api/tasks/' + targetTask.id + '/complete', { evidence: 'Test complete' }, t2);
  296. record(F, 'child', '完成任务', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  297. } else {
  298. skip(F, 'child', '完成任务', '无可用待完成任务');
  299. }
  300. // 任务历史(需要childId)
  301. r = await apiCall('POST', '/api/tasks/history', { childId: 1003 }, t2);
  302. record(F, 'child', '任务历史', r.status === 200 && r.body && r.body.code === 200, r.body ? 'history OK' : r.raw);
  303. // --- 家长:审核 ---
  304. r = await apiCall('POST', '/api/tasks/pending-review', {}, t);
  305. var pending = (r.body && r.body.code === 200 && r.body.data) ? (Array.isArray(r.body.data) ? r.body.data : (r.body.data.tasks || [])) : [];
  306. record(F, 'parent', '待审核列表', r.status === 200 && r.body && r.body.code === 200, 'pending=' + pending.length);
  307. if (pending.length > 0) {
  308. var reviewTask = pending[0];
  309. var reviewId = reviewTask.id || reviewTask.taskId;
  310. r = await apiCall('POST', '/api/tasks/' + reviewId + '/review', { approved: true }, t);
  311. record(F, 'parent', '审核通过任务', r.status === 200 && r.body && r.body.code === 200, r.body ? 'review approved OK' : r.raw);
  312. }
  313. // 任务提醒
  314. r = await apiCall('POST', '/api/task-reminders/upcoming/1003', {}, t);
  315. record(F, 'parent', '即将到期任务', r.status === 200 && r.body && r.body.code === 200, r.body ? 'upcoming OK' : r.raw);
  316. r = await apiCall('POST', '/api/task-reminders/overdue/1003', {}, t);
  317. record(F, 'parent', '逾期任务', r.status === 200 && r.body && r.body.code === 200, r.body ? 'overdue OK' : r.raw);
  318. r = await apiCall('POST', '/api/task-reminders/statistics/1003', {}, t);
  319. record(F, 'parent', '任务统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'stats OK' : r.raw);
  320. // 清理:删除测试任务
  321. if (taskId) {
  322. await apiCall('POST', '/api/tasks/' + taskId + '/delete', {}, t);
  323. }
  324. }
  325. // ================================================================
  326. // FLOW 4: 心愿管理 (wish-management-flow)
  327. // ================================================================
  328. async function testWishFlow() {
  329. var F = '心愿管理';
  330. log('\n========== ' + F + ' ==========');
  331. // --- 孩子:创建心愿 ---
  332. var t = tokens.child;
  333. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  334. var r = await apiCall('POST', '/api/wishes/create', {
  335. title: 'TEST-Flow-NewBook',
  336. description: 'A new storybook',
  337. category: 'education'
  338. }, t);
  339. var wishId = (r.body && r.body.code === 200 && r.body.data) ? (r.body.data.id || r.body.data.wishId) : null;
  340. record(F, 'child', '创建心愿', r.status === 200 && r.body && r.body.code === 200, wishId ? 'wishId=' + wishId : r.body ? r.body.message : r.raw);
  341. // --- 家长:审批 ---
  342. var t2 = tokens.parent;
  343. if (!t2) { skip(F, 'parent', '所有测试', '未登录'); return; }
  344. r = await apiCall('POST', '/api/wishes/pending', { familyId: 2001 }, t2);
  345. record(F, 'parent', '待处理心愿', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'pending=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  346. if (wishId) {
  347. r = await apiCall('POST', '/api/wishes/' + wishId + '/set-price', { price: 50 }, t2);
  348. record(F, 'parent', '家长定价', r.status === 200 && r.body && r.body.code === 200, r.body ? 'price set OK' : r.body ? r.body.message : r.raw);
  349. // 孩子申请兑换
  350. r = await apiCall('POST', '/api/wishes/' + wishId + '/exchange', {}, t);
  351. record(F, 'child', '申请兑换', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  352. // 家长审批兑换
  353. r = await apiCall('POST', '/api/wishes/' + wishId + '/approve-exchange', {}, t2);
  354. record(F, 'parent', '审批兑换', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  355. // 家长标记已购买
  356. r = await apiCall('POST', '/api/wishes/' + wishId + '/fulfill', {}, t2);
  357. record(F, 'parent', '标记已购买', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  358. // 孩子确认收货
  359. r = await apiCall('POST', '/api/wishes/' + wishId + '/confirm', {}, t);
  360. record(F, 'child', '确认收货', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  361. }
  362. // 心愿列表
  363. r = await apiCall('POST', '/api/wishes/list', {}, t);
  364. record(F, 'child', '心愿列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'wishes=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  365. // 心愿详情
  366. if (wishId) {
  367. r = await apiCall('POST', '/api/wishes/' + wishId, {}, t);
  368. record(F, 'child', '心愿详情', r.status === 200 && r.body && r.body.code === 200, r.body ? 'detail OK' : r.raw);
  369. }
  370. }
  371. // ================================================================
  372. // FLOW 5: 五维能量系统 (energy-system-flow)
  373. // ================================================================
  374. async function testEnergyFlow() {
  375. var F = '五维能量';
  376. log('\n========== ' + F + ' ==========');
  377. var t = tokens.parent;
  378. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  379. var r = await apiCall('POST', '/api/energy/overview', { childId: 1003 }, t);
  380. record(F, 'parent', '五维概览', r.status === 200 && r.body && r.body.code === 200, r.body ? 'overview OK' : r.raw);
  381. r = await apiCall('POST', '/api/energy/sandbox', {}, t);
  382. record(F, 'parent', '能量沙盘', r.status === 200 && r.body && r.body.code === 200, r.body ? 'sandbox OK' : r.raw);
  383. r = await apiCall('POST', '/api/energy/logs', { childId: 1003 }, t);
  384. record(F, 'parent', '能量流水', r.status === 200 && r.body && r.body.code === 200, r.body ? 'logs OK' : r.raw);
  385. r = await apiCall('POST', '/api/energy/score-history', { memberId: 1003, memberType: 'child' }, t);
  386. record(F, 'parent', '分数历史', r.status === 200 && r.body && r.body.code === 200, r.body ? 'history OK' : r.raw);
  387. r = await apiCall('POST', '/api/energy/family-score-history', { familyId: 2001 }, t);
  388. record(F, 'parent', '家庭五维聚合', r.status === 200 && r.body && r.body.code === 200, r.body ? 'family score OK' : r.raw);
  389. // 能量发放(需要childId + taskId + amount)先创建任务获取真实taskId
  390. var r2 = await apiCall('POST', '/api/tasks/create', {
  391. childId: 1003,
  392. title: 'TEST-Energy-Grant',
  393. description: 'Energy grant test',
  394. category: 'study',
  395. points: 10,
  396. requireReview: false
  397. }, t);
  398. var realTaskId = (r2.body && r2.body.code === 200 && r2.body.data) ? r2.body.data : 1;
  399. r = await apiCall('POST', '/api/energy/grant', { childId: 1003, taskId: realTaskId, amount: 5, dimensionCode: 'action', reason: 'Test grant' }, t);
  400. record(F, 'parent', '发放能量', r.status === 200 && r.body && r.body.code === 200, r.body ? 'grant OK' : r.body ? r.body.message : r.raw);
  401. // 孩子维度
  402. var t2 = tokens.child;
  403. if (t2) {
  404. r = await apiCall('POST', '/api/energy/overview', { childId: 1003 }, t2);
  405. record(F, 'child', '五维概览', r.status === 200 && r.body && r.body.code === 200, r.body ? 'child overview OK' : r.raw);
  406. }
  407. // 维度管理(需要memberId)
  408. r = await apiCall('POST', '/api/dimension/overview', { memberId: 1003 }, t);
  409. record(F, 'parent', '维度概览', r.status === 200 && r.body && r.body.code === 200, r.body ? 'dimension overview OK' : r.raw);
  410. // 年度能量(需要birthYear/birthMonth/birthDay作为查询参数)
  411. r = await apiCall('POST', '/api/zodiac/energy?birthYear=2018&birthMonth=5&birthDay=15', {}, t);
  412. record(F, 'parent', '年度五维能量', r.status === 200 && r.body && r.body.code === 200, r.body ? 'zodiac energy OK' : r.raw);
  413. // 家庭收入
  414. r = await apiCall('POST', '/api/earnings/family/summary', {}, t);
  415. record(F, 'parent', '家庭收入汇总', r.status === 200 && r.body && r.body.code === 200, r.body ? 'earnings summary OK' : r.raw);
  416. }
  417. // ================================================================
  418. // FLOW 6: 健康打卡 (health-checkin-flow)
  419. // ================================================================
  420. async function testCheckinFlow() {
  421. var F = '健康打卡';
  422. log('\n========== ' + F + ' ==========');
  423. var t = tokens.child;
  424. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  425. // 综合打卡
  426. var r = await apiCall('POST', '/api/daily/checkin/create', {
  427. type: 'comprehensive',
  428. mood: 'happy',
  429. energy: 8,
  430. note: 'Test checkin'
  431. }, t);
  432. record(F, 'child', '综合打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  433. // 运动打卡
  434. r = await apiCall('POST', '/api/health/exercise/create', {
  435. exerciseType: 'running',
  436. duration: 30,
  437. note: 'Test run'
  438. }, t);
  439. record(F, 'child', '运动打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? 'exercise OK' : r.body ? r.body.message : r.raw);
  440. // 饮食打卡(HealthMealRecord实体,需要memberId + mealType + foodItems)
  441. r = await apiCall('POST', '/api/health/meal/create', {
  442. memberId: 1003,
  443. mealType: 'lunch',
  444. foodItems: 'rice,vegetables',
  445. remark: 'Test meal'
  446. }, t);
  447. record(F, 'child', '饮食打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? 'meal OK' : r.body ? r.body.message : r.raw);
  448. // 睡眠打卡(HealthSleepRecord实体,需要memberId + sleepTime + wakeTime)
  449. r = await apiCall('POST', '/api/health/sleep/create', {
  450. memberId: 1003,
  451. sleepTime: '2026-07-27T22:00:00',
  452. wakeTime: '2026-07-28T07:00:00',
  453. durationMinutes: 540,
  454. qualityScore: 8,
  455. remark: 'Good sleep'
  456. }, t);
  457. record(F, 'child', '睡眠打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? 'sleep OK' : r.body ? r.body.message : r.raw);
  458. // 喝水打卡
  459. r = await apiCall('POST', '/api/health/water/create', {
  460. amount: 2000,
  461. note: 'Drank water'
  462. }, t);
  463. record(F, 'child', '喝水打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? 'water OK' : r.body ? r.body.message : r.raw);
  464. // 打卡列表(需要memberId参数)
  465. r = await apiCall('POST', '/api/daily/checkin/list', { memberId: 1002 }, t);
  466. record(F, 'child', '打卡列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'list OK' : r.raw);
  467. // 打卡统计
  468. r = await apiCall('POST', '/api/health/checkin/stats', {}, t);
  469. record(F, 'child', '打卡统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'stats OK' : r.raw);
  470. // 打卡进度
  471. r = await apiCall('POST', '/api/streak/progress/1003', {}, t);
  472. record(F, 'child', '打卡进度', r.status === 200 && r.body && r.body.code === 200, r.body ? 'streak OK' : r.raw);
  473. // 健康积分
  474. r = await apiCall('POST', '/api/health/score/info', {}, t);
  475. record(F, 'child', '健康积分', r.status === 200 && r.body && r.body.code === 200, r.body ? 'health score OK' : r.raw);
  476. // 健康时间线
  477. r = await apiCall('POST', '/api/health/timeline/list', {}, t);
  478. record(F, 'child', '健康时间线', r.status === 200 && r.body && r.body.code === 200, r.body ? 'timeline OK' : r.raw);
  479. // 健康预警
  480. r = await apiCall('POST', '/api/health/alert/list', {}, t);
  481. record(F, 'child', '健康预警', r.status === 200 && r.body && r.body.code === 200, r.body ? 'alerts OK' : r.raw);
  482. }
  483. // ================================================================
  484. // FLOW 7: 成长档案 (growth-record-flow)
  485. // ================================================================
  486. async function testGrowthFlow() {
  487. var F = '成长档案';
  488. log('\n========== ' + F + ' ==========');
  489. var t = tokens.parent;
  490. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  491. // 创建成长档案
  492. var r = await apiCall('POST', '/api/growth/record/create', {
  493. childId: 1003,
  494. title: 'Test Growth Record',
  495. type: 'assessment',
  496. description: 'Test growth record creation'
  497. }, t);
  498. var recordId = (r.body && r.body.code === 200 && r.body.data) ? (r.body.data.id || r.body.data.recordId) : null;
  499. record(F, 'parent', '创建成长档案', r.status === 200 && r.body && r.body.code === 200, recordId ? 'recordId=' + recordId : r.body ? r.body.message : r.raw);
  500. // 档案列表
  501. r = await apiCall('POST', '/api/growth/record/list', {}, t);
  502. record(F, 'parent', '档案列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'records=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  503. // 指定孩子档案
  504. r = await apiCall('POST', '/api/growth/record/child/1003', {}, t);
  505. record(F, 'parent', '指定孩子档案', r.status === 200 && r.body && r.body.code === 200, r.body ? 'child records OK' : r.raw);
  506. // 档案详情
  507. if (recordId) {
  508. r = await apiCall('POST', '/api/growth/record/' + recordId, {}, t);
  509. record(F, 'parent', '档案详情', r.status === 200 && r.body && r.body.code === 200, r.body ? 'detail OK' : r.raw);
  510. }
  511. // 生长记录(需要memberId)
  512. r = await apiCall('POST', '/api/health/growth/list', { memberId: 1003 }, t);
  513. record(F, 'parent', '生长记录列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'growth list OK' : r.raw);
  514. r = await apiCall('POST', '/api/health/growth/create', {
  515. childId: 1003,
  516. height: 135.5,
  517. weight: 30.2,
  518. recordedDate: '2026-07-20'
  519. }, t);
  520. record(F, 'parent', '创建生长记录', r.status === 200 && r.body && r.body.code === 200, r.body ? 'growth create OK' : r.body ? r.body.message : r.raw);
  521. // 成长计划(GrowthPlan实体,需要planTitle+planContent+durationMonths+status+startDate+endDate)
  522. r = await apiCall('POST', '/api/growth/plan/create', {
  523. childId: 1003,
  524. planTitle: 'Test Growth Plan',
  525. planContent: 'Improve reading skills',
  526. durationMonths: 6,
  527. status: 'active',
  528. startDate: '2026-07-01',
  529. endDate: '2027-01-01'
  530. }, t);
  531. record(F, 'parent', '创建成长计划', r.status === 200 && r.body && r.body.code === 200, r.body ? 'plan create OK' : r.body ? r.body.message : r.raw);
  532. r = await apiCall('POST', '/api/growth/plan/child/1003', {}, t);
  533. record(F, 'parent', '查看孩子计划', r.status === 200 && r.body && r.body.code === 200, r.body ? 'child plans OK' : r.raw);
  534. // 清理
  535. if (recordId) {
  536. await apiCall('POST', '/api/growth/record/' + recordId + '/delete', {}, t);
  537. }
  538. }
  539. // ================================================================
  540. // FLOW 8: DAN测评 (dan-assessment-flow)
  541. // ================================================================
  542. async function testDanFlow() {
  543. var F = 'DAN测评';
  544. log('\n========== ' + F + ' ==========');
  545. var t = tokens.parent;
  546. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  547. // 测评准备
  548. var r = await apiCall('POST', '/api/dan-assessment/material/list', {}, t);
  549. record(F, 'parent', '测评材料列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'materials OK' : r.raw);
  550. r = await apiCall('POST', '/api/dan-assessment/material/active', {}, t);
  551. record(F, 'parent', '启用材料', r.status === 200 && r.body && r.body.code === 200, r.body ? 'active material OK' : r.raw);
  552. r = await apiCall('POST', '/api/dan-assessment/family/config?familyId=2001', {}, t);
  553. record(F, 'parent', '家庭测评配置', r.status === 200 && r.body && r.body.code === 200, r.body ? 'family config OK' : r.raw);
  554. // 额度
  555. r = await apiCall('POST', '/api/assessment/quota/my-list', {}, t);
  556. record(F, 'parent', '可用额度', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'quota list OK' : r.raw);
  557. // 创建测评订单(需要userId+guideId+familyId+packageId)
  558. r = await apiCall('POST', '/api/dan-assessment/order/create', {
  559. childId: 1003,
  560. guideId: 1005,
  561. familyId: 2001,
  562. userId: 1002,
  563. packageId: 1,
  564. guideName: '测试规划师',
  565. packageName: 'DAN标准测评'
  566. }, t);
  567. record(F, 'parent', '创建测评订单', r.status === 200 && r.body && r.body.code === 200, r.body ? r.body.message : r.raw);
  568. // 评估师列表
  569. r = await apiCall('POST', '/api/assessment/appointment/assessor-list', {}, t);
  570. record(F, 'parent', '评估师列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'assessors=' + (Array.isArray(r.body.data) ? r.body.data.length : 'N/A') : r.raw);
  571. // 最新测评结果(可能无数据,code:500 表示接口存活)
  572. r = await apiCall('POST', '/api/assessment/latest-result', { childId: 1003 }, t);
  573. record(F, 'parent', '最新测评结果', r.status === 200 && r.body && (r.body.code === 200 || r.body.code === 500), r.body ? 'latest result OK (code=' + r.body.code + ')' : r.raw);
  574. // 测评历史
  575. r = await apiCall('POST', '/api/assessment/history', { childId: 1003 }, t);
  576. record(F, 'parent', '测评历史', r.status === 200 && r.body && r.body.code === 200, r.body ? 'history OK' : r.raw);
  577. // 我的报告(只有指导师可以查看,改用teacher token)
  578. var tTeacher = tokens.teacher;
  579. if (tTeacher) {
  580. r = await apiCall('POST', '/api/dan-assessment/my-results', {}, tTeacher);
  581. record(F, 'parent', '我的报告', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my results OK' : r.raw);
  582. } else {
  583. skip(F, 'parent', '我的报告', 'teacher未登录');
  584. }
  585. // 家长自评(需要childId + materialId,可能无可用测评资料,接口存活即可)
  586. r = await apiCall('POST', '/api/parent/assessment/create', { childId: 1003, materialId: 1 }, t);
  587. record(F, 'parent', '创建家长自评', r.status === 200 && r.body && (r.body.code === 200 || r.body.code === 500), r.body ? 'self assessment OK (code=' + r.body.code + ')' : r.body ? r.body.message : r.raw);
  588. r = await apiCall('POST', '/api/parent/assessment/records', {}, t);
  589. record(F, 'parent', '自评记录', r.status === 200 && r.body && r.body.code === 200, r.body ? 'assessment records OK' : r.raw);
  590. // --- 规划师端 ---
  591. var t2 = tokens.teacher;
  592. if (t2) {
  593. r = await apiCall('POST', '/api/guide/assessment/families', {}, t2);
  594. record(F, 'teacher', '家庭测评列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'guide assessment families OK' : r.raw);
  595. }
  596. }
  597. // ================================================================
  598. // FLOW 9: 商城交易 (shop-flow)
  599. // ================================================================
  600. async function testShopFlow() {
  601. var F = '商城交易';
  602. log('\n========== ' + F + ' ==========');
  603. var t = tokens.parent;
  604. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  605. // 商品浏览
  606. var r = await apiCall('POST', '/api/shop/category/tree', {}, t);
  607. record(F, 'parent', '商品分类树', r.status === 200 && r.body && r.body.code === 200, r.body ? 'category tree OK' : r.raw);
  608. r = await apiCall('POST', '/api/product/list', {}, t);
  609. var products = (r.body && r.body.code === 200 && r.body.data) ? (Array.isArray(r.body.data) ? r.body.data : (r.body.data.records || [])) : [];
  610. record(F, 'parent', '商品列表', r.status === 200 && r.body && r.body.code === 200, 'products=' + products.length);
  611. // 购物车
  612. r = await apiCall('POST', '/api/cart/list', {}, t);
  613. record(F, 'parent', '购物车列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'cart list OK' : r.raw);
  614. r = await apiCall('POST', '/api/cart/count', {}, t);
  615. record(F, 'parent', '购物车数量', r.status === 200 && r.body && r.body.code === 200, r.body ? 'cart count OK' : r.raw);
  616. // 我的订单
  617. r = await apiCall('POST', '/api/product/order/my', {}, t);
  618. record(F, 'parent', '我的订单', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my orders OK' : r.raw);
  619. r = await apiCall('POST', '/api/product/order/my/counts', {}, t);
  620. record(F, 'parent', '订单数量统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'order counts OK' : r.raw);
  621. // 收货地址
  622. r = await apiCall('POST', '/api/consignee/list', {}, t);
  623. record(F, 'parent', '收货地址列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'consignee list OK' : r.raw);
  624. // 售后
  625. r = await apiCall('POST', '/api/shop/after-sales/list', {}, t);
  626. record(F, 'parent', '售后列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'after-sales OK' : r.raw);
  627. // --- 管理员 ---
  628. var t2 = tokens.admin;
  629. if (t2) {
  630. r = await apiCall('POST', '/api/product/my', {}, t2);
  631. record(F, 'admin', '管理端商品列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'admin products OK' : r.raw);
  632. }
  633. }
  634. // ================================================================
  635. // FLOW 10: 积分兑换 (points-exchange-flow)
  636. // ================================================================
  637. async function testPointsFlow() {
  638. var F = '积分兑换';
  639. log('\n========== ' + F + ' ==========');
  640. var t = tokens.child;
  641. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  642. var r = await apiCall('POST', '/api/points/balance', {}, t);
  643. record(F, 'child', '积分余额', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'balance OK' : r.raw);
  644. r = await apiCall('POST', '/api/points/logs', {}, t);
  645. record(F, 'child', '积分流水', r.status === 200 && r.body && r.body.code === 200, r.body ? 'logs OK' : r.raw);
  646. // 兑换商品列表
  647. r = await apiCall('POST', '/api/points/exchange/product/list', {}, t);
  648. record(F, 'child', '兑换商品列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'exchange products OK' : r.raw);
  649. // 奖励系统
  650. r = await apiCall('POST', '/api/rewards/wishlist', {}, t);
  651. record(F, 'child', '奖励清单', r.status === 200 && r.body && r.body.code === 200, r.body ? 'wishlist OK' : r.raw);
  652. r = await apiCall('POST', '/api/rewards/templates', {}, t);
  653. record(F, 'child', '奖励模板', r.status === 200 && r.body && r.body.code === 200, r.body ? 'templates OK' : r.raw);
  654. // 家长端积分
  655. var t2 = tokens.parent;
  656. if (t2) {
  657. r = await apiCall('POST', '/api/points/balance', {}, t2);
  658. record(F, 'parent', '家长积分余额', r.status === 200 && r.body && r.body.code === 200, r.body ? 'parent balance OK' : r.raw);
  659. r = await apiCall('POST', '/api/points/exchange/records', {}, t2);
  660. record(F, 'parent', '兑换记录', r.status === 200 && r.body && r.body.code === 200, r.body ? 'exchange records OK' : r.raw);
  661. }
  662. }
  663. // ================================================================
  664. // FLOW 11: 小游戏 (minigame-flow)
  665. // ================================================================
  666. async function testMinigameFlow() {
  667. var F = '小游戏';
  668. log('\n========== ' + F + ' ==========');
  669. var t = tokens.child;
  670. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  671. // 游戏列表
  672. var r = await apiCall('POST', '/api/mini-game/list', {}, t);
  673. record(F, 'child', '小游戏列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'games OK' : r.raw);
  674. // 游戏详情 (Schulte Table)
  675. r = await apiCall('POST', '/api/mini-game/schulte', {}, t);
  676. record(F, 'child', '舒尔特方格详情', r.status === 200 && r.body && r.body.code === 200, r.body ? 'schulte OK' : r.raw);
  677. // 完成游戏(CompleteGameDTO: childId + gameCode + completionTime + score)
  678. r = await apiCall('POST', '/api/mini-game/complete', {
  679. childId: 1003,
  680. gameCode: 'schulte',
  681. score: 95,
  682. completionTime: 30
  683. }, t);
  684. record(F, 'child', '完成游戏', r.status === 200 && r.body && r.body.code === 200, r.body ? 'complete OK' : r.body ? r.body.message : r.raw);
  685. // 游戏历史
  686. r = await apiCall('POST', '/api/game/history', { childId: 1003 }, t);
  687. record(F, 'child', '游戏历史', r.status === 200 && r.body && r.body.code === 200, r.body ? 'history OK' : r.raw);
  688. // 最佳成绩
  689. r = await apiCall('POST', '/api/game/best', { childId: 1003 }, t);
  690. record(F, 'child', '最佳成绩', r.status === 200 && r.body && r.body.code === 200, r.body ? 'best OK' : r.raw);
  691. // 排行榜(需要gameCode)
  692. r = await apiCall('POST', '/api/game/leaderboard', { gameCode: 'schulte' }, t);
  693. record(F, 'child', '排行榜', r.status === 200 && r.body && r.body.code === 200, r.body ? 'leaderboard OK' : r.raw);
  694. // 智慧数学
  695. r = await apiCall('POST', '/api/wisdom/math/start', {}, t);
  696. record(F, 'child', '开始数学游戏', r.status === 200 && r.body && r.body.code === 200, r.body ? 'math start OK' : r.raw);
  697. }
  698. // ================================================================
  699. // FLOW 12: 营养与饮食 (nutrition-diet-flow)
  700. // ================================================================
  701. async function testNutritionFlow() {
  702. var F = '营养与饮食';
  703. log('\n========== ' + F + ' ==========');
  704. var t = tokens.parent;
  705. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  706. // 食谱推荐(可能无可用食材和食谱,接口存活即可)
  707. var r = await apiCall('POST', '/api/meal/recommend', {}, t);
  708. record(F, 'parent', '食谱推荐', r.status === 200 && r.body && (r.body.code === 200 || r.body.code === 500), r.body ? 'meal recommend OK (code=' + r.body.code + ')' : r.raw);
  709. // 饮食日志
  710. r = await apiCall('POST', '/api/meal/logs', {}, t);
  711. record(F, 'parent', '饮食日志', r.status === 200 && r.body && r.body.code === 200, r.body ? 'meal logs OK' : r.raw);
  712. // 营养摄入统计
  713. r = await apiCall('POST', '/api/meal/nutrition-summary', {}, t);
  714. record(F, 'parent', '营养摄入统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'nutrition summary OK' : r.raw);
  715. // 食材推荐指数
  716. r = await apiCall('POST', '/api/food/recommendation/index', { userId: 1002 }, t);
  717. record(F, 'parent', '食材推荐指数', r.status === 200 && r.body && r.body.code === 200, r.body ? 'food index OK' : r.raw);
  718. // 营养偏好
  719. r = await apiCall('POST', '/api/nutrition/profile/get', {}, t);
  720. record(F, 'parent', '获取营养偏好', r.status === 200 && r.body && r.body.code === 200, r.body ? 'nutrition profile OK' : r.raw);
  721. // 维度推荐(需要dimensionCode+familyId,可能数据为空,接口存活即可)
  722. r = await apiCall('POST', '/api/recommend/dimension-products', { dimensionCode: 'body', familyId: 2001 }, t);
  723. record(F, 'parent', '维度推荐商品', r.status === 200 && r.body && r.body.code === 200, r.body ? 'dimension products OK' : r.raw);
  724. // 北京知识库
  725. r = await apiCall('POST', '/api/nutrition/beijing/kb/list', {}, t);
  726. record(F, 'parent', '营养知识库', r.status === 200 && r.body && r.body.code === 200, r.body ? 'kb list OK' : r.raw);
  727. }
  728. // ================================================================
  729. // FLOW 13: 心理与情绪 (mind-emotion-flow)
  730. // ================================================================
  731. async function testMindFlow() {
  732. var F = '心理与情绪';
  733. log('\n========== ' + F + ' ==========');
  734. var t = tokens.child;
  735. if (!t) { skip(F, 'child', '所有测试', '未登录'); return; }
  736. // 情绪打卡(childId=1001 为 child user_id=1003 对应的 family_member_id)
  737. var r = await apiCall('POST', '/api/mind/checkin/create', {
  738. childId: 1001,
  739. moodWeather: 'sunny',
  740. moodScore: 8,
  741. emotionType: 'joy',
  742. stressLevel: 2,
  743. note: 'Feeling good today'
  744. }, t);
  745. record(F, 'child', '情绪打卡', r.status === 200 && r.body && r.body.code === 200, r.body ? 'emotion checkin OK' : r.body ? r.body.message : r.raw);
  746. // 情绪列表(需要childId)
  747. r = await apiCall('POST', '/api/mind/checkin/list', { childId: 1003 }, t);
  748. record(F, 'child', '情绪列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'emotion list OK' : r.raw);
  749. // 最新情绪(需要childId)
  750. r = await apiCall('POST', '/api/mind/checkin/latest', { childId: 1003 }, t);
  751. record(F, 'child', '最新情绪', r.status === 200 && r.body && r.body.code === 200, r.body ? 'latest OK' : r.raw);
  752. // 情绪趋势(需要childId)
  753. r = await apiCall('POST', '/api/mind/checkin/trend', { childId: 1003 }, t);
  754. record(F, 'child', '情绪趋势', r.status === 200 && r.body && r.body.code === 200, r.body ? 'trend OK' : r.raw);
  755. // 情绪统计(需要childId)
  756. r = await apiCall('POST', '/api/mind/checkin/stats', { childId: 1003 }, t);
  757. record(F, 'child', '情绪统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'stats OK' : r.raw);
  758. // 心理测评(需要childId)
  759. r = await apiCall('POST', '/api/mind/screening/history', { childId: 1003 }, t);
  760. record(F, 'child', '筛查历史', r.status === 200 && r.body && r.body.code === 200, r.body ? 'screening history OK' : r.raw);
  761. // 心理运势(用parent token,因为child可能没有familyId)
  762. var tFortune = tokens.parent;
  763. if (tFortune) {
  764. r = await apiCall('POST', '/api/mind/fortune', {}, tFortune);
  765. record(F, 'parent', '心理运势', r.status === 200 && r.body && r.body.code === 200, r.body ? 'fortune OK' : r.raw);
  766. } else {
  767. skip(F, 'parent', '心理运势', 'parent未登录');
  768. }
  769. // EMI报告(需要childId)
  770. r = await apiCall('POST', '/api/mind/emireport/latest', { childId: 1003 }, t);
  771. record(F, 'child', 'EMI报告', r.status === 200 && r.body && r.body.code === 200, r.body ? 'EMI report OK' : r.raw);
  772. }
  773. // ================================================================
  774. // FLOW 14: 身体健康检测 (health-detection-flow)
  775. // ================================================================
  776. async function testHealthDetectionFlow() {
  777. var F = '身体健康检测';
  778. log('\n========== ' + F + ' ==========');
  779. var t = tokens.parent;
  780. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  781. var r = await apiCall('POST', '/api/health/report/list', { childId: 1003 }, t);
  782. record(F, 'parent', '健康报告列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'report list OK' : r.raw);
  783. // 先获取最新报告的reportId
  784. r = await apiCall('POST', '/api/health/report/latest', { childId: 1003 }, t);
  785. var reportId = (r.body && r.body.code === 200 && r.body.data) ? (r.body.data.id || r.body.data.reportId) : null;
  786. record(F, 'parent', '最新报告', r.status === 200 && r.body && r.body.code === 200, r.body ? 'latest report OK' : r.raw);
  787. // 先获取有数据的 reportId(如果最新报告无指标,先创建一个测试报告)
  788. r = await apiCall('POST', '/api/health/report/list', { childId: 1003 }, t);
  789. var validReportId = (r.body && r.body.code === 200 && r.body.data && Array.isArray(r.body.data) && r.body.data.length > 0)
  790. ? (r.body.data[0].id || r.body.data[0].reportId) : 1;
  791. r = await apiCall('POST', '/api/health/indicator/list', { reportId: validReportId }, t);
  792. record(F, 'parent', '指标明细', r.status === 200 && r.body && r.body.code === 200, r.body ? 'indicators OK' : r.raw);
  793. r = await apiCall('POST', '/api/health/nutrition/deficiency', { childId: 1003 }, t);
  794. record(F, 'parent', '营养缺乏分析', r.status === 200 && r.body && r.body.code === 200, r.body ? 'deficiency OK' : r.raw);
  795. }
  796. // ================================================================
  797. // FLOW 15: 活动管理 (activity-flow)
  798. // ================================================================
  799. async function testActivityFlow() {
  800. var F = '活动管理';
  801. log('\n========== ' + F + ' ==========');
  802. var t = tokens.parent;
  803. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  804. // 活动列表
  805. var r = await apiCall('POST', '/api/activity/list', {}, t);
  806. record(F, 'parent', '活动列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'activities OK' : r.raw);
  807. // 我的报名
  808. r = await apiCall('POST', '/api/activity/my-registrations', {}, t);
  809. record(F, 'parent', '我的报名', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my registrations OK' : r.raw);
  810. // --- 管理员 ---
  811. var t2 = tokens.admin;
  812. if (t2) {
  813. r = await apiCall('POST', '/api/admin/activity/list', {}, t2);
  814. record(F, 'admin', '管理端活动列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'admin activities OK' : r.raw);
  815. }
  816. }
  817. // ================================================================
  818. // FLOW 16: 内容与媒体 (content-media-flow)
  819. // ================================================================
  820. async function testContentFlow() {
  821. var F = '内容与媒体';
  822. log('\n========== ' + F + ' ==========');
  823. var t = tokens.parent;
  824. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  825. var r = await apiCall('POST', '/api/articles/list', {}, t);
  826. record(F, 'parent', '文章列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'articles OK' : r.raw);
  827. r = await apiCall('POST', '/api/articles/categories', {}, t);
  828. record(F, 'parent', '文章分类', r.status === 200 && r.body && r.body.code === 200, r.body ? 'categories OK' : r.raw);
  829. r = await apiCall('POST', '/api/articles/featured', {}, t);
  830. record(F, 'parent', '精选文章', r.status === 200 && r.body && r.body.code === 200, r.body ? 'featured OK' : r.raw);
  831. r = await apiCall('POST', '/api/articles/daily-tip', {}, t);
  832. record(F, 'parent', '每日贴士', r.status === 200 && r.body && r.body.code === 200, r.body ? 'daily tip OK' : r.raw);
  833. // 分享
  834. r = await apiCall('POST', '/api/share/my', {}, t);
  835. record(F, 'parent', '我的分享', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my shares OK' : r.raw);
  836. // 媒体(使用真实存在的taskId)
  837. r = await apiCall('POST', '/api/media/upload-text', { taskId: 192, creatorId: 1002, content: 'Test media text' }, t);
  838. record(F, 'parent', '保存文字记录', r.status === 200 && r.body && r.body.code === 200, r.body ? 'text upload OK' : r.body ? r.body.message : r.raw);
  839. }
  840. // ================================================================
  841. // FLOW 17: AI助手 (ai-assistant-flow)
  842. // ================================================================
  843. async function testAIFlow() {
  844. var F = 'AI助手';
  845. log('\n========== ' + F + ' ==========');
  846. var t = tokens.parent;
  847. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  848. // 会话列表
  849. var r = await apiCall('POST', '/api/ai/chat/conversations', {}, t);
  850. record(F, 'parent', 'AI会话列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'conversations OK' : r.raw);
  851. // AI管家会话
  852. r = await apiCall('POST', '/api/ai/butler/sessions/list', {}, t);
  853. record(F, 'parent', 'AI管家会话列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'butler sessions OK' : r.raw);
  854. // AI上下文(user_id 必须是字符串类型,后端用 (String) 强转)
  855. r = await apiCall('POST', '/api/ai/context', { user_id: "1002", intent_type: "general" }, t);
  856. record(F, 'parent', 'AI上下文', r.status === 200 && r.body && r.body.code === 200, r.body ? 'context OK' : r.raw);
  857. // 推荐搜索
  858. r = await apiCall('POST', '/api/recommend/search', { keyword: 'nutrition' }, t);
  859. record(F, 'parent', '推荐搜索', r.status === 200 && r.body && r.body.code === 200, r.body ? 'recommend search OK' : r.raw);
  860. }
  861. // ================================================================
  862. // FLOW 18: 会员与订阅 (membership-flow)
  863. // ================================================================
  864. async function testMembershipFlow() {
  865. var F = '会员与订阅';
  866. log('\n========== ' + F + ' ==========');
  867. var t = tokens.parent;
  868. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  869. var r = await apiCall('POST', '/api/membership/levels', {}, t);
  870. record(F, 'parent', '会员等级列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'levels OK' : r.raw);
  871. r = await apiCall('POST', '/api/membership/my', {}, t);
  872. record(F, 'parent', '我的会员信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my membership OK' : r.raw);
  873. r = await apiCall('POST', '/api/membership/level', {}, t);
  874. record(F, 'parent', '当前等级', r.status === 200 && r.body && r.body.code === 200, r.body ? 'current level OK' : r.raw);
  875. // 功能权限(需要 feature 参数)
  876. r = await apiCall('POST', '/api/membership/can-use', { feature: 'advance_analysis' }, t);
  877. record(F, 'parent', '功能权限', r.status === 200 && r.body && r.body.code === 200, r.body ? 'can-use OK' : r.raw);
  878. // 会员折扣(需要 amount 参数)
  879. r = await apiCall('POST', '/api/membership/discount', { amount: 1000 }, t);
  880. record(F, 'parent', '会员折扣', r.status === 200 && r.body && r.body.code === 200, r.body ? 'discount OK' : r.raw);
  881. // 订阅状态(需要familyId)
  882. r = await apiCall('POST', '/api/subscription/status?familyId=2001', {}, t);
  883. record(F, 'parent', '订阅状态', r.status === 200 && r.body && r.body.code === 200, r.body ? 'subscription status OK' : r.raw);
  884. r = await apiCall('POST', '/api/subscription/plans', {}, t);
  885. record(F, 'parent', '订阅计划', r.status === 200 && r.body && r.body.code === 200, r.body ? 'subscription plans OK' : r.raw);
  886. }
  887. // ================================================================
  888. // FLOW 19: 管理后台 (admin-overview-flow)
  889. // ================================================================
  890. async function testAdminFlow() {
  891. var F = '管理后台';
  892. log('\n========== ' + F + ' ==========');
  893. var t = tokens.admin;
  894. if (!t) { skip(F, 'admin', '所有测试', '未登录'); return; }
  895. // 用户管理
  896. var r = await apiCall('POST', '/api/admin/users', {}, t);
  897. record(F, 'admin', '用户列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'users OK' : r.raw);
  898. // 孩子管理
  899. r = await apiCall('POST', '/api/admin/children', {}, t);
  900. record(F, 'admin', '孩子列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'children OK' : r.raw);
  901. // 家庭管理
  902. r = await apiCall('POST', '/api/admin/families', {}, t);
  903. record(F, 'admin', '家庭列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'families OK' : r.raw);
  904. // 任务管理
  905. r = await apiCall('POST', '/api/admin/tasks', {}, t);
  906. record(F, 'admin', '任务列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'tasks OK' : r.raw);
  907. // 积分管理
  908. r = await apiCall('POST', '/api/admin/points/logs', {}, t);
  909. record(F, 'admin', '积分日志', r.status === 200 && r.body && r.body.code === 200, r.body ? 'points logs OK' : r.raw);
  910. // 规划师审核
  911. r = await apiCall('POST', '/api/admin/guide/applications/pending', {}, t);
  912. record(F, 'admin', '规划师待审批', r.status === 200 && r.body && r.body.code === 200, r.body ? 'guide pending OK' : r.raw);
  913. // 商品管理
  914. r = await apiCall('POST', '/api/admin/product/list', {}, t);
  915. record(F, 'admin', '商品列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'product list OK' : r.raw);
  916. // 订单管理
  917. r = await apiCall('POST', '/api/admin/product/order/list', {}, t);
  918. record(F, 'admin', '订单列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'order list OK' : r.raw);
  919. // 小游戏管理
  920. r = await apiCall('POST', '/api/mini-game/all', {}, t);
  921. record(F, 'admin', '所有游戏', r.status === 200 && r.body && r.body.code === 200, r.body ? 'all games OK' : r.raw);
  922. // 健康检查
  923. r = await apiCall('POST', '/api/system/health', {}, t);
  924. record(F, 'admin', '系统健康检查', r.status === 200 && r.body && r.body.code === 200, r.body ? 'health OK' : r.raw);
  925. }
  926. // ================================================================
  927. // FLOW 20: 规划师体系 (guide-system-flow)
  928. // ================================================================
  929. async function testGuideFlow() {
  930. var F = '规划师体系';
  931. log('\n========== ' + F + ' ==========');
  932. var t = tokens.teacher;
  933. if (!t) { skip(F, 'teacher', '所有测试', '未登录'); return; }
  934. // 个人信息
  935. var r = await apiCall('POST', '/api/guide/my', {}, t);
  936. record(F, 'teacher', '我的信息', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my info OK' : r.raw);
  937. r = await apiCall('POST', '/api/guide/my/packages', {}, t);
  938. record(F, 'teacher', '我的套餐', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my packages OK' : r.raw);
  939. // 团队管理
  940. r = await apiCall('POST', '/api/guide/team/my-team', {}, t);
  941. record(F, 'teacher', '我的团队', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my team OK' : r.raw);
  942. r = await apiCall('POST', '/api/guide/team/members', {}, t);
  943. record(F, 'teacher', '团队成员', r.status === 200 && r.body && r.body.code === 200, r.body ? 'team members OK' : r.raw);
  944. // 绑定家庭
  945. r = await apiCall('POST', '/api/guide/families/bound-families', {}, t);
  946. record(F, 'teacher', '绑定家庭', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'bound families OK' : r.raw);
  947. // 任务模板
  948. r = await apiCall('POST', '/api/guide/packages/list', {}, t);
  949. record(F, 'teacher', '模板列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'package list OK' : r.raw);
  950. // 训练方案
  951. r = await apiCall('POST', '/api/guide/training-plans/list', {}, t);
  952. record(F, 'teacher', '方案列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'training plans OK' : r.raw);
  953. // 活动管理
  954. r = await apiCall('POST', '/api/guide/activities/list', {}, t);
  955. record(F, 'teacher', '活动列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'activities OK' : r.raw);
  956. // 成长记录
  957. r = await apiCall('POST', '/api/guide/record/my-records', {}, t);
  958. record(F, 'teacher', '我的记录', r.status === 200 && r.body && r.body.code === 200, r.body ? 'records OK' : r.raw);
  959. // 咨询消息
  960. r = await apiCall('POST', '/api/guide/messages/list', {}, t);
  961. record(F, 'teacher', '咨询列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'messages OK' : r.raw);
  962. // 订单佣金
  963. r = await apiCall('POST', '/api/guide/orders/list', {}, t);
  964. record(F, 'teacher', '订单列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'orders OK' : r.raw);
  965. // 仪表盘
  966. r = await apiCall('POST', '/api/guide/families/dashboard-stats', {}, t);
  967. record(F, 'teacher', '仪表盘统计', r.status === 200 && r.body && r.body.code === 200, r.body ? 'dashboard stats OK' : r.raw);
  968. }
  969. // ================================================================
  970. // FLOW 21: 圈子与联系人 (circle-contact-flow)
  971. // ================================================================
  972. async function testCircleFlow() {
  973. var F = '圈子与联系人';
  974. log('\n========== ' + F + ' ==========');
  975. var t = tokens.parent;
  976. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  977. var r = await apiCall('POST', '/api/circle/my-circles', { memberId: 1003 }, t);
  978. record(F, 'parent', '我的圈子', r.status === 200 && r.body && r.body.code === 200, r.body ? 'my circles OK' : r.raw);
  979. r = await apiCall('POST', '/api/circle/discover', { childId: 1003 }, t);
  980. record(F, 'parent', '发现圈子', r.status === 200 && r.body && r.body.code === 200, r.body ? 'discover OK' : r.raw);
  981. // 健康圈子
  982. r = await apiCall('POST', '/api/health/circle/list', {}, t);
  983. record(F, 'parent', '健康圈子列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'health circle OK' : r.raw);
  984. // 联系人
  985. r = await apiCall('POST', '/api/contact/list', {}, t);
  986. record(F, 'parent', '联系人列表', r.status === 200 && r.body && r.body.code === 200, r.body && r.body.data ? 'contacts OK' : r.raw);
  987. // 家庭挑战
  988. r = await apiCall('POST', '/api/health/challenge/list', {}, t);
  989. record(F, 'parent', '家庭挑战列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'challenges OK' : r.raw);
  990. }
  991. // ================================================================
  992. // FLOW 22: 知识库与邀请 (knowledge-invite-flow)
  993. // ================================================================
  994. async function testKnowledgeFlow() {
  995. var F = '知识库与邀请';
  996. log('\n========== ' + F + ' ==========');
  997. // 管理员:知识库
  998. var t = tokens.admin;
  999. if (t) {
  1000. var r = await apiCall('POST', '/api/health/knowledge/list', {}, t);
  1001. record(F, 'admin', '知识库列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'kb list OK' : r.raw);
  1002. r = await apiCall('POST', '/api/health/knowledge/v3/bacteria/query', { name: 'lactobacillus' }, t);
  1003. record(F, 'admin', '菌属查询', r.status === 200 && r.body && r.body.code === 200, r.body ? 'bacteria query OK' : r.raw);
  1004. r = await apiCall('POST', '/api/health/knowledge/v3/food/query', { name: 'apple' }, t);
  1005. record(F, 'admin', '食物营养查询', r.status === 200 && r.body && r.body.code === 200, r.body ? 'food query OK' : r.raw);
  1006. }
  1007. // 用户:邀请码
  1008. var t2 = tokens.parent;
  1009. if (t2) {
  1010. var r = await apiCall('POST', '/api/invite/code', {}, t2);
  1011. record(F, 'parent', '生成邀请码', r.status === 200 && r.body && r.body.code === 200, r.body ? 'invite code OK' : r.raw);
  1012. r = await apiCall('POST', '/api/invite/list', {}, t2);
  1013. record(F, 'parent', '邀请列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'invite list OK' : r.raw);
  1014. r = await apiCall('POST', '/api/invite/summary', {}, t2);
  1015. record(F, 'parent', '邀请汇总', r.status === 200 && r.body && r.body.code === 200, r.body ? 'invite summary OK' : r.raw);
  1016. // 里程碑
  1017. r = await apiCall('POST', '/api/invite/milestone/list', {}, t2);
  1018. record(F, 'parent', '里程碑列表', r.status === 200 && r.body && r.body.code === 200, r.body ? 'milestones OK' : r.raw);
  1019. }
  1020. }
  1021. // ================================================================
  1022. // FLOW 23: 其他功能 (extra-features-flow)
  1023. // ================================================================
  1024. async function testExtraFlow() {
  1025. var F = '其他功能';
  1026. log('\n========== ' + F + ' ==========');
  1027. var t = tokens.parent;
  1028. if (!t) { skip(F, 'parent', '所有测试', '未登录'); return; }
  1029. // 吉祥物
  1030. var r = await apiCall('POST', '/api/user/mascot/get', {}, t);
  1031. record(F, 'parent', '获取吉祥物', r.status === 200 && r.body && r.body.code === 200, r.body ? 'mascot OK' : r.raw);
  1032. // 每日反馈
  1033. r = await apiCall('POST', '/api/feedback/today', {}, t);
  1034. record(F, 'parent', '今日反馈', r.status === 200 && r.body && r.body.code === 200, r.body ? 'today feedback OK' : r.raw);
  1035. r = await apiCall('POST', '/api/feedback/recent', {}, t);
  1036. record(F, 'parent', '最近反馈', r.status === 200 && r.body && r.body.code === 200, r.body ? 'recent feedback OK' : r.raw);
  1037. // 生成小程序码(仅支持 type=register 且需要 referralCode)
  1038. r = await apiCall('POST', '/api/common/qrcode', { type: 'register', referralCode: 'TEST2001' }, t);
  1039. record(F, 'parent', '生成小程序码', r.status === 200 && r.body && r.body.code === 200, r.body ? 'qrcode OK' : r.raw);
  1040. // 引导进度
  1041. r = await apiCall('POST', '/api/onboarding/progress', {}, t);
  1042. record(F, 'parent', '引导进度', r.status === 200 && r.body && r.body.code === 200, r.body ? 'onboarding OK' : r.raw);
  1043. }
  1044. // ================================================================
  1045. // MAIN RUNNER
  1046. // ================================================================
  1047. async function main() {
  1048. console.log('============================================================');
  1049. console.log(' 流程级一级测试用例 — FLOW L1 TEST SUITE');
  1050. console.log(' Target: ' + BASE_URL);
  1051. console.log(' Date: ' + new Date().toISOString());
  1052. console.log('============================================================\n');
  1053. // Step 1: Login all roles
  1054. console.log('--- LOGIN ALL ROLES ---');
  1055. await loginAll();
  1056. console.log('');
  1057. // Step 2: Run all flow tests
  1058. await testAuthFlow();
  1059. await testFamilyFlow();
  1060. await testTaskFlow();
  1061. await testWishFlow();
  1062. await testEnergyFlow();
  1063. await testCheckinFlow();
  1064. await testGrowthFlow();
  1065. await testDanFlow();
  1066. await testShopFlow();
  1067. await testPointsFlow();
  1068. await testMinigameFlow();
  1069. await testNutritionFlow();
  1070. await testMindFlow();
  1071. await testHealthDetectionFlow();
  1072. await testActivityFlow();
  1073. await testContentFlow();
  1074. await testAIFlow();
  1075. await testMembershipFlow();
  1076. await testAdminFlow();
  1077. await testGuideFlow();
  1078. await testCircleFlow();
  1079. await testKnowledgeFlow();
  1080. await testExtraFlow();
  1081. // Step 3: Summary
  1082. console.log('\n============================================================');
  1083. console.log(' TEST RESULTS SUMMARY');
  1084. console.log('============================================================');
  1085. console.log(' ✅ Passed: ' + results.passed);
  1086. console.log(' ❌ Failed: ' + results.failed);
  1087. console.log(' ⏭️ Skipped: ' + results.skipped);
  1088. console.log(' Total: ' + (results.passed + results.failed + results.skipped));
  1089. console.log('============================================================');
  1090. // Group failures by flow
  1091. var failures = results.details.filter(function(d) { return d.passed === false; });
  1092. if (failures.length > 0) {
  1093. console.log('\n--- FAILURES ---');
  1094. var byFlow = {};
  1095. failures.forEach(function(f) {
  1096. if (!byFlow[f.flow]) byFlow[f.flow] = [];
  1097. byFlow[f.flow].push(f);
  1098. });
  1099. for (var flow in byFlow) {
  1100. console.log('\n[' + flow + ']');
  1101. byFlow[flow].forEach(function(f) {
  1102. console.log(' ❌ ' + f.role + ' | ' + f.step + ' — ' + (f.detail || ''));
  1103. });
  1104. }
  1105. }
  1106. // Group issues
  1107. if (results.issues.length > 0) {
  1108. console.log('\n--- ISSUES ---');
  1109. results.issues.forEach(function(iss) {
  1110. console.log('⚠️ [' + iss.flow + '] ' + iss.role + ' | ' + iss.step + ': ' + iss.description);
  1111. });
  1112. }
  1113. // Flows with all passes
  1114. var allFlows = {};
  1115. results.details.forEach(function(d) {
  1116. if (!allFlows[d.flow]) allFlows[d.flow] = { pass: 0, fail: 0, skip: 0 };
  1117. if (d.passed === true) allFlows[d.flow].pass++;
  1118. else if (d.passed === false) allFlows[d.flow].fail++;
  1119. else allFlows[d.flow].skip++;
  1120. });
  1121. console.log('\n--- FLOW STATUS ---');
  1122. for (var f in allFlows) {
  1123. var s = allFlows[f];
  1124. var status = s.fail === 0 ? '✅' : '❌';
  1125. console.log(status + ' ' + f + ': ' + s.pass + '/' + (s.pass + s.fail) + ' passed, ' + s.skip + ' skipped');
  1126. }
  1127. console.log('\n============================================================');
  1128. console.log(' DONE');
  1129. console.log('============================================================');
  1130. }
  1131. main().catch(function(err) {
  1132. console.error('FATAL:', err);
  1133. process.exit(1);
  1134. });