176 lines
5.3 KiB
TypeScript
176 lines
5.3 KiB
TypeScript
import { RedisService } from '../global/redis/redis.service';
|
|
import { RiotDdragonService } from './riot-ddragon.service';
|
|
|
|
function jsonResponse(payload: unknown): Response {
|
|
return {
|
|
ok: true,
|
|
json: jest.fn().mockResolvedValue(payload),
|
|
} as unknown as Response;
|
|
}
|
|
|
|
function makeRedisService() {
|
|
return {
|
|
getJson: jest.fn().mockResolvedValue(null),
|
|
setJson: jest.fn().mockResolvedValue(undefined),
|
|
} as unknown as jest.Mocked<RedisService>;
|
|
}
|
|
|
|
describe('RiotDdragonService', () => {
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it('includes localized item, spell, and rune metadata in the manifest', async () => {
|
|
const fetchMock = jest.fn(async (url: string) => {
|
|
if (url.endsWith('/api/versions.json')) {
|
|
return jsonResponse(['15.24.1']);
|
|
}
|
|
if (url.endsWith('/champion.json')) {
|
|
return jsonResponse({
|
|
data: {
|
|
Aatrox: { key: '266', id: 'Aatrox', name: '아트록스' },
|
|
},
|
|
});
|
|
}
|
|
if (url.endsWith('/summoner.json')) {
|
|
return jsonResponse({
|
|
data: {
|
|
SummonerFlash: {
|
|
key: '4',
|
|
id: 'SummonerFlash',
|
|
name: '점멸',
|
|
description: '커서 방향으로 순간이동합니다.',
|
|
tooltip: '<span>커서 방향으로 순간이동합니다.</span>',
|
|
},
|
|
},
|
|
});
|
|
}
|
|
if (url.endsWith('/runesReforged.json')) {
|
|
return jsonResponse([
|
|
{
|
|
id: 8000,
|
|
key: 'Precision',
|
|
icon: 'perk-images/Styles/7201_Precision.png',
|
|
name: '정밀',
|
|
slots: [
|
|
{
|
|
runes: [
|
|
{
|
|
id: 8005,
|
|
key: 'PressTheAttack',
|
|
icon: 'perk-images/Styles/Precision/PressTheAttack/PressTheAttack.png',
|
|
name: '집중 공격',
|
|
shortDesc: '연속 공격 시 추가 피해',
|
|
longDesc:
|
|
'<lol-uikit-tooltipped-keyword>기본 공격</lol-uikit-tooltipped-keyword>으로 적을 약화시킵니다.',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
}
|
|
if (url.endsWith('/item.json')) {
|
|
return jsonResponse({
|
|
data: {
|
|
'1055': {
|
|
name: '도란의 검',
|
|
description:
|
|
'<mainText><stats>공격력 <attention>10</attention></stats></mainText>',
|
|
plaintext: '공격력과 체력을 올려줍니다.',
|
|
gold: {
|
|
base: 450,
|
|
total: 450,
|
|
sell: 180,
|
|
purchasable: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
throw new Error(`Unexpected URL: ${url}`);
|
|
});
|
|
jest.spyOn(global, 'fetch').mockImplementation(fetchMock as typeof fetch);
|
|
|
|
const redis = makeRedisService();
|
|
const service = new RiotDdragonService(redis);
|
|
|
|
await expect(service.getManifest('ko_KR')).resolves.toMatchObject({
|
|
version: '15.24.1',
|
|
locale: 'ko_KR',
|
|
summonerSpells: {
|
|
'4': {
|
|
key: 'SummonerFlash',
|
|
name: '점멸',
|
|
description: '커서 방향으로 순간이동합니다.',
|
|
tooltip: '<span>커서 방향으로 순간이동합니다.</span>',
|
|
},
|
|
},
|
|
runesReforged: [
|
|
{
|
|
id: 8000,
|
|
name: '정밀',
|
|
slots: [
|
|
{
|
|
runes: [
|
|
{
|
|
id: 8005,
|
|
name: '집중 공격',
|
|
shortDesc: '연속 공격 시 추가 피해',
|
|
longDesc:
|
|
'<lol-uikit-tooltipped-keyword>기본 공격</lol-uikit-tooltipped-keyword>으로 적을 약화시킵니다.',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
items: {
|
|
'1055': {
|
|
name: '도란의 검',
|
|
description:
|
|
'<mainText><stats>공격력 <attention>10</attention></stats></mainText>',
|
|
plaintext: '공격력과 체력을 올려줍니다.',
|
|
gold: {
|
|
base: 450,
|
|
total: 450,
|
|
sell: 180,
|
|
purchasable: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
expect.stringContaining('/15.24.1/data/ko_KR/item.json'),
|
|
expect.any(Object),
|
|
);
|
|
expect(redis.setJson).toHaveBeenCalledWith(
|
|
'ddragon:manifest:v5:ko_KR',
|
|
expect.objectContaining({
|
|
summonerSpells: expect.objectContaining({
|
|
'4': expect.objectContaining({
|
|
description: '커서 방향으로 순간이동합니다.',
|
|
}),
|
|
}),
|
|
runesReforged: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
slots: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
runes: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
longDesc: expect.stringContaining('기본 공격'),
|
|
}),
|
|
]),
|
|
}),
|
|
]),
|
|
}),
|
|
]),
|
|
items: expect.objectContaining({
|
|
'1055': expect.objectContaining({ name: '도란의 검' }),
|
|
}),
|
|
}),
|
|
86_400,
|
|
);
|
|
});
|
|
});
|