feat(round-14): GDPR脱敏被遗忘权/展会海报排版/全球雷达热力散点/DeepLink深度路由 (95套件1053测试全绿)
这个提交包含在:
@@ -0,0 +1,93 @@
|
||||
import {
|
||||
RadarGeoHeatmapService,
|
||||
resolveCityCoordinates,
|
||||
calculateGeoHeatPoints,
|
||||
VisitorGeoLog,
|
||||
GeoHeatPoint,
|
||||
} from '../../../src/modules/crm/service/geo-heatmap';
|
||||
|
||||
describe('Point 55: 全球访客雷达国家城市坐标聚合与热力散点引擎', () => {
|
||||
let service: RadarGeoHeatmapService;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new RadarGeoHeatmapService();
|
||||
});
|
||||
|
||||
describe('1. resolveCityCoordinates (出海核心商务枢纽城市经纬度解析)', () => {
|
||||
it('应精准解析迪拜、利雅得、新加坡与伦敦经纬度', () => {
|
||||
const dubai = resolveCityCoordinates('AE', 'Dubai');
|
||||
expect(dubai).toEqual([55.27, 25.20]);
|
||||
|
||||
const riyadh = resolveCityCoordinates('SA', 'Riyadh');
|
||||
expect(riyadh).toEqual([46.67, 24.71]);
|
||||
|
||||
const sg = resolveCityCoordinates('SG', 'Singapore');
|
||||
expect(sg).toEqual([103.81, 1.35]);
|
||||
|
||||
const london = resolveCityCoordinates('GB', 'London');
|
||||
expect(london).toEqual([-0.12, 51.50]);
|
||||
});
|
||||
|
||||
it('未收录城市应平滑回退到对应国家首都或默认中心点', () => {
|
||||
const fallback = resolveCityCoordinates('AE', 'UnknownCity');
|
||||
expect(fallback).toEqual([54.37, 24.45]); // 阿联酋中心点 (Abu Dhabi)
|
||||
});
|
||||
});
|
||||
|
||||
describe('2. calculateGeoHeatPoints (意向权重与时间半衰期热力计算)', () => {
|
||||
const now = Date.now();
|
||||
const mockLogs: VisitorGeoLog[] = [
|
||||
// 迪拜 2 次高意向访问 (1小时前)
|
||||
{
|
||||
country: 'AE',
|
||||
city: 'Dubai',
|
||||
radarScore: 90,
|
||||
timestamp: now - 3600 * 1000,
|
||||
},
|
||||
{
|
||||
country: 'AE',
|
||||
city: 'Dubai',
|
||||
radarScore: 85,
|
||||
timestamp: now - 1800 * 1000,
|
||||
},
|
||||
// 利雅得 1 次访问 (7天前,有时间衰减)
|
||||
{
|
||||
country: 'SA',
|
||||
city: 'Riyadh',
|
||||
radarScore: 80,
|
||||
timestamp: now - 7 * 86400 * 1000,
|
||||
},
|
||||
];
|
||||
|
||||
it('应精准聚合城市点并计算独立访客与加权热度', () => {
|
||||
const points = calculateGeoHeatPoints(mockLogs, now);
|
||||
|
||||
expect(points.length).toBe(2);
|
||||
|
||||
const dubaiPoint = points.find(p => p.city === 'Dubai');
|
||||
expect(dubaiPoint).toBeDefined();
|
||||
expect(dubaiPoint?.visitorCount).toBe(2);
|
||||
expect(dubaiPoint?.coordinates).toEqual([55.27, 25.20]);
|
||||
expect(dubaiPoint?.heatValue).toBeGreaterThan(150); // 近期无衰减累计
|
||||
|
||||
const riyadhPoint = points.find(p => p.city === 'Riyadh');
|
||||
expect(riyadhPoint).toBeDefined();
|
||||
expect(riyadhPoint?.visitorCount).toBe(1);
|
||||
// 7天衰减后热度减半 (~40)
|
||||
expect(riyadhPoint?.heatValue).toBeLessThan(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe('3. RadarGeoHeatmapService 综合数据报告', () => {
|
||||
it('应返回热力散点列表与 Top 国家活跃度榜单', async () => {
|
||||
const result = await service.generateHeatmapReport([
|
||||
{ country: 'AE', city: 'Dubai', radarScore: 95, timestamp: Date.now() },
|
||||
{ country: 'SG', city: 'Singapore', radarScore: 80, timestamp: Date.now() },
|
||||
]);
|
||||
|
||||
expect(result.points.length).toBe(2);
|
||||
expect(result.topCountries[0].country).toBe('AE');
|
||||
expect(result.totalUniqueVisitors).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户