Files
Home-Care/hss-home-service/website/tests/api.spec.ts
comclib c02029a5f3 feat: 初始化居家上门服务系统完整项目代码
- Spring Boot 后端服务 (hss-home-service)
- delivery-miniapp 配送小程序
- website 官网 (Nuxt)
- docs 架构设计文档
- Docker 容器化部署配置

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 09:04:49 +08:00

83 lines
3.4 KiB
TypeScript

import { test, expect } from '@playwright/test'
const API = 'http://172.31.12.249:18080/api/hss'
const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' }
test.describe('后端 API 连通性', () => {
test('OpenAPI 文档可达', async ({ request }) => {
const res = await request.get('http://172.31.12.249:18080/api-docs')
expect(res.status()).toBe(200)
const json = await res.json()
expect(json.openapi).toBeDefined()
expect(Object.keys(json.paths).length).toBeGreaterThan(80)
})
test('管理端仪表盘返回数据', async ({ request }) => {
const res = await request.get(`${API}/admin/dashboard`, { headers: H })
expect(res.status()).toBe(200)
const json = await res.json()
expect(json.code).toBe(200)
expect(json.data).toBeDefined()
})
test('分析汇总返回数据', async ({ request }) => {
const res = await request.get(`${API}/analytics/summary`, { headers: H })
expect(res.status()).toBe(200)
})
test('应用列表返回数据', async ({ request }) => {
const res = await request.get(`${API}/applications?page=1&size=5`, { headers: H })
expect(res.status()).toBe(200)
})
test('Leads 提交成功', async ({ request }) => {
const key = 'pw-test-' + Date.now()
const res = await request.post(`${API}/leads`, {
headers: { ...H, 'Idempotency-Key': key },
data: { type: 'demo', name: 'PW测试', orgName: '测试机构', phone: '13800000000', source: 'playwright' }
})
expect(res.status()).toBe(200)
const json = await res.json()
expect(json.code).toBe(200)
})
test('Leads 幂等去重', async ({ request }) => {
const key = 'pw-idem-' + Date.now()
const data = { type: 'demo', name: '幂等测试', orgName: '幂等机构', phone: '13900000000', source: 'playwright' }
const r1 = await request.post(`${API}/leads`, { headers: { ...H, 'Idempotency-Key': key }, data })
const r2 = await request.post(`${API}/leads`, { headers: { ...H, 'Idempotency-Key': key }, data })
expect(r1.status()).toBe(200)
const j1 = await r1.json(); const j2 = await r2.json()
expect(j1.data?.id || j1.data?.status).toBe(j2.data?.id || j2.data?.status)
})
test('非法状态转换被拦截', async ({ request }) => {
const res = await request.post(`${API}/applications/99999/accept`, { headers: H })
expect(res.status()).toBe(422)
})
test('主数据接口可达', async ({ request }) => {
for (const ep of ['/master/service-items', '/master/price-rules', '/master/regions', '/master/staff']) {
const res = await request.get(`${API}${ep}`, { headers: H })
expect(res.status()).toBe(200)
}
})
test('运力与绩效接口可达', async ({ request }) => {
for (const ep of ['/capacity/dashboard', '/analytics/quality', '/performance/ranking']) {
const res = await request.get(`${API}${ep}`, { headers: H })
expect(res.status(), `${ep} should return 200`).toBe(200)
}
})
})
test.describe('官网表单提交通过 Nginx 代理', () => {
test('预约演示表单 mock 提交', async ({ request }) => {
const res = await request.post('http://172.31.12.249:3080/api/hss/leads', {
headers: { ...H, 'Idempotency-Key': 'pw-nginx-' + Date.now() },
data: { type: 'demo', name: 'Nginx代理测试', orgName: '测试机构', phone: '13800000001', source: 'website' }
})
expect(res.status()).toBe(200)
})
})