diff --git a/apps/api/src/modules/riot/riot-league.service.spec.ts b/apps/api/src/modules/riot/riot-league.service.spec.ts new file mode 100644 index 00000000..43158d91 --- /dev/null +++ b/apps/api/src/modules/riot/riot-league.service.spec.ts @@ -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 ( + _path: string, + _options: unknown, + parser?: RiotResponseParser, + ) => + 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([ + { + queueType: 'RANKED_SOLO_5x5', + tier: 'EMERALD', + rank: 'I', + puuid: 'puuid-1', + leaguePoints: 75, + wins: 160, + losses: 148, + }, + ]); + }); +}); diff --git a/apps/api/src/modules/riot/riot-league.service.ts b/apps/api/src/modules/riot/riot-league.service.ts index a8c4614c..3c3003d1 100644 --- a/apps/api/src/modules/riot/riot-league.service.ts +++ b/apps/api/src/modules/riot/riot-league.service.ts @@ -36,7 +36,10 @@ function parseEntry(value: unknown, index: number): RiotLeagueEntryDto { throw new TypeError(`leagueEntries[${index}] must be an object.`); } return { - leagueId: requireString(value.leagueId, `leagueEntries[${index}].leagueId`), + leagueId: optionalString( + value.leagueId, + `leagueEntries[${index}].leagueId`, + ), queueType: requireString( value.queueType, `leagueEntries[${index}].queueType`, @@ -71,6 +74,11 @@ function requireString(value: unknown, path: string): string { 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 { if (typeof value !== 'number' || !Number.isFinite(value)) { throw new TypeError(`${path} must be a finite number.`); diff --git a/apps/api/src/modules/riot/riot.types.ts b/apps/api/src/modules/riot/riot.types.ts index dd7df8d1..fa890349 100644 --- a/apps/api/src/modules/riot/riot.types.ts +++ b/apps/api/src/modules/riot/riot.types.ts @@ -89,7 +89,7 @@ export interface RiotSummonerDto { // League-V4 entries by-puuid 응답 export interface RiotLeagueEntryDto { - leagueId: string; + leagueId?: string; queueType: string; tier: string; rank: string;