- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
220 行
8.3 KiB
JavaScript
220 行
8.3 KiB
JavaScript
/**
|
||
* 接口契约测试(后台管理端 PC)
|
||
* 覆盖 10 大模块:数据总览 / 商家 / 会员 / 信息审核 / 评价 / 分销 / 订单 / 财务 / 权限 / 系统设置
|
||
*/
|
||
import { describe, it, expect, expectReject } from './harness.mjs'
|
||
import adminApi from '../common/api/admin.js'
|
||
|
||
describe('后台 · 数据总览', () => {
|
||
it('核心数据看板字段完整', async () => {
|
||
const o = await adminApi.dashboardOverview()
|
||
expect(o.pv).toBeGreaterThan(0)
|
||
expect(o.todayOrderAmount).toBeDefined()
|
||
expect(o.pendingAudit).toBeDefined()
|
||
expect(o.memberCount).toBeGreaterThan(0)
|
||
})
|
||
|
||
it('趋势分析支持流量 / 营收 / 用户增长', async () => {
|
||
const traffic = await adminApi.dashboardTrend('traffic')
|
||
expect(traffic[0].pv).toBeDefined()
|
||
const revenue = await adminApi.dashboardTrend('revenue')
|
||
expect(revenue[0].amount).toBeDefined()
|
||
const growth = await adminApi.dashboardTrend('userGrowth')
|
||
expect(growth[0].newUser).toBeDefined()
|
||
})
|
||
})
|
||
|
||
describe('后台 · 商家管理', () => {
|
||
it('商家列表支持状态筛选与关键词检索', async () => {
|
||
const all = await adminApi.merchants({ page: 1, size: 20 })
|
||
expect(all.total).toBeGreaterThan(0)
|
||
const pending = await adminApi.merchants({ status: 0 })
|
||
expect(pending.list.every((m) => m.auditStatus === 0)).toBe(true)
|
||
const kw = await adminApi.merchants({ keyword: '物流' })
|
||
expect(kw.list[0].name).toContain('物流')
|
||
})
|
||
|
||
it('资质审核支持通过 / 驳回,非法状态被拦截', async () => {
|
||
expect((await adminApi.auditMerchant(2005, 1)).auditStatus).toBe(1)
|
||
expect((await adminApi.auditMerchant(2005, 2)).auditStatus).toBe(2)
|
||
await expectReject(() => adminApi.auditMerchant(2005, 9), '审核状态仅支持')
|
||
})
|
||
})
|
||
|
||
describe('后台 · 会员管理', () => {
|
||
it('用户列表区分个人 / 商家', async () => {
|
||
const res = await adminApi.users({ page: 1, size: 20 })
|
||
const types = new Set(res.list.map((u) => u.userType))
|
||
expect(types.has(1)).toBe(true)
|
||
expect(types.has(2)).toBe(true)
|
||
})
|
||
|
||
it('会员权益设置:免费查看条数不能为负', async () => {
|
||
const r = await adminApi.saveMemberBenefit({ freeView: 30, postDiscount: '7 折' })
|
||
expect(r.freeView).toBe(30)
|
||
await expectReject(() => adminApi.saveMemberBenefit({ freeView: -1 }), '不能为负')
|
||
})
|
||
})
|
||
|
||
describe('后台 · 信息审核', () => {
|
||
it('待审核列表仅返回 auditStatus=0', async () => {
|
||
const res = await adminApi.pendingPosts({ page: 1, size: 20 })
|
||
expect(res.list.every((p) => p.auditStatus === 0)).toBe(true)
|
||
})
|
||
|
||
it('审核通过 / 驳回,非法状态被拦截', async () => {
|
||
expect((await adminApi.auditPost(104, 1)).auditStatus).toBe(1)
|
||
expect((await adminApi.auditPost(104, 2)).auditStatus).toBe(2)
|
||
await expectReject(() => adminApi.auditPost(104, 0), '仅支持通过')
|
||
})
|
||
|
||
it('违规信息可强制下架', async () => {
|
||
const r = await adminApi.offlinePost(106)
|
||
expect(r.offline).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('后台 · 评价管理', () => {
|
||
it('全平台评价可查看', async () => {
|
||
const res = await adminApi.comments({ page: 1, size: 20 })
|
||
expect(res.list.length).toBeGreaterThan(0)
|
||
expect(res.list[0].score).toBeDefined()
|
||
})
|
||
|
||
it('回复评价需填写内容', async () => {
|
||
const r = await adminApi.replyComment(5001, '感谢您的评价')
|
||
expect(r.reply).toBe('感谢您的评价')
|
||
await expectReject(() => adminApi.replyComment(5001, ''), '回复内容不能为空')
|
||
})
|
||
|
||
it('举报处理列表可读取', async () => {
|
||
const list = await adminApi.reports()
|
||
expect(list).toBeArray()
|
||
expect(list[0].reason).toBeDefined()
|
||
})
|
||
})
|
||
|
||
describe('后台 · 分销管理', () => {
|
||
it('分润设置:可开关、层级、比例', async () => {
|
||
const s = await adminApi.distSetting()
|
||
expect(s.enabled).toBe(true)
|
||
expect(s.level).toBe(2)
|
||
})
|
||
|
||
it('分佣比例一级+二级不得超过 100%', async () => {
|
||
const ok = await adminApi.saveDistSetting({ level1Rate: 20, level2Rate: 10 })
|
||
expect(ok.level1Rate).toBe(20)
|
||
await expectReject(
|
||
() => adminApi.saveDistSetting({ level1Rate: 80, level2Rate: 40 }),
|
||
'不能超过 100%'
|
||
)
|
||
})
|
||
|
||
it('提现审核:打款 / 驳回(驳回需原因)', async () => {
|
||
expect((await adminApi.handleWithdraw(2, 'pay')).status).toBe('paid')
|
||
await expectReject(() => adminApi.handleWithdraw(3, 'reject'), '需填写原因')
|
||
expect((await adminApi.handleWithdraw(3, 'reject', '账户异常')).status).toBe('rejected')
|
||
})
|
||
|
||
it('提现列表可读取', async () => {
|
||
const list = await adminApi.withdraws()
|
||
expect(list).toBeArray()
|
||
})
|
||
})
|
||
|
||
describe('后台 · 订单管理', () => {
|
||
it('订单列表按类型筛选(发布单条付费记录)', async () => {
|
||
const all = await adminApi.orders({ page: 1, size: 50 })
|
||
expect(all.total).toBeGreaterThan(0)
|
||
const posts = await adminApi.orders({ type: 'post' })
|
||
expect(posts.list.every((o) => o.type === 'post')).toBe(true)
|
||
})
|
||
|
||
it('退款金额必须大于 0', async () => {
|
||
expect((await adminApi.refund(3001, 5, '用户申请')).refunded).toBe(true)
|
||
await expectReject(() => adminApi.refund(3001, 0), '退款金额需大于 0')
|
||
})
|
||
|
||
it('支持补单', async () => {
|
||
const r = await adminApi.supplement('PO20240101001')
|
||
expect(r.supplemented).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('后台 · 财务管理', () => {
|
||
it('资金流水支持按类型筛选', async () => {
|
||
const all = await adminApi.financeFlows({ page: 1, size: 50 })
|
||
expect(all.total).toBeGreaterThan(0)
|
||
const income = await adminApi.financeFlows({ type: 'income' })
|
||
expect(income.list.every((f) => f.type === 'income')).toBe(true)
|
||
})
|
||
|
||
it('财务报表支持日/月/年导出数据结构', async () => {
|
||
const day = await adminApi.financeReport('day')
|
||
expect(day.period).toBe('day')
|
||
expect(day.rows[0].net).toBeDefined()
|
||
const month = await adminApi.financeReport('month')
|
||
expect(month.period).toBe('month')
|
||
})
|
||
})
|
||
|
||
describe('后台 · 权限管理', () => {
|
||
it('角色管理:内置超级管理员/运营/客服/财务', async () => {
|
||
const roles = await adminApi.roles()
|
||
const names = roles.map((r) => r.name)
|
||
expect(names).toContain('超级管理员')
|
||
expect(names).toContain('运营')
|
||
})
|
||
|
||
it('新建角色必须有名称与权限', async () => {
|
||
const r = await adminApi.saveRole({ name: '审核员', permissions: ['post'] })
|
||
expect(r.id).toBeDefined()
|
||
await expectReject(() => adminApi.saveRole({ permissions: ['post'] }), '角色名称不能为空')
|
||
await expectReject(() => adminApi.saveRole({ name: 'x' }), '请至少分配一项权限')
|
||
})
|
||
|
||
it('子账号与操作日志可查询', async () => {
|
||
const accs = await adminApi.accounts()
|
||
expect(accs[0].roleName).toBeDefined()
|
||
const logs = await adminApi.logs({ page: 1, size: 20 })
|
||
expect(logs.list[0].action).toBeDefined()
|
||
})
|
||
})
|
||
|
||
describe('后台 · 系统设置', () => {
|
||
it('基础配置:小程序名称必填', async () => {
|
||
const b = await adminApi.baseSetting()
|
||
expect(b.appName).toBeDefined()
|
||
const r = await adminApi.saveBaseSetting({ appName: '同城分类信息' })
|
||
expect(r.appName).toBe('同城分类信息')
|
||
await expectReject(() => adminApi.saveBaseSetting({}), '小程序名称不能为空')
|
||
})
|
||
|
||
it('支付配置:商户号与密钥必填', async () => {
|
||
const r = await adminApi.savePaySetting({ mchId: '1900000001', apiKey: 'k' })
|
||
expect(r.configured).toBe(true)
|
||
await expectReject(() => adminApi.savePaySetting({ apiKey: 'k' }), '商户号不能为空')
|
||
await expectReject(() => adminApi.savePaySetting({ mchId: '1' }), '支付密钥不能为空')
|
||
})
|
||
|
||
it('费用标准:单条发布价与会员套餐价动态设置', async () => {
|
||
const fee = await adminApi.feeSetting()
|
||
expect(fee.singlePost).toBeDefined()
|
||
expect(fee.memberYear).toBeDefined()
|
||
const r = await adminApi.saveFeeSetting({ singlePost: 6, memberMonth: 25 })
|
||
expect(r.singlePost).toBe(6)
|
||
await expectReject(() => adminApi.saveFeeSetting({ singlePost: -1 }), '不能为负')
|
||
})
|
||
|
||
it('地区管理:同城服务区域划分', async () => {
|
||
const areas = await adminApi.areas()
|
||
expect(areas.length).toBeGreaterThan(0)
|
||
expect(areas[0].province).toBeDefined()
|
||
const r = await adminApi.saveArea({ province: '贵州省', city: '贵阳市', district: '乌当区', sort: 6 })
|
||
expect(r.id).toBeDefined()
|
||
await expectReject(() => adminApi.saveArea({}), '省份不能为空')
|
||
await expectReject(() => adminApi.saveArea({ province: '贵州省', city: '贵阳市', district: '云岩区' }), '该省市区组合已存在')
|
||
})
|
||
})
|
||
|