/** * Singleton PrismaClient against the hermetic test DB (DATABASE_URL from .env.test, loaded by * setup/load-env.ts). Used by: * - the fixture seeder (fixtures/seed-core.ts), and * - "direct-instantiation" specs for services behind the IAM/RabbitMQ wall (BookingsService, * PaymentsService, WalletService, …) which cannot be booted through their Nest modules because * those transitively import the @tria-plc IAM stack (ESM-only `file-type`) / golevelup RabbitMQ. * Those specs `new TheService(prisma, ...mockedCollaborators)` and assert the money logic. */ import { PrismaClient } from "@prisma/client"; let client: PrismaClient | undefined; export function getTestPrisma(): PrismaClient { if (!client) { client = new PrismaClient(); } return client; } export async function disconnectTestPrisma(): Promise { if (client) { await client.$disconnect(); client = undefined; } }