mmday-firebase/tests/repositories/gameRepository.test.ts
윤정민 c7e4ed8c22 Standardize game status values and make favorite team optional.
- `GameStatus` 타입을 `scheduled`, `live`, `completed`, `cancelled`로 변경하여 상태 관리의 일관성을 높였습니다.
- 사용자 프로필의 `favoriteTeamCode`를 선택 사항으로 변경하고, null 또는 undefined 입력에 대한 처리를 추가했습니다.
- KBO 데이터 병합 과정에 상세 로그를 도입하여 실시간 데이터 매칭 및 외부 API 호출 실패 상황에 대한 가시성을 확보했습니다.
- 상태 값 변경에 따라 영향받는 서비스 로직과 테스트 코드를 일괄 업데이트했습니다.
2026-04-14 23:08:45 +09:00

66 lines
2.2 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import { Timestamp } from "firebase-admin/firestore";
import { firestore } from "../../src/firebase.js";
import { getGame, listByDate } from "../../src/repositories/gameRepository.js";
import type { DateString } from "../../src/types/dateString.js";
describe("gameRepository", () => {
beforeEach(async () => {
await firestore.recursiveDelete(firestore.collection("games"));
});
it("존재하지 않는 경기는 null을 반환한다", async () => {
const result = await getGame("nonexistent");
expect(result).toBeNull();
});
describe("listByDate", () => {
it("지정한 KST 날짜의 경기만 시간순으로 반환한다", async () => {
// 2026-04-12 18:30 KST = 2026-04-12 09:30 UTC
const game1 = {
time: Timestamp.fromDate(new Date("2026-04-12T09:30:00.000Z")),
stadium: "잠실",
status: "scheduled" as const,
homeTeamCode: "LG",
awayTeamCode: "HT",
};
// 2026-04-12 14:00 KST = 2026-04-12 05:00 UTC (먼저)
const game2 = {
time: Timestamp.fromDate(new Date("2026-04-12T05:00:00.000Z")),
stadium: "문학",
status: "scheduled" as const,
homeTeamCode: "SK",
awayTeamCode: "WO",
};
// 2026-04-11 18:30 KST = 범위 밖
const game3 = {
time: Timestamp.fromDate(new Date("2026-04-11T09:30:00.000Z")),
stadium: "사직",
status: "completed" as const,
homeTeamCode: "LT",
awayTeamCode: "KT",
};
await firestore.collection("games").doc("g1").set(game1);
await firestore.collection("games").doc("g2").set(game2);
await firestore.collection("games").doc("g3").set(game3);
const result = await listByDate("2026-04-12" as DateString);
expect(result.map((g) => g.gameId)).toEqual(["g2", "g1"]);
});
});
it("저장된 경기를 정상적으로 조회한다", async () => {
const gameId = "20260412HTLG0";
const gameData = {
date: "2026-04-12",
homeTeam: "LG",
awayTeam: "KIA",
status: "scheduled",
};
await firestore.collection("games").doc(gameId).set(gameData);
const result = await getGame(gameId);
expect(result).toMatchObject(gameData);
});
});