fix: accept Riot league entries without leagueId

This commit is contained in:
dahyeon committed 2026-06-07 09:51:37 -07:00
1 parent bd52160d91
commit 528744ebf6
3 files changed
+57 -2

No files matched your search

@@ -0,0 +1,47 @@
import { RiotClientService } from './riot.client.service';
import { RiotLeagueService } from './riot-league.service';
import type { RiotLeagueEntryDto, RiotResponseParser } from './riot.types';
describe('RiotLeagueService', () => {
it('accepts Riot league entries without optional leagueId', async () => {
const client = {
get: jest.fn(
async <T>(
_path: string,
_options: unknown,
parser?: RiotResponseParser<T>,
) =>
parser
? parser([
{
queueType: 'RANKED_SOLO_5x5',
tier: 'EMERALD',
rank: 'I',
puuid: 'puuid-1',
leaguePoints: 75,
wins: 160,
losses: 148,
},
])
: ([] as T),
),
} as unknown as RiotClientService;
const service = new RiotLeagueService(client);
const result = await service.getEntriesByPuuid('puuid-1', {
platform: 'kr',
});
expect(result).toEqual<RiotLeagueEntryDto[]>([
{
queueType: 'RANKED_SOLO_5x5',
tier: 'EMERALD',
rank: 'I',
puuid: 'puuid-1',
leaguePoints: 75,
wins: 160,
losses: 148,
},
]);
});
});
@@ -36,7 +36,10 @@ function parseEntry(value: unknown, index: number): RiotLeagueEntryDto {
throw new TypeError(`leagueEntries[${index}] must be an object.`); throw new TypeError(`leagueEntries[${index}] must be an object.`);
} }
return { return {
leagueId: requireString(value.leagueId, `leagueEntries[${index}].leagueId`), leagueId: optionalString(
value.leagueId,
`leagueEntries[${index}].leagueId`,
),
queueType: requireString( queueType: requireString(
value.queueType, value.queueType,
`leagueEntries[${index}].queueType`, `leagueEntries[${index}].queueType`,
@@ -71,6 +74,11 @@ function requireString(value: unknown, path: string): string {
return value; return value;
} }
function optionalString(value: unknown, path: string): string | undefined {
if (value === undefined || value === null) return undefined;
return requireString(value, path);
}
function requireNumber(value: unknown, path: string): number { function requireNumber(value: unknown, path: string): number {
if (typeof value !== 'number' || !Number.isFinite(value)) { if (typeof value !== 'number' || !Number.isFinite(value)) {
throw new TypeError(`${path} must be a finite number.`); throw new TypeError(`${path} must be a finite number.`);
+1 -1
View File
@@ -89,7 +89,7 @@ export interface RiotSummonerDto {
// League-V4 entries by-puuid 응답 // League-V4 entries by-puuid 응답
export interface RiotLeagueEntryDto { export interface RiotLeagueEntryDto {
leagueId: string; leagueId?: string;
queueType: string; queueType: string;
tier: string; tier: string;
rank: string; rank: string;