/** * 健康知识库 E2E 测试(health knowledge base) * * 后端模块 HealthKnowledgeBaseController * - POST /api/health/knowledge/query 单条查询 * - POST /api/health/knowledge/batch-query 批量查询 * - POST /api/health/knowledge/import 一键导入预置 JSON * * 前端路由:通过 admin 端的 /api/admin/* 接口触发同样后端 * 测试场景:直接走后端 API + 简单 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('health knowledge base', () => { test('login + reachable', async ({ page }) => { const t = await login(page); expect(t).toBeTruthy(); const r = await page.request.post(base() + '/api/health/knowledge/query', { data: { itemType: 'food', itemName: '苹果' }, headers: auth(t) }); expect(r).toBeTruthy(); }); test('query requires itemType + itemName', async ({ page }) => { const t = await login(page); const r = await page.request.post(base() + '/api/health/knowledge/query', { data: {}, headers: auth(t) }); const j = await r.json(); expect(j.code).not.toBe(200); }); test('batch-query empty -> error', async ({ page }) => { const t = await login(page); const r = await page.request.post(base() + '/api/health/knowledge/batch-query', { data: { queries: [] }, headers: auth(t) }); const j = await r.json(); expect(j.code).not.toBe(200); }); test('import endpoint accessible', async ({ page }) => { const t = await login(page); const r = await page.request.post(base() + '/api/health/knowledge/import', { headers: auth(t) }); expect(r).toBeTruthy(); }); });