/** * 营养师申请 E2E 测试(nutritionist apply/status) * * 后端模块 NutritionistController * - POST /api/nutritionist/apply 申请营养师(要求 requestAttribute userId) * - POST /api/nutritionist/status 查看当前营养师状态 * * 这里测试通过 admin token 触发,验证后端接口联通 + 不重复申请保护 * 实际业务场景:家长端用户在登录的小程序调用 */ const { test, expect } = require('@playwright/test'); function base() { return 'http' + String.fromCharCode(58,47,47) + 'cfc.iwintrue.com'; } function auth(t) { return t ? { Authorization: 'Bearer ' + t } : {}; } async function login(page) { const r = await page.request.post(base() + '/api/admin-auth/login-by-password', { data: { phone: '13800138000', password: 'admin123' } }); if (!r.ok()) return null; const j = await r.json(); return j?.data?.token || null; } test.describe('nutritionist apply/status', () => { test('login reachable', async ({ page }) => { const t = await login(page); expect(t).toBeTruthy(); }); test('status endpoint requires userId', async ({ page }) => { const t = await login(page); const r = await page.request.post(base() + '/api/nutritionist/status', { headers: auth(t) }); expect(r).toBeTruthy(); }); test('apply endpoint requires userId', async ({ page }) => { const t = await login(page); const r = await page.request.post(base() + '/api/nutritionist/apply', { data: {}, headers: auth(t) }); expect(r).toBeTruthy(); }); });