import { Db, MongoClient } from 'mongodb'; import type { ISchema } from '../../interfaces/types'; import { MongoService } from './mongo.service'; /** * Provides utilities for managing a MongoDB database during tests. * * Handles database connections, collection creation, schema validation, * index creation, and database cleanup. * * @example * ```ts * const database = new MongoTestService(process.env.MONGO_URI!, 'api_test') * * await database.open() * * try { * await database.createCollections(listSchema) * // Run tests * } finally { * await database.close() * } * ``` */ export declare class MongoTestService { private mongoClient; private mongoService; private db; /** * Creates a MongoDB test service. * * Initializes the MongoDB client and database reference. * The connection is not established until {@link open} is called. * * @param uri - MongoDB connection URI. * @param name - Name of the test database. */ constructor(uri: string, name: string); /** * Provides access to the MongoDB client. * * Use this to access native MongoDB client functionality, * such as creating sessions and managing transactions. * * @example * ```ts * const session = mongoTestService.client.startSession() * ``` */ get client(): MongoClient; /** * Provides access to the MongoDB database. * * Use this to perform direct database operations in tests, * such as inserting fixtures and querying documents. * * @example * ```ts * await mongoTestService.database.collection('users').insertOne({ * email: 'john@example.com' * }) * ``` */ get database(): Db; /** * Provides access to the MongoDB service. * * Use this to perform MongoDB operations through the service abstraction * instead of accessing the database directly. * * @example * ```ts * await mongoTestService.service.createUnique('users', { email: 1 }) * ``` */ get service(): MongoService; /** * Establishes a connection to MongoDB. * * @returns A promise that resolves when the connection is established. */ open(): Promise; /** * Closes the MongoDB connection. * * @returns A promise that resolves when the connection is closed. */ close(): Promise; /** * Creates collections defined in the provided schema configuration. * * For each collection, this method: * - Creates the collection if it does not exist. * - Applies the collection's JSON schema validation. * - Creates unique indexes. * - Creates unique sparse indexes for fields that may be missing or null. * * Existing collections are not dropped or recreated. * * @param listSchema - Grouped collection schema configurations. * @returns A promise that resolves when all collections and indexes are configured. * * @example * ```ts * await database.createCollections(listSchema) * ``` */ createCollections(listSchema: ISchema[][]): Promise; /** * Drops the entire test database, including all its collections and indexes. * * Use this when a complete database cleanup is required. * * @returns A promise that resolves when the database has been dropped. * * @example * ```ts * await database.dropDatabase() * ``` */ dropDatabase(): Promise; /** * Drops every collection in the test database. * * Unlike {@link dropDatabase}, this keeps the database itself. * * @returns A promise that resolves when all collections have been dropped. * * @example * ```ts * await database.dropAllCollections() * ``` */ dropAllCollections(): Promise; /** * Removes all documents from every collection in the test database. * * Collections, indexes, and schema validation rules are preserved. * * @returns A promise that resolves when all collections have been cleared. * * @example * ```ts * // Clear test data before each test. * await database.reset() * ``` */ reset(): Promise; } //# sourceMappingURL=mongo-test.service.d.ts.map