import { afterAll, beforeEach, inject } from "vitest"; import mongoose from "mongoose"; import { connectDb } from "@/lib/server/db"; declare module "vitest" { export interface ProvidedContext { mongoUri: string; } } process.env.MONGODB_URI = inject("mongoUri"); process.env.JWT_ACCESS_SECRET = "test-access-secret-0123456789"; process.env.JWT_REFRESH_SECRET = "test-refresh-secret-0123456789"; process.env.PLATFORM_ADMIN_EMAILS = "operator@aquaflow.test"; beforeEach(async () => { await connectDb(); const collections = await mongoose.connection.db!.collections(); await Promise.all(collections.map((c) => c.deleteMany({}))); await Promise.all(Object.values(mongoose.models).map((m) => m.syncIndexes())); }); afterAll(async () => { await mongoose.disconnect(); global.__mongooseCache = { conn: null, promise: null }; });