文件
fenleixinxi/uniapp/tests/api.admin.contract.test.mjs
linda 376a7ed793 feat(uniapp): 小程序端(用户端 uni-app)源码入库到 uniapp/ 目录
需求:小程序端代码要同时同步到服务器与 git 远程仓库,此前前端仅存在于本地目录(无 remote,从未推送),
服务器与 gitcode 上只有后端。现并入本仓库,复用现有「push 即部署」链路,一次推送双端落地。

- 新增 uniapp/:小程序端源码全量快照(150 文件 / 1.2M)
  pages(13 页面) · components(fc-navbar/fc-tabbar/fc-post-card/fc-empty) ·
  common(api·utils·mock·assets·store·config) · static(74 图标 + 3 轮播插画 + LOGO) ·
  docs(01-04 交付文档) · tests(零依赖全链路用例) · tools(图标/主题/轮播配图生成脚本)
- 明确排除:AGENTS.md(含后台密码、服务器 root 密码、小程序 AppSecret,切勿入库)、
  unpackage/(构建产物,由 uniapp/.gitignore 忽略)、node_modules、.DS_Store、*.log
- .gitignore 新增 /uniapp/AGENTS.md 兜底(与根 /AGENTS.md、/fluniapp/ 同一约定)
- README.md 增补「本项目结构 + 部署链路」章节,说明 uniapp/ 为源码快照、
  小程序真正上线仍需微信开发者工具 cli upload

说明:本次为源码快照,未携带前端本地仓库历史——其历史提交中含 AGENTS.md 凭据,
若做 subtree 合并会把密码永久写入本仓库历史,故采用快照方式。
2026-10-17 14:19:03 +08:00

218 行
8.1 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

/**
* 接口契约测试(后台管理端 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)
const r = await adminApi.saveArea({ name: '乌当区', sort: 6 })
expect(r.id).toBeDefined()
await expectReject(() => adminApi.saveArea({}), '区域名称不能为空')
})
})