.
This commit is contained in:
1 parent
285f72b3ee
commit
4bad21c2d8
4 files changed
+124
-8
No files matched your search
@@ -0,0 +1,109 @@
|
||||
import { RiotClientService } from './riot.client.service';
|
||||
import { RiotMatchService } from './riot-match.service';
|
||||
import type { RiotResponseParser } from './riot.types';
|
||||
|
||||
function createMatchPayload() {
|
||||
const participant = {
|
||||
assists: 7,
|
||||
champExperience: 12000,
|
||||
champLevel: 16,
|
||||
championId: 103,
|
||||
championName: 'Ahri',
|
||||
deaths: 2,
|
||||
goldEarned: 12000,
|
||||
goldSpent: 11000,
|
||||
individualPosition: '',
|
||||
item0: 0,
|
||||
item1: 0,
|
||||
item2: 0,
|
||||
item3: 0,
|
||||
item4: 0,
|
||||
item5: 0,
|
||||
item6: 0,
|
||||
kills: 8,
|
||||
neutralMinionsKilled: 12,
|
||||
participantId: 1,
|
||||
perks: {
|
||||
statPerks: { defense: 0, flex: 0, offense: 0 },
|
||||
styles: [],
|
||||
},
|
||||
puuid: 'puuid-1',
|
||||
riotIdGameName: '테스터',
|
||||
riotIdTagLine: 'KR1',
|
||||
summoner1Id: 4,
|
||||
summoner2Id: 14,
|
||||
summonerId: 'summoner-id-1',
|
||||
summonerLevel: 100,
|
||||
summonerName: '',
|
||||
teamId: 100,
|
||||
teamPosition: '',
|
||||
timePlayed: 1800,
|
||||
totalDamageDealtToChampions: 22000,
|
||||
totalDamageTaken: 11000,
|
||||
totalMinionsKilled: 180,
|
||||
visionScore: 20,
|
||||
wardsKilled: 2,
|
||||
wardsPlaced: 10,
|
||||
win: true,
|
||||
};
|
||||
|
||||
return {
|
||||
metadata: {
|
||||
dataVersion: '2',
|
||||
matchId: 'KR_8188913502',
|
||||
participants: ['puuid-1'],
|
||||
},
|
||||
info: {
|
||||
gameCreation: 1777000000000,
|
||||
gameDuration: 1800,
|
||||
gameEndTimestamp: 1777001800000,
|
||||
gameId: 8188913502,
|
||||
gameMode: 'CLASSIC',
|
||||
gameName: 'teambuilder-match-8188913502',
|
||||
gameStartTimestamp: 1777000000000,
|
||||
gameType: 'MATCHED_GAME',
|
||||
gameVersion: '15.8.1',
|
||||
mapId: 11,
|
||||
participants: [participant],
|
||||
platformId: 'KR',
|
||||
queueId: 420,
|
||||
teams: [
|
||||
{
|
||||
bans: [],
|
||||
objectives: {
|
||||
baron: { first: false, kills: 0 },
|
||||
champion: { first: true, kills: 25 },
|
||||
dragon: { first: true, kills: 3 },
|
||||
inhibitor: { first: false, kills: 1 },
|
||||
riftHerald: { first: true, kills: 1 },
|
||||
tower: { first: true, kills: 8 },
|
||||
},
|
||||
teamId: 100,
|
||||
win: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('RiotMatchService', () => {
|
||||
it('accepts empty Riot display fields in match participants', async () => {
|
||||
const payload = createMatchPayload();
|
||||
const riotClientService = {
|
||||
get: jest.fn(
|
||||
async <T>(
|
||||
_path: string,
|
||||
_options: unknown,
|
||||
parser?: RiotResponseParser<T>,
|
||||
) => (parser ? parser(payload) : (payload as T)),
|
||||
),
|
||||
} as unknown as RiotClientService;
|
||||
const service = new RiotMatchService(riotClientService);
|
||||
|
||||
const match = await service.getMatch('KR_8188913502', { region: 'asia' });
|
||||
|
||||
expect(match.info.participants[0].summonerName).toBe('');
|
||||
expect(match.info.participants[0].teamPosition).toBe('');
|
||||
expect(match.info.participants[0].individualPosition).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -247,7 +247,7 @@ function parseParticipant(
|
||||
value.goldSpent,
|
||||
`participants[${index}].goldSpent`,
|
||||
),
|
||||
individualPosition: requireString(
|
||||
individualPosition: requireStringAllowEmpty(
|
||||
value.individualPosition,
|
||||
`participants[${index}].individualPosition`,
|
||||
),
|
||||
@@ -293,12 +293,12 @@ function parseParticipant(
|
||||
value.summonerLevel,
|
||||
`participants[${index}].summonerLevel`,
|
||||
),
|
||||
summonerName: requireString(
|
||||
summonerName: requireStringAllowEmpty(
|
||||
value.summonerName,
|
||||
`participants[${index}].summonerName`,
|
||||
),
|
||||
teamId: requireNumber(value.teamId, `participants[${index}].teamId`),
|
||||
teamPosition: requireString(
|
||||
teamPosition: requireStringAllowEmpty(
|
||||
value.teamPosition,
|
||||
`participants[${index}].teamPosition`,
|
||||
),
|
||||
@@ -539,6 +539,14 @@ function requireString(value: unknown, path: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function requireStringAllowEmpty(value: unknown, path: string): string {
|
||||
if (typeof value !== 'string') {
|
||||
throw new TypeError(`${path} must be a string.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function optionalString(value: unknown, path: string): string | undefined {
|
||||
if (value === undefined || value === null) {
|
||||
return undefined;
|
||||
|
||||
@@ -3,8 +3,8 @@ import type { RiotPlatformRoute, RiotRegionalRoute } from './riot.types';
|
||||
import { GarnetService } from '../global/garnet/garnet.service';
|
||||
|
||||
const APP_LIMITS = [
|
||||
{ windowMs: 1_000, max: 20 },
|
||||
{ windowMs: 120_000, max: 100 },
|
||||
{ windowMs: 1_000, max: 15 },
|
||||
{ windowMs: 120_000, max: 90 },
|
||||
] as const;
|
||||
|
||||
const ACQUIRE_SCRIPT = `
|
||||
|
||||
@@ -148,10 +148,9 @@ export class RiotClientService {
|
||||
const error = await this.createApiError(response, url);
|
||||
if (
|
||||
error.status === 429 &&
|
||||
attempt === 0 &&
|
||||
error.retryAfterSeconds !== undefined
|
||||
attempt === 0
|
||||
) {
|
||||
await sleep(error.retryAfterSeconds * 1000);
|
||||
await sleep((error.retryAfterSeconds ?? 1) * 1000);
|
||||
return this.fetchWithRetry(
|
||||
url,
|
||||
apiKey,
|
||||
|
||||
Reference in new issue
Block a user