import { getPayload } from "payload"; import config from "@payload-config"; /** * Baseline data every test run can assume: a Game Rules global with a main * currency resource. Runs after truncation, so it recreates the baseline on * the empty database each run (idempotent by construction). Banking and * economy code paths throw without a main currency. */ const CURRENCY_CODE_NAME = "res_test_credits"; const payload = await getPayload({ config }); const existingCurrency = await payload.find({ collection: "resources", where: { codeName: { equals: CURRENCY_CODE_NAME } }, limit: 1, overrideAccess: true, }); let currencyId = existingCurrency.docs[0]?.id as number | undefined; if (!currencyId) { const created = await payload.create({ collection: "resources", data: { name: "Test Credits", codeName: CURRENCY_CODE_NAME, unitOfMeasure: "dollar", approvalStatus: "in_progress", type: "abstract", baseValue: 1, rarity: "common", massPerUnit: 0, gridWidth: 1, gridHeight: 1, tradeable: false, }, draft: false, overrideAccess: true, }); currencyId = created.id as number; } const rules = await payload.findGlobal({ slug: "game-rules" }); await payload.updateGlobal({ slug: "game-rules", data: { ...(rules as unknown as Record), mainCurrency: currencyId, }, overrideAccess: true, }); payload.logger.info(`[test-db] baseline ready: main currency resource ${currencyId}`); process.exit(0);