import { beforeEach, describe, expect, it } from "vitest"; import { Timestamp } from "firebase-admin/firestore"; import { firestore } from "../../src/firebase"; import { listAllProducts, listProducts } from "../../src/repositories/productRepository"; import type { ProductDoc } from "../../src/types/reward"; const now = Timestamp.now(); function makeProduct(overrides: Partial = {}): ProductDoc { return { name: "상품", pointPrice: 1000, active: true, redeemable: true, displayOrder: 0, mainImages: [], detailImages: [], createdAt: now, updatedAt: now, ...overrides, }; } describe("productRepository", () => { beforeEach(async () => { await firestore.recursiveDelete(firestore.collection("products")); }); describe("listAllProducts", () => { it("active/redeemable 필터 없이 비노출 상품도 포함해 전체를 반환한다", async () => { await firestore.doc("products/exposed").set(makeProduct({ active: true, redeemable: true })); await firestore.doc("products/hidden-inactive").set(makeProduct({ active: false, redeemable: true })); await firestore.doc("products/hidden-non-redeemable").set(makeProduct({ active: true, redeemable: false })); const all = await listAllProducts(); expect(all.map((p) => p.id).sort()).toEqual([ "exposed", "hidden-inactive", "hidden-non-redeemable", ]); }); it("listProducts(소비자용)는 여전히 active+redeemable 필터가 걸려 있다", async () => { await firestore.doc("products/exposed").set(makeProduct({ active: true, redeemable: true })); await firestore.doc("products/hidden").set(makeProduct({ active: false, redeemable: true })); const consumerList = await listProducts(); expect(consumerList.map((p) => p.id)).toEqual(["exposed"]); }); }); });