需求:小程序端代码要同时同步到服务器与 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 合并会把密码永久写入本仓库历史,故采用快照方式。
185 行
7.2 KiB
JavaScript
185 行
7.2 KiB
JavaScript
/**
|
||
* v1.0.7 新增能力用例:我的发布 / 后台手动置顶 / 免费-付费发布开关与套餐额度
|
||
*
|
||
* 覆盖需求:
|
||
* ① 发布后能看到发布记录(/post/mine + 状态计数 + 驳回原因)
|
||
* ② 后台手动置顶 → 用户端主页置顶优先展示(/home/feed)
|
||
* ③ 发布模式开关(免费/付费)+ 单条价格 + 月卡/年卡价格与含发布条数
|
||
* ④ 计费口径:金额只由后台配置决定,客户端传入的 amount 一律被忽略
|
||
*/
|
||
import { describe, it, expect, expectReject } from './harness.mjs'
|
||
import { homeApi, postApi, memberApi } from '../common/api/index.js'
|
||
import { datasets } from '../common/mock/data.js'
|
||
|
||
/** 每个用例前把 mock 状态复位,保证用例之间互不影响 */
|
||
function resetPublish() {
|
||
datasets.publishRule.mode = 'paid'
|
||
datasets.publishRule.singlePrice = 5
|
||
datasets.publishRule.monthPrice = 19.9
|
||
datasets.publishRule.monthQuota = 30
|
||
datasets.publishRule.yearPrice = 168
|
||
datasets.publishRule.yearQuota = 500
|
||
datasets.publishRule.quotaLeft = 30
|
||
datasets.publishRule.freePerDay = 2
|
||
datasets.publishRule.freeUsedToday = 0
|
||
datasets.publishRule.isMember = true
|
||
}
|
||
|
||
describe('发布配置 · 后台开关与价格下发', () => {
|
||
it('返回发布模式、三档价格与剩余额度', async () => {
|
||
resetPublish()
|
||
const cfg = await postApi.publishConfig()
|
||
expect(cfg.mode).toBe('paid')
|
||
expect(cfg.singlePrice).toBe(5)
|
||
expect(cfg.monthPrice).toBe(19.9)
|
||
expect(cfg.monthQuota).toBe(30)
|
||
expect(cfg.yearPrice).toBe(168)
|
||
expect(cfg.yearQuota).toBe(500)
|
||
expect(cfg.quotaLeft).toBe(30)
|
||
expect(cfg.isMember).toBe(true)
|
||
})
|
||
|
||
it('免费模式:所有人免费发布且不消耗额度', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.mode = 'free'
|
||
datasets.publishRule.quotaLeft = 0
|
||
const res = await postApi.create({ title: '免费模式发布', content: '内容', plan: 'free' })
|
||
expect(res.order).toBeFalsy()
|
||
expect(res.plan).toBe('free')
|
||
expect(res.amount).toBe(0)
|
||
})
|
||
})
|
||
|
||
describe('发布计费 · 服务端定价与套餐额度', () => {
|
||
it('套餐额度内免费发布:无订单且额度 -1', async () => {
|
||
resetPublish()
|
||
const res = await postApi.create({ title: '额度内发布', content: '内容', plan: 'free' })
|
||
expect(res.order).toBeFalsy()
|
||
expect(res.plan).toBe('quota')
|
||
expect(res.quotaLeft).toBe(29)
|
||
const mine = await postApi.mine({ page: 1, size: 20 })
|
||
const created = mine.list.find((p) => p.title === '额度内发布')
|
||
expect(created).toBeDefined()
|
||
expect(created.auditStatus).toBe(0)
|
||
})
|
||
|
||
it('额度与每日免费次数都用尽时,免费发布被拦截', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.quotaLeft = 0
|
||
datasets.publishRule.freePerDay = 0 // 关闭每日免费额度,隔离出「必须付费」的场景
|
||
await expectReject(() => postApi.create({ title: '无额度', content: '内容', plan: 'free' }), '请选择发布方式')
|
||
})
|
||
|
||
it('付费模式下仍保留每日免费额度(避免硬付费墙)', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.quotaLeft = 0
|
||
datasets.publishRule.freePerDay = 2
|
||
datasets.publishRule.freeUsedToday = 0
|
||
const first = await postApi.create({ title: '今日免费第 1 条', content: '内容', plan: 'free' })
|
||
expect(first.plan).toBe('free')
|
||
expect(first.order).toBeFalsy()
|
||
const cfg = await postApi.publishConfig()
|
||
expect(cfg.freeLeftToday).toBe(1)
|
||
const second = await postApi.create({ title: '今日免费第 2 条', content: '内容', plan: 'free' })
|
||
expect(second.plan).toBe('free')
|
||
// 第 3 条超出每日额度 → 必须付费
|
||
await expectReject(() => postApi.create({ title: '超出每日额度', content: '内容', plan: 'free' }), '请选择发布方式')
|
||
})
|
||
|
||
it('单条付费:金额取后台配置,忽略客户端传入的 amount', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.quotaLeft = 0
|
||
datasets.publishRule.freePerDay = 0
|
||
const res = await postApi.create({
|
||
title: '单条付费发布',
|
||
content: '内容',
|
||
plan: 'single',
|
||
payType: 'wxpay',
|
||
amount: 0.01, // 客户端篡改金额:应被无条件忽略
|
||
})
|
||
expect(res.order.amount).toBe(5)
|
||
expect(res.order.orderNo).toContain('PO')
|
||
})
|
||
|
||
it('单条付费缺少支付方式时报错', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.quotaLeft = 0
|
||
datasets.publishRule.freePerDay = 0
|
||
await expectReject(() => postApi.create({ title: 'x', content: 'y', plan: 'single' }), '支付方式不支持')
|
||
})
|
||
|
||
it('月卡/年卡走会员开通接口,开通后获得对应发布条数', async () => {
|
||
resetPublish()
|
||
datasets.publishRule.quotaLeft = 0
|
||
datasets.publishRule.freePerDay = 0
|
||
const opened = await memberApi.open({ planId: 'M1', payType: 'balance' })
|
||
expect(opened.postQuota).toBe(30)
|
||
expect(opened.quotaLeft).toBe(30)
|
||
const res = await postApi.create({ title: '月卡额度发布', content: '内容', plan: 'free' })
|
||
expect(res.plan).toBe('quota')
|
||
expect(res.quotaLeft).toBe(29)
|
||
// 年卡:含 500 条
|
||
const year = await memberApi.open({ planId: 'M12', payType: 'balance' })
|
||
expect(year.postQuota).toBe(500)
|
||
expect(year.quotaLeft).toBe(529)
|
||
})
|
||
|
||
it('会员套餐列表带出「含发布条数」字段', async () => {
|
||
const plans = await memberApi.plans()
|
||
expect(plans.length).toBe(3)
|
||
plans.forEach((p) => expect(p.postQuota).toBeGreaterThan(0))
|
||
})
|
||
})
|
||
|
||
describe('我的发布 · 审核状态与计数', () => {
|
||
it('列表返回本人信息与各状态计数', async () => {
|
||
const res = await postApi.mine({ page: 1, size: 20 })
|
||
expect(res.list.length).toBeGreaterThan(0)
|
||
expect(res.counts.all).toBeGreaterThan(0)
|
||
expect(res.counts.pending + res.counts.passed + res.counts.rejected).toBeGreaterThan(0)
|
||
res.list.forEach((p) => {
|
||
expect(p.auditStatus).toBeDefined()
|
||
expect(p.status).toBeDefined()
|
||
expect(p.isTop).toBeDefined()
|
||
})
|
||
})
|
||
|
||
it('按状态筛选:待审核 / 已驳回(含驳回原因)/ 已下架', async () => {
|
||
const pending = await postApi.mine({ status: 'pending' })
|
||
expect(pending.list.every((p) => p.auditStatus === 0 && p.status === 1)).toBe(true)
|
||
|
||
const rejected = await postApi.mine({ status: 'rejected' })
|
||
expect(rejected.list.every((p) => p.auditStatus === 2)).toBe(true)
|
||
expect(rejected.list[0].auditReason).toBeTruthy()
|
||
|
||
const offline = await postApi.mine({ status: 'offline' })
|
||
expect(offline.list.every((p) => p.status === 0)).toBe(true)
|
||
})
|
||
|
||
it('置顶的发布记录排在最前', async () => {
|
||
const res = await postApi.mine({ page: 1, size: 20 })
|
||
expect(res.list[0].isTop).toBe(true)
|
||
})
|
||
|
||
it('可删除本人发布(删除后列表不再包含)', async () => {
|
||
const before = await postApi.mine({ page: 1, size: 20 })
|
||
const target = before.list[0]
|
||
await postApi.remove(target.id)
|
||
const after = await postApi.mine({ page: 1, size: 20 })
|
||
expect(after.counts.all).toBe(before.counts.all - 1)
|
||
expect(after.list.some((p) => p.id === target.id)).toBe(false)
|
||
})
|
||
})
|
||
|
||
describe('后台置顶 → 用户端展示闭环', () => {
|
||
it('置顶信息在首页信息流优先展示', async () => {
|
||
const feed = await homeApi.feed({ page: 1, size: 10 })
|
||
expect(feed.list[0].isTop).toBe(true)
|
||
// 置顶项之后才是非置顶项
|
||
const firstUnpinned = feed.list.findIndex((p) => !p.isTop)
|
||
if (firstUnpinned > -1) {
|
||
expect(feed.list.slice(firstUnpinned).every((p) => !p.isTop)).toBe(true)
|
||
}
|
||
})
|
||
})
|