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.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: "waiting" 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: "waiting" 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: "ended" 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);
|
|
});
|
|
}); |