- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
126 行
5.1 KiB
JavaScript
126 行
5.1 KiB
JavaScript
/**
|
||
* 真实数据对接回归(消除前端写死的假数据)
|
||
*
|
||
* 覆盖:
|
||
* ① GET /home/areas —— 区域选项由后台「区域管理」下发
|
||
* ② GET /message/unread-count —— 首页消息角标由后端未读数驱动
|
||
* ③ GET /distribution/overview —— 最低提现金额由后台「分销设置」下发
|
||
* ④ 源码断言:登录不再伪造 mock_code / 营业执照假文件名;首页不再写死会员文案、角标与区域
|
||
*/
|
||
import fs from 'node:fs'
|
||
import path from 'node:path'
|
||
import url from 'node:url'
|
||
import { describe, it, expect } from './harness.mjs'
|
||
import { homeApi, messageApi, distributionApi, postApi } from '../common/api/index.js'
|
||
import { datasets } from '../common/mock/data.js'
|
||
import { flattenAreaTree, groupAreaTree } from '../common/utils/area.js'
|
||
|
||
const ROOT = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..')
|
||
const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8')
|
||
|
||
describe('对接 · 服务区域来自后台', () => {
|
||
it('GET /home/areas 返回平铺服务区域,每条自带省/市/区县', async () => {
|
||
const rows = await homeApi.areas()
|
||
expect(rows).toBeArray()
|
||
const yunyan = rows.find((r) => r.district === '云岩区')
|
||
expect(yunyan).toBeDefined()
|
||
expect(yunyan.province).toBe('贵州省')
|
||
expect(yunyan.city).toBe('贵阳市')
|
||
expect(rows.every((r) => r.province && r.city && r.district)).toBe(true)
|
||
// 白云区在后台被停用,不应下发
|
||
expect(rows.some((r) => r.district === '白云区')).toBe(false)
|
||
})
|
||
it('GET /home/locate 按坐标匹配到服务区域', async () => {
|
||
const found = await homeApi.locate({ lat: 26.605, lng: 106.71 })
|
||
expect(found).toBeDefined()
|
||
expect(found.city).toBe('贵阳市')
|
||
expect(found.district).toBe('云岩区')
|
||
})
|
||
it('级联选择:按省/市分组,列表筛选只出现区县', async () => {
|
||
const rows = await homeApi.areas()
|
||
const tree = groupAreaTree(rows)
|
||
expect(tree[0].name).toBe('贵州省')
|
||
expect(tree[0].cities[0].name).toBe('贵阳市')
|
||
expect(tree[0].cities[0].districts.some((d) => d.name === '云岩区')).toBe(true)
|
||
const options = flattenAreaTree(rows)
|
||
expect(options.every((o) => o.key === 'all' || o.key.indexOf('area-') === 0)).toBe(true)
|
||
expect(options.some((o) => o.label === '云岩区')).toBe(true)
|
||
})
|
||
})
|
||
|
||
describe('对接 · 首页未读角标来自后台', () => {
|
||
it('GET /message/unread-count 返回未读消息数', async () => {
|
||
const res = await messageApi.unreadCount()
|
||
expect(res.count).toBe(datasets.messages.filter((m) => !m.read).length)
|
||
})
|
||
})
|
||
|
||
describe('对接 · 最低提现金额来自后台', () => {
|
||
it('GET /distribution/overview 含 minWithdraw', async () => {
|
||
const res = await distributionApi.overview()
|
||
expect(res.minWithdraw).toBeDefined()
|
||
expect(res.minWithdraw).toBe(50)
|
||
})
|
||
})
|
||
|
||
describe('对接 · 详情页评价来自后台', () => {
|
||
it('GET /post/:id/comments 仅返回该信息的评价', async () => {
|
||
const list = await postApi.comments(101)
|
||
expect(list).toBeArray()
|
||
const expected = datasets.comments.filter((c) => String(c.postId) === '101')
|
||
expect(list.length).toBe(expected.length)
|
||
if (list.length) {
|
||
expect(list[0].user).toBe(expected[0].user)
|
||
expect(list[0].content).toBe(expected[0].content)
|
||
}
|
||
})
|
||
|
||
it('详情页不再写死假评价', () => {
|
||
const src = read('pages/detail/detail.vue')
|
||
expect(src.includes("user: '小王同学'")).toBe(false)
|
||
expect(src.includes("user: '果果'")).toBe(false)
|
||
})
|
||
})
|
||
|
||
describe('去假数据 · 源码断言', () => {
|
||
it('登录页不再伪造微信 code(mock_code)', () => {
|
||
const src = read('pages/auth/login.vue')
|
||
expect(src.includes("resolve('mock_code')")).toBe(false)
|
||
expect(src.includes("r.code || 'mock_code'")).toBe(false)
|
||
})
|
||
|
||
it('登录页不再伪造营业执照文件名', () => {
|
||
expect(read('pages/auth/login.vue').includes("license = '营业执照.jpg'")).toBe(false)
|
||
})
|
||
|
||
it('首页不再写死会员文案与未读角标', () => {
|
||
const src = read('pages/index/index.vue')
|
||
expect(src.includes('每日免费查看 20 条联系方式')).toBe(false)
|
||
expect(src.includes('超值月卡 ¥19.9 起')).toBe(false)
|
||
expect(src.includes('unread: 2')).toBe(false)
|
||
})
|
||
|
||
it('首页区域选项不再写死', () => {
|
||
expect(read('pages/index/index.vue').includes("['云岩区', '南明区', '观山湖区', '花溪区']")).toBe(false)
|
||
})
|
||
|
||
it('首页不再写死定位区名', () => {
|
||
expect(read('pages/index/index.vue').includes("location: '贵阳 · 观山湖区'")).toBe(false)
|
||
})
|
||
|
||
it('信息列表区域选项不再写死', () => {
|
||
expect(read('pages/post/list.vue').includes("['云岩区', '南明区', '观山湖区', '花溪区']")).toBe(false)
|
||
})
|
||
|
||
it('首页未读角标调用前有登录态守卫,避免游客被 401 跳登录页', () => {
|
||
const src = read('pages/index/index.vue')
|
||
// loadUnread 内部必须先判断 isLogin,再调用需要鉴权的接口
|
||
const body = src.slice(src.indexOf('async loadUnread()'))
|
||
const guardAt = body.indexOf('isLogin')
|
||
const callAt = body.indexOf('messageApi.unreadCount()')
|
||
expect(guardAt).toBeGreaterThan(-1)
|
||
expect(callAt).toBeGreaterThan(-1)
|
||
expect(guardAt < callAt).toBe(true)
|
||
})
|
||
})
|