本次提交完成多模块真实数据对接,移除前端硬编码假数据: - 新增后端接口:区域列表、未读消息数、详情页评价列表、最低提现金额 - 前端对应修改:移除首页/列表/详情页硬编码区域选项、未读消息数、评价内容,分销页最低提现金额 - 修复登录页微信授权不伪造code、营业执照不伪造文件名,避免绕过校验 - 新增集成测试用例,验证真实数据对接正确性
108 行
4.1 KiB
JavaScript
108 行
4.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'
|
||
|
||
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 仅返回启用区域,按 sort 升序', async () => {
|
||
const areas = await homeApi.areas()
|
||
expect(areas).toBeArray()
|
||
const enabled = datasets.areas
|
||
.filter((a) => a.enabled)
|
||
.sort((a, b) => a.sort - b.sort)
|
||
.map((a) => a.name)
|
||
expect(areas).toEqual(enabled)
|
||
expect(areas).toContain('云岩区')
|
||
})
|
||
})
|
||
|
||
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)
|
||
})
|
||
})
|