import { Timestamp } from "firebase-admin/firestore"; import { beforeEach, describe, expect, it } from "vitest"; import { firestore } from "../../src/firebase"; import { getCatalog, getCatalogProduct, invalidateRewardCatalog, } from "../../src/services/rewardCatalogService"; const id = "catalog-images-test"; const mainImages = [ "https://cdn.example.com/product/cover.jpg", "https://cdn.example.com/product/gallery-2.jpg", ]; const detailImages = [ "https://cdn.example.com/product/detail-1.jpg", "https://cdn.example.com/product/detail-2.jpg", ]; describe("rewardCatalogService image contract", () => { beforeEach(async () => { invalidateRewardCatalog(id); await firestore.doc(`products/${id}`).delete(); const now = Timestamp.now(); await firestore.doc(`products/${id}`).set({ name: "이미지 계약 상품", pointPrice: 1000, active: true, redeemable: true, displayOrder: 999, mainImages, detailImages, totalStock: 10, reservedStock: 2, safetyStock: 1, createdAt: now, updatedAt: now, }); }); it("목록에는 순서가 보존된 mainImages만 노출한다", async () => { const product = (await getCatalog()).find((item) => item.id === id); expect(product).toMatchObject({ id, mainImages }); expect(product).not.toHaveProperty("detailImages"); expect(product).not.toHaveProperty("totalStock"); expect(product).not.toHaveProperty("reservedStock"); expect(product).not.toHaveProperty("safetyStock"); }); it("상세에는 mainImages와 detailImages를 모두 순서대로 노출한다", async () => { expect(await getCatalogProduct(id)).toMatchObject({ id, mainImages, detailImages, }); }); });