import { prisma } from "../src/db/prisma.js"; import { syncRecipeSources } from "../src/db/recipe-source-sync.js"; import { seedReferenceData } from "../src/db/reference-seed-data.js"; // Single TRUNCATE ... CASCADE covers FK ordering and resets identity // sequences — used between tests/scenarios to start from a clean slate. // Re-seeds the Diet/Category/Allergy/Unit reference data right after // truncating it, so every test starts from the same realistic reference // data the real app seeds (`prisma/seed.ts`) rather than empty tables — // tests exercising dietId/allergyIds/unitId need real rows to reference. // `syncRecipeSources` runs last, for the same reason: `sources` should // reflect whatever adapters this test run happens to have registered // (usually none — see recipe-source-registry.ts). export async function resetDatabase() { await prisma.$executeRawUnsafe(` TRUNCATE TABLE "user_profile_allergy", "user_preference", "allergy", "category", "planning_item", "planning", "recipe_ingredient", "step", "tech_step_mapping", "tech_step", "recipe", "ingredients", "sources", "unit", "user_profiles", "diet", "house" RESTART IDENTITY CASCADE; `); await seedReferenceData(prisma); await syncRecipeSources(prisma); }