feat(api): add match stats fragments
This commit is contained in:
1 parent
b3b59d37fc
commit
956e45ee59
6 files changed
+777
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import mongoose from 'mongoose';
|
||||
import type { MatchDocument } from '../global/database/schema';
|
||||
import { MatchStatsFragmentBuilder } from './match-stats-fragment.builder';
|
||||
|
||||
function makeMatch(): MatchDocument {
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
return {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
communityId: new mongoose.Types.ObjectId(),
|
||||
title: '내전',
|
||||
scheduledAt: new Date('2026-05-03T00:00:00.000Z'),
|
||||
status: 'finished',
|
||||
gameCount: 1,
|
||||
participants: [
|
||||
{
|
||||
userId,
|
||||
puuid: 'puuid-1',
|
||||
gameName: 'Player',
|
||||
profileIconId: 7,
|
||||
},
|
||||
],
|
||||
teams: [
|
||||
{
|
||||
teamIndex: 1,
|
||||
name: 'A',
|
||||
members: [{ userId, assignedPosition: 'TOP' }],
|
||||
},
|
||||
{ teamIndex: 2, name: 'B', members: [] },
|
||||
],
|
||||
result: {
|
||||
winnerTeamIndex: 1,
|
||||
riotMatchIds: ['KR_1'],
|
||||
games: [
|
||||
{
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_1',
|
||||
blueTeamIndex: 1,
|
||||
redTeamIndex: 2,
|
||||
winnerTeamIndex: 1,
|
||||
winnerSide: 'blue',
|
||||
gameCreation: 1_000,
|
||||
gameDuration: 1_800,
|
||||
participants: [
|
||||
{
|
||||
userId,
|
||||
teamIndex: 1,
|
||||
side: 'blue',
|
||||
championId: 266,
|
||||
kills: 5,
|
||||
deaths: 1,
|
||||
assists: 7,
|
||||
win: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
seriesResults: [
|
||||
{
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 2,
|
||||
teamAWins: 1,
|
||||
teamBWins: 0,
|
||||
winnerTeamIndex: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
} as unknown as MatchDocument;
|
||||
}
|
||||
|
||||
describe('MatchStatsFragmentBuilder', () => {
|
||||
it('builds a fallback fragment without raw Riot match data', () => {
|
||||
const builder = new MatchStatsFragmentBuilder();
|
||||
const match = makeMatch();
|
||||
|
||||
const fragment = builder.buildFragment({
|
||||
match,
|
||||
rawByRiotMatchId: new Map(),
|
||||
});
|
||||
|
||||
expect(fragment.matchCard.matchId).toBe(match._id.toString());
|
||||
expect(fragment.gameCreationMin).toBe(1_000);
|
||||
expect(fragment.gameCreationMax).toBe(1_000);
|
||||
expect(fragment.userIds.map((id) => id.toString())).toEqual([
|
||||
match.participants[0].userId.toString(),
|
||||
]);
|
||||
expect(fragment.championIds).toEqual([266]);
|
||||
expect(fragment.records).toHaveLength(1);
|
||||
expect(fragment.records[0]).toMatchObject({
|
||||
summonerName: 'Player',
|
||||
championId: 266,
|
||||
kills: 5,
|
||||
deaths: 1,
|
||||
assists: 7,
|
||||
win: true,
|
||||
});
|
||||
expect(fragment.gameDetails[0].teams[0].participants).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user