import { beforeEach, describe, expect, it } from "vitest"; import { firestore } from "../../src/firebase"; import { computeEligibility } from "../../src/services/eligibilityService"; import { applyPointChanges } from "../../src/services/pointService"; import { PointLedgerType } from "../../src/types/points"; const uid = "eligibility-points-only"; describe("computeEligibility", () => { beforeEach(async () => { await firestore.recursiveDelete(firestore.doc(`users/${uid}`)); }); it("상점 진입 자격은 가용 포인트 보유 여부만 확인한다", async () => { expect(await computeEligibility(uid)).toEqual({ eligible: false, reasons: ["INSUFFICIENT_BALANCE"], availableBalance: 0, }); await applyPointChanges(uid, [{ txId: `${uid}:admin:seed`, type: PointLedgerType.AdminCredit, amount: 100, }]); expect(await computeEligibility(uid)).toEqual({ eligible: true, reasons: [], availableBalance: 100, }); }); it("주문 자격은 주문 총액 이상의 가용 포인트만 확인한다", async () => { await applyPointChanges(uid, [{ txId: `${uid}:admin:seed-order`, type: PointLedgerType.AdminCredit, amount: 100, }]); expect(await computeEligibility(uid, 101)).toMatchObject({ eligible: false, reasons: ["INSUFFICIENT_BALANCE"], }); expect(await computeEligibility(uid, 100)).toMatchObject({ eligible: true, reasons: [], }); }); });