UNPKG

@directus/api

Version:

Directus is a real-time API and App dashboard for managing SQL database content

49 lines (48 loc) 1.72 kB
/** * Database mocking utilities for service tests * Provides simplified mocks for src/database/index module used in service testing */ import type { DatabaseClient } from '@directus/types'; /** * Creates a standard database mock for service tests * This matches the pattern used across all service test files * * @param client Database client to mock (default: 'postgres') * @returns Mock module object for vi.mock() * * @example * ```typescript * // Standard usage * vi.mock('../../src/database/index', () => mockDatabase()); * * // For MySQL-specific tests * vi.mock('../../src/database/index', () => mockDatabase('mysql')); * * // To dynamically change the client during tests, import and mock directly: * import { getDatabaseClient } from '../database/index.js'; * vi.mocked(getDatabaseClient).mockReturnValue('mssql'); * ``` */ export declare function mockDatabase(client?: DatabaseClient): { default: import("vitest").Mock<(...args: any[]) => any>; getDatabaseClient: import("vitest").Mock<(...args: any[]) => any>; getSchemaInspector: import("vitest").Mock<(...args: any[]) => any>; }; /** * Creates a mock for the transaction utility * By default, the mock simply executes the callback with the provided knex instance * (no actual transaction wrapper, which is fine for most service tests) * * @returns Mock module object for vi.mock() * * @example * ```typescript * vi.mock('../utils/transaction.js', async () => { * const { mockTransaction } = await import('../__mocks__/database.js'); * return mockTransaction(); * }); * ``` */ export declare function mockTransaction(): { transaction: import("vitest").Mock<(knex: any, callback: any) => any>; };