backend-api-test-doc-qrcode-channel.md 6.37 KB

接口测试文档 — qrcode-channel


1. 模块概览

字段 值
模块名称 qrcode-channel
模块说明 渠道活码配置管理 — 增删改查 + 启用/禁用 + 批量操作 + 导出
路由前缀 /api/v1/agent-group/qrcode
数据库表 qrcode_channels
外部依赖 WeComClient(创建活码)、OSSClient(导出)

2. 接口列表

序号 方法 路径 说明
1 POST /api/v1/agent-group/qrcode/create 创建渠道活码
2 PUT /api/v1/agent-group/qrcode/{qrcode_id} 更新活码
3 GET /api/v1/agent-group/qrcode/{qrcode_id} 查询活码详情
4 GET /api/v1/agent-group/qrcode/list 分页查询活码列表
5 POST /api/v1/agent-group/qrcode/export 导出活码
6 PUT /api/v1/agent-group/qrcode/{qrcode_id}/disable 禁用活码
7 PUT /api/v1/agent-group/qrcode/{qrcode_id}/enable 启用活码
8 POST /api/v1/agent-group/qrcode/batch-status 批量启用/禁用

3. 接口详细说明

3.1 创建渠道活码

请求参数

参数名 位置 类型 必填 说明
qrcode_name body string 是 活码名称,最长50
position_code body string 是 岗位编码
employee_id body string 是 员工ID
employee_name body string 是 员工姓名
wechat_user_id body string 是 企微用户ID
remark body string 否 备注
welcome_message body string 否 欢迎语

响应参数

字段路径 类型 说明
qrcode_id integer 活码ID
qrcode_name string 活码名称
qrcode_url string 企微活码URL
channel_code string 渠道编码(格式:zdxs_{position_code}_{employee_id})
status string 状态,默认enable
agent_ids integer[] 关联Agent ID列表
agent_names string[] 关联Agent名称列表
created_at string 创建时间

错误码

HTTP 状态码 触发条件
400 岗位不存在
409 同岗位同员工活码已存在

3.2 更新活码

请求参数

参数名 位置 类型 必填 说明
qrcode_name body string 是 活码名称
remark body string 否 备注
welcome_message body string 否 欢迎语

3.3 活码详情

响应参数

字段路径 类型 说明
qrcode_id integer 活码ID
qrcode_name string 活码名称
employee_id string 员工ID
employee_name string 员工姓名
position_name string 岗位名称
channel_code string 渠道编码
qrcode_url string 活码URL
agent_ids integer[] Agent ID列表
welcome_message string 欢迎语
status string 状态

3.4 禁用/启用活码

禁用请求参数

参数名 位置 类型 必填 说明
reason body string 是 停用原因

响应参数

字段路径 类型 说明
success boolean 是否成功
previous_status string 变更前状态

3.5 批量状态变更

请求参数

参数名 位置 类型 必填 说明
qrcode_ids body integer[] 是 活码ID列表,至少1个
target_status body string 是 enable/disable
reason body string 否 原因

响应参数

字段路径 类型 说明
success_count integer 成功数
failed_count integer 失败数
failed_list array 失败列表

4. 测试场景

序号 场景名称 分类 预期结果
1 创建成功 正常 qrcode_id>0, channel_code格式正确, 含管家+岗位Agent
2 岗位不存在 异常 ValueError "岗位不存在"
3 重复创建返回冲突 异常 ValueError "已存在同岗位活码"
4 channel_code格式 正常 zdxs_{code}_{emp_id}
5 自动包含管家+岗位Agent 正常 agent_ids含steward和metric
6 更新成功 正常 success=True
7 更新不存在 异常 ValueError
8 详情查询 正常 qrcode_name, welcome_message正确
9 详情不存在 异常 ValueError
10 列表按员工名筛选 正常 total=1
11 列表按状态筛选 正常 status=enable → total=1
12 列表关键词搜索 正常 keyword匹配channel_code
13 列表空结果 边界 total=0, list=[]
14 导出成功 正常 total_count=1, file_url非空
15 禁用成功 正常 success=True, previous_status="enable"
16 启用成功 正常 previous_status="disable"
17 禁用不存在 异常 ValueError
18 批量禁用 正常 success_count=2, failed_count=0
19 批量部分失败 正常 success_count=1, failed_count=1
20 集成:创建→查询→更新→禁用→启用 集成 全流程通过

5. 对应测试代码

测试文件:backend/tests/test_qrcode_channel_api.py

测试类 测试方法 对应场景
TestCreateQrcode test_create_success 1
TestCreateQrcode test_create_position_not_found 2
TestCreateQrcode test_create_duplicate_returns_409 3
TestCreateQrcode test_create_channel_code_format 4
TestCreateQrcode test_create_auto_includes_steward_and_position_agents 5
TestUpdateQrcode test_update_success 6
TestUpdateQrcode test_update_nonexistent 7
TestGetDetail test_detail_success 8
TestGetDetail test_detail_not_found 9
TestListQrcodes test_list_with_employee_name_filter 10
TestListQrcodes test_list_by_status 11
TestListQrcodes test_list_keyword_search 12
TestListQrcodes test_list_empty 13
TestExport test_export_success 14
TestDisableEnable test_disable_success 15
TestDisableEnable test_enable_success 16
TestDisableEnable test_disable_not_found 17
TestBatchStatus test_batch_disable 18
TestBatchStatus test_batch_with_failures 19
TestIntegrationFlow test_create_query_update_disable_enable 20