- 仓储 getCompanions(keyword?):参数化 LIKE 搜索 name/track/rank_name/tags 及 id 精确匹配 - 接口 /api/companions 支持 ?keyword=(长度截断 40) - 小程序 api.js getCompanions(keyword) 带 encodeURIComponent;首页监听 searchKeyword 防抖 350ms 走服务端搜索,搜索态以服务端结果为准(含空结果不展示陈旧数据) - 回归 95 套件/668 用例全绿;冒烟 4/4(昵称/品类命中、无匹配空数组、无关键词向后兼容)
28 行
1.2 KiB
TypeScript
28 行
1.2 KiB
TypeScript
// 已读取AGENTS.md
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
/**
|
|
* 第七十九批:大神关键词搜索(服务端)。
|
|
*/
|
|
describe('第七十九批大神搜索闸门', () => {
|
|
const root = path.resolve(__dirname, '../../');
|
|
const indexCode = fs.readFileSync(path.join(root, 'server/src/index.ts'), 'utf-8');
|
|
const repo = fs.readFileSync(path.join(root, 'server/src/db/repository.ts'), 'utf-8');
|
|
const api = fs.readFileSync(path.join(root, 'pwuniapp/common/api.js'), 'utf-8');
|
|
const home = fs.readFileSync(path.join(root, 'pwuniapp/pages/index/index.vue'), 'utf-8');
|
|
|
|
it('后端支持关键词搜索(参数化,避免注入)', () => {
|
|
expect(indexCode).toContain('req.query.keyword');
|
|
expect(repo).toContain('async getCompanions(keyword?: string)');
|
|
expect(repo).toContain('WHERE name LIKE ? OR track LIKE ? OR rank_name LIKE ?');
|
|
});
|
|
|
|
it('小程序搜索走服务端并做防抖', () => {
|
|
expect(api).toContain('export async function getCompanions(keyword)');
|
|
expect(api).toContain('encodeURIComponent(kw)');
|
|
expect(home).toContain('watch(searchKeyword');
|
|
expect(home).toContain('fetchLiveCompanions');
|
|
});
|
|
});
|