- 模块一: 出海案例作品集、博客动态发布、人名发音语音条、RTL阿语多语言切换 - 模块二: AI顾问人设配置、行业术语库润色、RAG切片沙盒调试、流式会话与意向留资卡片 - 模块三: 全球访客雷达大屏、多维加权意向算分、外部CRM对接推送、团队公海池流转 - 模块四: 移动端NFC安全挂失、NFC动态路由规则配置、动态防伪验签、展会制卡Zip批量导出 - 模块五: 组织架构与名片分配、移动端个人中心设置、离职交接与历史线索迁移、安全审计日志 - 模块六: Stripe国际信用卡订阅Webhook、独立二级域名与SSL检测、坐席配额预警、多币种发票 - 模块七: 纸质名片OCR解析入库、国际商务日程RFC 5545 ICS日历、微官网离线SWR预加载、展会实时排行榜大屏 - 模块八: 全球出海SEO OpenGraph元标签注入与社交爬虫探测、30点端到端全链路业务流集成测试套件
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({ updateTime: '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);
|
|
});
|
|
});
|
|
});
|