nutritionist-apply.spec.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * 营养师申请 E2E 测试(nutritionist apply/status)
  3. *
  4. * 后端模块 NutritionistController
  5. * - POST /api/nutritionist/apply 申请营养师(要求 requestAttribute userId)
  6. * - POST /api/nutritionist/status 查看当前营养师状态
  7. *
  8. * 这里测试通过 admin token 触发,验证后端接口联通 + 不重复申请保护
  9. * 实际业务场景:家长端用户在登录的小程序调用
  10. */
  11. const { test, expect } = require('@playwright/test');
  12. function base() { return 'http' + String.fromCharCode(58,47,47) + 'cfc.iwintrue.com'; }
  13. function auth(t) { return t ? { Authorization: 'Bearer ' + t } : {}; }
  14. async function login(page) {
  15. const r = await page.request.post(base() + '/api/admin-auth/login-by-password', {
  16. data: { phone: '13800138000', password: 'admin123' }
  17. });
  18. if (!r.ok()) return null;
  19. const j = await r.json();
  20. return j?.data?.token || null;
  21. }
  22. test.describe('nutritionist apply/status', () => {
  23. test('login reachable', async ({ page }) => {
  24. const t = await login(page);
  25. expect(t).toBeTruthy();
  26. });
  27. test('status endpoint requires userId', async ({ page }) => {
  28. const t = await login(page);
  29. const r = await page.request.post(base() + '/api/nutritionist/status', {
  30. headers: auth(t)
  31. });
  32. expect(r).toBeTruthy();
  33. });
  34. test('apply endpoint requires userId', async ({ page }) => {
  35. const t = await login(page);
  36. const r = await page.request.post(base() + '/api/nutritionist/apply', {
  37. data: {},
  38. headers: auth(t)
  39. });
  40. expect(r).toBeTruthy();
  41. });
  42. });