Expose mentor match API

This commit is contained in:
dahyeon committed 2026-07-03 02:04:11 -07:00
1 parent 4f70e07cb7
commit 1d8037adf1
4 files changed
+259 -2

No files matched your search

+118 -1
View File
@@ -3,6 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import {
FEATURE_SCHEMA_VERSION,
type MentorMatchesDto,
type PlayerAnalysisDto,
} from '@persona-lenz/shared';
import request from 'supertest';
@@ -10,7 +11,11 @@ import { App } from 'supertest/types';
import { configureApp } from './../src/app.setup';
import { AppModule } from './../src/app.module';
import { AnalysisQueueService } from './../src/modules/analysis/analysis-queue.service';
import { ANALYSIS_QUEUE_NAME } from './../src/modules/analysis/analysis.constants';
import {
ANALYSIS_QUEUE_NAME,
SEED_COLLECTION_QUEUE_NAME,
} from './../src/modules/analysis/analysis.constants';
import { MentorMatchService } from './../src/modules/analysis/mentor-match.service';
import { ConnectionService } from './../src/modules/global/database/connection.service';
import { REDIS_CLIENT } from './../src/modules/global/redis/redis.constants';
import { SecretService } from './../src/modules/global/secret/secret.service';
@@ -20,6 +25,9 @@ describe('AppController (e2e)', () => {
let analysisQueueService: {
enqueueUserAnalysis: jest.Mock;
};
let mentorMatchService: {
findMentorMatches: jest.Mock;
};
let connectionService: {
getModel: jest.Mock;
};
@@ -36,6 +44,9 @@ describe('AppController (e2e)', () => {
analysisQueueService = {
enqueueUserAnalysis: jest.fn(),
};
mentorMatchService = {
findMentorMatches: jest.fn(),
};
connectionService = {
getModel: jest.fn(),
};
@@ -46,6 +57,8 @@ describe('AppController (e2e)', () => {
.useValue(connectionService)
.overrideProvider(AnalysisQueueService)
.useValue(analysisQueueService)
.overrideProvider(MentorMatchService)
.useValue(mentorMatchService)
.overrideProvider(SecretService)
.useValue({
get: jest.fn((key: string) => {
@@ -65,6 +78,10 @@ describe('AppController (e2e)', () => {
.useValue({
add: jest.fn(),
})
.overrideProvider(getQueueToken(SEED_COLLECTION_QUEUE_NAME))
.useValue({
add: jest.fn(),
})
.compile();
app = moduleFixture.createNestApplication();
@@ -334,6 +351,7 @@ describe('AppController (e2e)', () => {
expect(profileFindOne).toHaveBeenCalledWith({
puuid: 'target-puuid',
queueId: 420,
featureSchemaVersion: FEATURE_SCHEMA_VERSION,
});
expect(responseBody).toEqual({
account: {
@@ -410,6 +428,105 @@ describe('AppController (e2e)', () => {
});
});
it('/api/players/:puuid/mentor-matches (GET) returns mentor matches with display Riot IDs', async () => {
mentorMatchService.findMentorMatches.mockResolvedValue({
puuid: 'target-puuid',
queueId: 420,
profileUpdatedAt: new Date('2026-07-02T00:00:00.000Z'),
matches: [
{
puuid: 'mentor-puuid',
similarityScore: 0.87,
finalScore: 0.81,
tier: 'CHALLENGER',
leaguePoints: 900,
mainRole: 'MIDDLE',
mainChampions: [{ championId: 103, games: 20, wins: 14 }],
sampleGameCount: 40,
similarMetrics: [
{
metricId: 'kda',
currentValue: 0.3,
mentorValue: 0.31,
absoluteGap: 0.01,
},
],
gapMetrics: [
{
metricId: 'goldPerMin',
currentValue: 0.5,
mentorValue: 0.8,
mentorAdvantage: 0.3,
},
],
},
],
});
const accountFind = jest.fn(() =>
createLeanExec([
{
puuid: 'mentor-puuid',
gameName: '프리리',
tagLine: 'KR1',
},
]),
);
connectionService.getModel.mockResolvedValue({
find: accountFind,
});
const response = await request(app.getHttpServer())
.get('/api/players/target-puuid/mentor-matches?limit=3')
.expect(200);
const responseBody = response.body as MentorMatchesDto;
expect(mentorMatchService.findMentorMatches).toHaveBeenCalledWith(
'target-puuid',
420,
3,
);
expect(accountFind).toHaveBeenCalledWith({
puuid: { $in: ['mentor-puuid'] },
});
expect(responseBody).toEqual({
puuid: 'target-puuid',
queueId: 420,
profileUpdatedAt: '2026-07-02T00:00:00.000Z',
matches: [
{
puuid: 'mentor-puuid',
riotId: {
gameName: '프리리',
tagLine: 'KR1',
},
similarityScore: 0.87,
finalScore: 0.81,
tier: 'CHALLENGER',
leaguePoints: 900,
mainRole: 'MIDDLE',
mainChampions: [{ championId: 103, games: 20, wins: 14 }],
sampleGameCount: 40,
similarMetrics: [
{
metricId: 'kda',
currentValue: 0.3,
mentorValue: 0.31,
absoluteGap: 0.01,
},
],
gapMetrics: [
{
metricId: 'goldPerMin',
currentValue: 0.5,
mentorValue: 0.8,
mentorAdvantage: 0.3,
},
],
},
],
});
});
afterEach(async () => {
await app.close();
});