sc-p50-growth-record.spec.js 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * SC-P-50 成长记录查看(时间线聚合)三类流(API 级 e2e)
  3. * ================================================================
  4. * 端点(源码核对 cfc-backend GrowthRecordController / PointsController):
  5. * - /api/growth/record/list 家长查本人成长档案列表(@RequestAttribute("userId"),无 token → 401「请先登录」)
  6. * - /api/growth/record/child-records 按成员查成长档案(body 为裸 Long memberId,G-11 归属门禁:跨家庭 → 403「无权访问该成员成长档案」)
  7. * - /api/points/logs 积分流水分页(body {memberId?,page?,size?},缺省取 currentMemberId)
  8. *
  9. * 探针取证(2026-11-30 远程 cfc.iwintrue.com 实测锁定):
  10. * LIST_OK 200 data=[](首访空态正常,不 500)
  11. * CHILD_SELF 200 data=[](裸数字 body 自身 memberId)
  12. * CHILD_OBJ 400「请求参数格式错误,请检查请求体 JSON 或字段类型」(body 传对象 {memberId} 而非裸数字)
  13. * CROSS 403「无权访问该成员成长档案」(跨家庭 memberId=999999)
  14. * LIST_ANON 401「请先登录」(/api/growth/record/list 无 token)
  15. * LOGS_OK 200 data=Page{records:[]}
  16. * LOGS_BADPAGE 200(page=-1 未被拒,points/logs 分页参数宽松——如实断言不锁 400)
  17. *
  18. * 契约缺口(承袭·真实缺陷未修,不为缺陷造绿):
  19. * ① /api/points/logs 匿名未 401(探针 ANON 返回 200 + 空 Page,属放行面),
  20. * 与 TC-P-50-P「非归属 403/401」部分偏离——权限流以 growth 域的 403/401 真实守卫为主证;
  21. * ② /api/growth/record/child-records 对对象 body 返回 400 而非 200(body 须裸数字),
  22. * 属入参契约严格性,非缺陷;正常/异常/权限三流均以实测契约断言。
  23. */
  24. const { test, expect } = require('@playwright/test');
  25. const { apiPost, registerRole, pickMemberByUserId, uniqueSuffix } = require('../helpers/api');
  26. test.describe('SC-P-50 成长记录查看三类流', () => {
  27. let user, selfMemberId;
  28. test.beforeAll(async ({ request }) => {
  29. user = await registerRole(request, 'parent', 'QA-P50-' + uniqueSuffix());
  30. const mem = await apiPost(request, '/api/family/member/list', {}, user.token);
  31. const self = pickMemberByUserId(mem.data, user.userId);
  32. expect(self, '成员列表应含登录用户自身').toBeTruthy();
  33. selfMemberId = self.id;
  34. });
  35. // ---------- 正常流(P1:查成长记录 / 时间线聚合)----------
  36. test('[P-50 正常] 家长查本人成长档案列表返回数组(首访空态不报错)', async ({ request }) => {
  37. const r = await apiPost(request, '/api/growth/record/list', {}, user.token);
  38. expect(r.code, 'list: ' + r.message).toBe(200);
  39. expect(Array.isArray(r.data), '应返回数组').toBe(true);
  40. });
  41. test('[P-50 正常] 按家庭成员查成长档案(裸数字 body)返回数组', async ({ request }) => {
  42. const r = await apiPost(request, '/api/growth/record/child-records', selfMemberId, user.token);
  43. expect(r.code, 'child-records: ' + r.message).toBe(200);
  44. expect(Array.isArray(r.data), '应返回数组').toBe(true);
  45. });
  46. test('[P-50 正常] 查积分流水返回分页结构(records 数组 + total)', async ({ request }) => {
  47. const r = await apiPost(request, '/api/points/logs', { memberId: selfMemberId }, user.token);
  48. expect(r.code, 'logs: ' + r.message).toBe(200);
  49. expect(r.data && typeof r.data === 'object', '应返回分页对象').toBe(true);
  50. expect(Array.isArray(r.data.records), 'records 应为数组').toBe(true);
  51. expect(typeof r.data.total).toBe('number');
  52. });
  53. // ---------- 异常流(P2:空态 / 入参异常)----------
  54. test('[P-50-E 异常] 首访无成长数据返回空数组(不 500、不报错)', async ({ request }) => {
  55. const r = await apiPost(request, '/api/growth/record/list', {}, user.token);
  56. expect(r.code, '首访空态应 200: ' + r.message).toBe(200);
  57. expect(r.code).not.toBe(500);
  58. expect(Array.isArray(r.data)).toBe(true);
  59. });
  60. test('[P-50-E 异常] child-records 传对象 body(非裸数字)被 400 拒绝', async ({ request }) => {
  61. const r = await apiPost(request, '/api/growth/record/child-records', { memberId: selfMemberId }, user.token);
  62. expect(r.code, '对象 body 应 400: ' + r.message).toBe(400);
  63. expect(r.code).not.toBe(500);
  64. expect(String(r.message)).toMatch(/请求参数格式错误|JSON 或字段类型/i);
  65. });
  66. // ---------- 权限流(P3:归属 / 登录守卫)----------
  67. test('[P-50-P 权限] 跨家庭 memberId 访问成长档案被 403 拒绝', async ({ request }) => {
  68. const r = await apiPost(request, '/api/growth/record/child-records', 999999, user.token);
  69. expect(r.code, '跨家庭应 403: ' + r.message).toBe(403);
  70. expect(String(r.message)).toMatch(/无权访问该成员成长档案/i);
  71. });
  72. test('[P-50-P 权限] 匿名查本人成长档案被 401 拒绝', async ({ request }) => {
  73. const r = await apiPost(request, '/api/growth/record/list', {}, '');
  74. expect(r.code, '匿名应 401: ' + r.message).toBe(401);
  75. expect(r.code).not.toBe(200);
  76. });
  77. });