- getPreferences: SYSTEM par défaut si aucune ligne (même logique que dietId/allergies : absent = valeur par défaut, pas une omission) - updatePreferences: upsert (crée la ligne au premier PATCH) - Tests Mocha + Cucumber : 401, valeur invalide, défaut, création à la volée, cloisonnement entre profils
21 lines
966 B
TypeScript
21 lines
966 B
TypeScript
import { prisma } from "../src/db/prisma.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 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 need real rows to reference.
|
|
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",
|
|
"user_profiles", "diet", "house"
|
|
RESTART IDENTITY CASCADE;
|
|
`);
|
|
await seedReferenceData(prisma);
|
|
}
|