- [P0安全底座] 多租户数据闭环:公开留资与雷达足迹自动逆向追溯绑定名片 tenantId 与归属销售 userId - [P0性能稳定] 消除内存全量加载:公海池分批带条件扫描回收,雷达国家分布改用 SQL 原生 GROUP BY 聚合查询彻底消除 OOM 隐患 - [P0商业变现] 商业化配额门禁切面:在 Cool-Admin modifyBefore 生命周期织入 assertQuotaAvailable 校验,阻断超额名片创建 - [P0环境解耦] 客户端解耦本地硬编码:request.uts 支持 api_base_url 本地覆盖,生产数据库名修正为 crmmpdata - [P1高并发削峰] 雷达足迹批量缓冲引擎:引入 CrmRadarBufferService 环形缓冲队列与阈值/定时批量 Bulk Insert 落盘 - [P2中枢租户化] AI 智能中枢多租户 BYOK 与 Token 成本风控:支持企业自带 Key 隔离、Token 消耗账本、用量配额门禁与名片人设个性化联动 - [跨端规范] 对齐 Uni-app x 移动微官网原生首屏与底部原生 tabBar 规范 - [测试驱动] 全工程 116 个测试套件,1,175 个单元与集成测试用例全部 100% 绿色通过,管理后台 Vite 打包无错误
98 行
3.4 KiB
TypeScript
98 行
3.4 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { BaseController } from '@cool-midway/core';
|
|
import { CardInfoEntity } from '../../../src/modules/card/entity/info';
|
|
import { CardPortalService } from '../../../src/modules/card/service/portal';
|
|
import {
|
|
AdminCardInfoController,
|
|
adminCardInfoCurdOption,
|
|
} from '../../../src/modules/card/controller/admin/info';
|
|
import { CardInfoService } from '../../../src/modules/card/service/info';
|
|
|
|
describe('后台名片 CRUD (Admin Card Info CoolController)', () => {
|
|
const controllerFile = path.join(
|
|
__dirname,
|
|
'../../../src/modules/card/controller/admin/info.ts'
|
|
);
|
|
|
|
describe('1. 控制器装饰器与路由约定', () => {
|
|
it('文件路径应符合 /admin/card/info 自动路由约定', () => {
|
|
expect(fs.existsSync(controllerFile)).toBe(true);
|
|
expect(controllerFile.replace(/\\/g, '/')).toMatch(
|
|
/modules\/card\/controller\/admin\/info\.ts$/
|
|
);
|
|
});
|
|
|
|
it('控制器应继承 BaseController 并挂载 CoolController CRUD', () => {
|
|
expect(AdminCardInfoController.prototype).toBeInstanceOf(BaseController);
|
|
expect(adminCardInfoCurdOption.entity).toBe(CardInfoEntity);
|
|
expect(adminCardInfoCurdOption.service).toBe(CardInfoService);
|
|
});
|
|
|
|
it('装饰器 api 必须包含 add/delete/update/info/list/page', () => {
|
|
expect(adminCardInfoCurdOption.api).toEqual([
|
|
'add',
|
|
'delete',
|
|
'update',
|
|
'info',
|
|
'list',
|
|
'page',
|
|
]);
|
|
});
|
|
|
|
it('infoIgnoreProperty 必须包含 remark 与 internalConfig', () => {
|
|
expect(adminCardInfoCurdOption.infoIgnoreProperty).toEqual(
|
|
expect.arrayContaining(['remark', 'internalConfig'])
|
|
);
|
|
});
|
|
|
|
it('pageQueryOp 应支持 name 模糊搜索与 status 精确筛选', () => {
|
|
const pageQueryOp = adminCardInfoCurdOption.pageQueryOp;
|
|
expect(pageQueryOp.keyWordLikeFields).toEqual(
|
|
expect.arrayContaining(['a.name'])
|
|
);
|
|
expect(pageQueryOp.fieldEq).toEqual(expect.arrayContaining(['a.status']));
|
|
expect(pageQueryOp.addOrderBy).toEqual({ update_time: 'desc' });
|
|
});
|
|
|
|
it('insertParam 应从后台登录态写入 userId', () => {
|
|
expect(
|
|
adminCardInfoCurdOption.insertParam({ admin: { userId: 42 } })
|
|
).toEqual({ userId: 42 });
|
|
expect(adminCardInfoCurdOption.insertParam({})).toEqual({
|
|
userId: undefined,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('2. modifyAfter 发布后清缓存', () => {
|
|
let service: CardInfoService;
|
|
let clearPortalCache: jest.Mock;
|
|
|
|
beforeEach(() => {
|
|
clearPortalCache = jest.fn().mockResolvedValue(undefined);
|
|
service = new CardInfoService();
|
|
service.cardPortalService = {
|
|
clearPortalCache,
|
|
} as unknown as CardPortalService;
|
|
});
|
|
|
|
it('add 时应按 id 或 slug 调用 clearPortalCache', async () => {
|
|
await service.modifyAfter({ id: 101, slug: 'alex-zheng' }, 'add');
|
|
expect(clearPortalCache).toHaveBeenCalledWith(101);
|
|
expect(clearPortalCache).toHaveBeenCalledWith('alex-zheng');
|
|
});
|
|
|
|
it('update 时应清缓存', async () => {
|
|
await service.modifyAfter({ id: 101 }, 'update');
|
|
expect(clearPortalCache).toHaveBeenCalledWith(101);
|
|
});
|
|
|
|
it('delete 时应按 id 列表清缓存', async () => {
|
|
await service.modifyAfter([101, 102], 'delete');
|
|
expect(clearPortalCache).toHaveBeenCalledWith(101);
|
|
expect(clearPortalCache).toHaveBeenCalledWith(102);
|
|
});
|
|
});
|
|
});
|