128 lines
3.6 KiB
TypeScript
128 lines
3.6 KiB
TypeScript
import {
|
|
ADVANTAGE_EVENT_WEIGHTS,
|
|
FEATURE_SCHEMA_VERSION,
|
|
METRICS,
|
|
VECTOR_DIMENSION,
|
|
type AnalysisRequestAcceptedDto,
|
|
type AnalysisJobStatusDto,
|
|
type AnalysisRequestDto,
|
|
type PlayerAnalysisDto,
|
|
} from '@persona-lenz/shared';
|
|
|
|
const MVP_1_METRIC_IDS = [
|
|
'kda',
|
|
'killParticipation',
|
|
'damageShare',
|
|
'damagePerMin',
|
|
'goldPerMin',
|
|
'csPerMin',
|
|
'visionScorePerMin',
|
|
'wardsKilledPerMin',
|
|
'controlWardsPlaced',
|
|
'deathsPerMin',
|
|
'objectiveParticipation',
|
|
'soloKills',
|
|
];
|
|
|
|
describe('shared feature registry', () => {
|
|
it('defines MVP 1 vector metrics in the documented order', () => {
|
|
expect(FEATURE_SCHEMA_VERSION).toBe(1);
|
|
expect(METRICS.map((metric) => metric.id)).toEqual(MVP_1_METRIC_IDS);
|
|
expect(VECTOR_DIMENSION).toBe(12);
|
|
expect(METRICS.filter((metric) => metric.includeInVector)).toHaveLength(
|
|
VECTOR_DIMENSION,
|
|
);
|
|
});
|
|
|
|
it('keeps metric ids unique and every MVP 1 metric normalizable by role', () => {
|
|
const metricIds = METRICS.map((metric) => metric.id);
|
|
|
|
expect(new Set(metricIds).size).toBe(metricIds.length);
|
|
for (const metric of METRICS) {
|
|
expect(metric.label).toBeTruthy();
|
|
expect(metric.kind).toBe('scalar');
|
|
expect(metric.includeInVector).toBe(true);
|
|
expect(metric.baseline).toBeDefined();
|
|
expect(Object.keys(metric.baseline ?? {}).sort()).toEqual([
|
|
'BOTTOM',
|
|
'JUNGLE',
|
|
'MIDDLE',
|
|
'TOP',
|
|
'UTILITY',
|
|
]);
|
|
|
|
for (const range of Object.values(metric.baseline ?? {})) {
|
|
expect(range.min).toBeLessThan(range.max);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('marks deaths per minute as lower-is-better for strength scoring', () => {
|
|
expect(
|
|
METRICS.find((metric) => metric.id === 'deathsPerMin')?.direction,
|
|
).toBe('lowerIsBetter');
|
|
});
|
|
|
|
it('defines shared advantage event weights for timeline-derived metrics', () => {
|
|
expect(ADVANTAGE_EVENT_WEIGHTS).toEqual({
|
|
championKill: 1,
|
|
turretPlate: 0.5,
|
|
tower: 1.5,
|
|
dragon: 1.5,
|
|
riftHerald: 1.5,
|
|
baron: 3,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('shared DTO contracts', () => {
|
|
it('exports request, job status, and player analysis DTO shapes', () => {
|
|
const request: AnalysisRequestDto = {
|
|
gameName: 'Hide on bush',
|
|
tagLine: 'KR1',
|
|
platform: 'ph2',
|
|
matchCount: 20,
|
|
};
|
|
const jobStatus: AnalysisJobStatusDto = {
|
|
jobId: 'job-1',
|
|
status: 'processing',
|
|
stage: 'fetch-match-details',
|
|
puuid: 'puuid-1',
|
|
progress: { fetchedMatches: 3, totalMatches: 20 },
|
|
error: null,
|
|
};
|
|
const accepted: AnalysisRequestAcceptedDto = {
|
|
jobId: 'job-1',
|
|
status: 'queued',
|
|
};
|
|
const playstyle = Object.fromEntries(
|
|
MVP_1_METRIC_IDS.map((metricId) => [metricId, 0.5]),
|
|
) as PlayerAnalysisDto['profile']['playstyle'];
|
|
const analysis: PlayerAnalysisDto = {
|
|
account: {
|
|
gameName: 'Hide on bush',
|
|
tagLine: 'KR1',
|
|
profileIconId: 1,
|
|
tiers: [],
|
|
},
|
|
profile: {
|
|
mainRole: 'MIDDLE',
|
|
queueId: 420,
|
|
sampleGameCount: 12,
|
|
championPool: [{ championId: 103, games: 4, wins: 3 }],
|
|
playstyle,
|
|
featureSchemaVersion: FEATURE_SCHEMA_VERSION,
|
|
confidence: 0.9,
|
|
},
|
|
strengths: [{ metricId: 'kda', value: 0.6 }],
|
|
weaknesses: [{ metricId: 'deathsPerMin', value: 0.7 }],
|
|
updatedAt: '2026-07-02T00:00:00.000Z',
|
|
};
|
|
|
|
expect(request.platform).toBe('ph2');
|
|
expect(accepted.status).toBe('queued');
|
|
expect(jobStatus.progress.totalMatches).toBe(20);
|
|
expect(analysis.profile.mainRole).toBe('MIDDLE');
|
|
});
|
|
});
|