- TypeScript 소스 파일 내 모든 import 구문에서 불필요한 `.js` 확장자를 제거하여 모듈 참조 방식을 표준화했습니다. - 핸들러, 서비스, 리포지토리 및 테스트 코드를 포함한 프로젝트 전반의 import 경로를 일관성 있게 정리했습니다.
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { Timestamp } from "firebase-admin/firestore";
|
|
import { firestore } from "../../src/firebase";
|
|
import { getGame, listByDate } from "../../src/repositories/gameRepository";
|
|
import type { DateString } from "../../src/types/dateString";
|
|
|
|
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);
|
|
});
|
|
}); |