mmday-firebase/tests/repositories/kboRepository.test.ts
윤정민 c94ce69e4f Remove redundant .js extensions from import paths.
- TypeScript 소스 파일 내 모든 import 구문에서 불필요한 `.js` 확장자를 제거하여 모듈 참조 방식을 표준화했습니다.
- 핸들러, 서비스, 리포지토리 및 테스트 코드를 포함한 프로젝트 전반의 import 경로를 일관성 있게 정리했습니다.
2026-05-06 16:17:51 +09:00

78 lines
2.9 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import { firestore } from "../../src/firebase";
import {
fetchRankFromKbo,
fetchScheduleFromKbo,
} from "../../src/repositories/kboRepository";
describe("kboRepository (실제 KBO 사이트 호출)", () => {
beforeEach(async () => {
console.log("[setup] 캐시/락 컬렉션 초기화");
await firestore.recursiveDelete(firestore.collection("kboCache"));
await firestore.recursiveDelete(firestore.collection("kboLocks"));
});
it("팀 순위를 정상적으로 fetch한다", async () => {
console.log("\n[rank] 2025년 팀 순위 fetch 시작");
const t0 = Date.now();
const [result] = await fetchRankFromKbo([2025]);
console.log(`[rank] fetch 완료 (${Date.now() - t0}ms)`);
console.log(`[rank] year=${result.year}, teams=${result.teams.length}`);
console.table(
result.teams.map((t) => ({
rank: t.rank,
team: t.team,
winRate: t.winRate,
games: t.games,
}))
);
expect(result.year).toBe(2025);
expect(Array.isArray(result.teams)).toBe(true);
expect(result.teams.length).toBe(10);
expect(result.teams[0]).toHaveProperty("team");
expect(result.teams[0]).toHaveProperty("rank");
}, 30000);
it("경기 일정을 정상적으로 fetch한다", async () => {
console.log("\n[schedule] 2025-04 일정 fetch 시작");
const t0 = Date.now();
const result = await fetchScheduleFromKbo({ year: 2025, month: 4 });
console.log(`[schedule] fetch 완료 (${Date.now() - t0}ms)`);
console.log(
`[schedule] year=${result.year}, month=${result.month}, games=${result.games.length}`
);
console.log("[schedule] 첫 3개 경기:");
console.table(result.games.slice(0, 3));
expect(result.year).toBe(2025);
expect(result.month).toBe(4);
expect(Array.isArray(result.games)).toBe(true);
expect(result.games.length).toBeGreaterThan(0);
expect(result.games[0]).toHaveProperty("gameId");
expect(result.games[0]).toHaveProperty("homeTeamCode");
expect(result.games[0]).toHaveProperty("awayTeamCode");
}, 30000);
it("같은 요청을 두 번 하면 두 번째는 캐시에서 온다", async () => {
console.log("\n[cache] 1차 호출 (실제 fetch 예상)");
const start1 = Date.now();
await fetchScheduleFromKbo({ year: 2025, month: 5 });
const firstDuration = Date.now() - start1;
console.log(`[cache] 1차 소요: ${firstDuration}ms`);
console.log("[cache] 2차 호출 (캐시 hit 예상)");
const start2 = Date.now();
await fetchScheduleFromKbo({ year: 2025, month: 5 });
const secondDuration = Date.now() - start2;
console.log(`[cache] 2차 소요: ${secondDuration}ms`);
console.log(
`[cache] 속도 비교: ${firstDuration}ms → ${secondDuration}ms (${(
(1 - secondDuration / firstDuration) *
100
).toFixed(1)}% 빨라짐)`
);
expect(secondDuration).toBeLessThan(firstDuration);
}, 30000);
});