# erp-tests **Repository Path**: oplus-data/erp-tests ## Basic Information - **Project Name**: erp-tests - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-17 - **Last Updated**: 2026-04-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ERP Tests — 端到端测试套件 > 全栈 E2E 测试覆盖:**Mall(商城)** + **OA(办公)** + **API(后端接口)** > 技术栈:**Playwright** + **TypeScript** + **ESM** --- ## 项目结构 ``` erp-tests/ ├── playwright.config.ts # Playwright 全局配置(3 个项目:chromium / mobile / api) ├── tsconfig.json # TypeScript ESM 配置 ├── jest.config.js # Jest 备用 ├── package.json │ ├── tests/ │ ├── mall/ # Mall E2E(Web H5) │ │ └── mall.spec.ts │ ├── oa/ # OA E2E(Web H5) │ │ └── oa.spec.ts │ ├── api/ # API 测试(HTTP,Node.js) │ │ ├── api.spec.ts # 通用 API(热搜/商品/登录/接待) │ │ ├── stat.spec.ts # Stat 统计模块(12 个测试) │ │ └── order.spec.ts # Order 订单模块(12 个测试) │ └── fixtures/ # 测试数据 JSON/CSV │ ├── utils/ │ ├── global-setup.ts # Playwright 全局初始化(环境变量默认值) │ ├── helpers.ts # ApiClient + wait/randomPhone/randomOrderId │ └── test-fixtures.ts # 测试账号 & BASE URL 配置 │ ├── test-results/ # JSON 结果 + 截图 ├── playwright-report/ # HTML 报告(浏览器打开) └── README.md ``` --- ## 快速开始 ```bash cd erp-tests yarn install npx playwright install --with-deps chromium # 首次安装 # 全部测试 npx playwright test # 仅 API 测试(最快,无需浏览器) npx playwright test --project=api # Mall E2E npx playwright test tests/mall/ --project=chromium # OA E2E npx playwright test tests/oa/ --project=chromium # 移动端模拟 npx playwright test --project=mobile-chrome # 带 UI 调试 npx playwright test --ui # 查看报告 npx playwright show-report ``` --- ## 环境变量(可选) ```bash # .env.test(不会被 git 提交) cat > .env.test << 'EOF' BASE_URL=https://oval.anitago.com MALL_BASE_URL=https://omall.anitago.com API_BASE_URL=https://oval.anitago.com/api/v1 OA_STAFF_PHONE=13800138001 OA_STAFF_PASSWORD=Test123456 MALL_TEST_PHONE=13800138001 MALL_TEST_PASSWORD=Test123456 EOF ``` > **默认已配置**:直接运行,无需手动创建 `.env.test` --- ## 测试范围 ### API 测试(`tests/api/`) | 测试编号 | 模块 | 端点 | 说明 | |---------|------|------|------| | T-A0 | 通用 | GET `/search/hot` | 服务健康检查 | | T-A1 | 通用 | GET `/search/hot` | 热搜接口 | | T-A2 | 通用 | GET `/products/search` | 商品搜索(无关键词) | | T-A3 | 通用 | GET `/products/search?keyword=手机` | 商品搜索(关键词) | | T-A4 | 通用 | GET `/products/:id` | 商品详情 | | T-A5 | 登录 | POST `/auth/login` | OA 员工登录 | | T-A6~T-A10 | 接待 | `POST/GET /reception/*` | 接待码/统计/活跃列表 | | T-A11 | 搜索 | POST+GET `/search/*` | 搜索记录+历史 | | T-A12 | 全流程 | 组合 | 接待完整流程 | | **T-S0~T-S11** | **Stat** | **`GET/POST /stat/*`** | **统计模块(新增)** | | **T-O1~T-O12** | **Order** | **`GET/POST/PATCH /orders/*`** | **订单模块(新增)** | #### Stat 模块(`stat.spec.ts`) | 测试 | 接口 | 说明 | |------|------|------| | T-S1 | GET `/stat/error-stat?period=today` | 错误统计 | | T-S2 | GET `/stat/error-stat?period=7d` | 近7天错误统计 | | T-S3 | GET `/stat/page-analysis?period=today` | 页面分析 | | T-S4 | GET `/stat/page-analysis?period=30d` | 近30天页面分析 | | T-S5 | GET `/stat/event-analysis?period=today` | 事件分析 | | T-S6 | GET `/stat/channel-analysis?period=today` | 渠道分析 | | T-S7 | GET `/stat/user-analysis?period=today` | 用户分析 | | T-S8 | GET `/stat/api-analysis?period=today` | API 调用分析 | | T-S9 | GET `/dashboard/summary` | 仪表盘摘要 | | T-S10 | GET `/dashboard/trend?days=7` | 7天趋势 | | T-S11 | 组合 | stat 全接口容错汇总 | #### Order 模块(`order.spec.ts`) | 测试 | 接口 | 说明 | |------|------|------| | T-O1 | GET `/orders?page=1&pageSize=10` | 订单列表(分页) | | T-O2 | GET `/orders?status=0` | 按状态过滤 | | T-O3 | GET `/orders?keyword=手机` | 关键词搜索 | | T-O4 | POST `/orders` | 创建订单(正式) | | T-O5 | POST `/orders` | 创建订单(最小化) | | T-O6 | GET `/orders/:id` | 订单详情 | | T-O7 | POST `/orders/:id/status` | 更新订单状态 | | T-O8 | POST `/orders/:id/pay` | 收银台支付(完整流程) | | T-O9 | POST `/orders/:id/pay`(分次) | 分次支付 | | T-O10 | PATCH `/orders/:id` | 编辑订单(改备注) | | T-O11 | GET `/orders/dashboard/today` | 今日订单统计 | | T-O12 | 组合 | 完整订单流程 | ### Mall E2E(`tests/mall/`) | 编号 | 测试点 | |------|--------| | T1-1~T1-3 | 首页 / tabBar / 搜索框 | | T2-1~T2-3 | 搜索 / 热搜 / 扫码 | | T3-1~T3-3 | 登录(正确账号/错误密码) | | T4-1 | 商品详情页 | ### OA E2E(`tests/oa/`) | 编号 | 测试点 | |------|--------| | T5-1~T5-4 | 登录(正确账号/错误密码/token过期) | | T6-1~T6-4 | 工作台(搜索框/接待统计/加单入口) | | T7-1~T7-2 | 接待码生成 + 二维码有效期 | | T8-1~T8-2 | 订单列表 + 收银台 | | T9-1~T9-2 | 会员列表 + 手机号搜索 | --- ## CI/CD 集成 ```yaml # .github/workflows/test.yml name: ERP E2E Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' cache: 'yarn' - run: yarn install --frozen-lockfile - run: npx playwright install --with-deps chromium - run: npx playwright test env: BASE_URL: https://oval.anitago.com MALL_BASE_URL: https://omall.anitago.com API_BASE_URL: https://oval.anitago.com/api/v1 ``` --- ## 开发指南 ### 响应结构约定 后端返回 **三层包装**: ```json { "code": "OK", "data": { "code": "OK", "data": { ...实际数据 } } } ``` 测试工具提供三个 unwrap 工具: ```ts import { api } from '../../utils/helpers'; function unwrap(d: any): T // 三层解包 → 实际数据 function unwrapList(d: any): any[] // 解包 → 数组(兼容 list/total 包装) function unwrapObj(d: any): any // 解包 → 对象 // 示例 const d = await api.get('/products/search', { keyword: '手机' }); const list = unwrapList(d); // 自动兼容 {list,total} 或直接数组 ``` ### 编写新 API 测试 ```ts // tests/api/my-feature.spec.ts import { test, expect } from '@playwright/test'; import { ApiClient } from '../../utils/helpers'; const api = new ApiClient(process.env.API_BASE_URL || 'https://oval.anitago.com/api/v1'); test.describe('我的功能', () => { test('T-MF1: 功能描述', async () => { const d = await api.post('/my-endpoint', { key: 'value' }); const result = unwrapObj(d); expect(result.id).toBeTruthy(); }); }); ``` ### 添加新测试账号 编辑 `utils/test-fixtures.ts` 或 `.env.test`: ```ts export function getOaStaff() { return { phone: process.env.OA_STAFF_PHONE || '13800138001', password: process.env.OA_STAFF_PASSWORD || 'Test123456', name: '管理员1号', }; } ``` --- ## 技术选型 - ✅ Playwright:支持 H5+API+移动端,一套框架 - ✅ TypeScript ESM:无缝集成现代前端项目 - ✅ 内置 request API:直接发 HTTP,无需额外客户端 - ✅ 自动截图/录屏/trace:CI 失败调查更容易 - ✅ 并行+按项目隔离:chromium / mobile / api 完全独立 --- ## 维护者 自动生成于 2026-04-17