/** * Testing utilities for @lexmata/nestjs-multi-tenant * * These utilities help with mocking tenant context in unit tests. * * @example * ```typescript * import { createMockTenantContext, MockTenantContextService } from '@lexmata/nestjs-multi-tenant/testing'; * * // Create a mock tenant context service * const mockService = createMockTenantContext({ id: 'test-tenant', name: 'Test' }); * * // Use in your test module * const module = await Test.createTestingModule({ * providers: [ * { provide: TenantContextService, useValue: mockService }, * MyService, * ], * }).compile(); * ``` */ import type { Tenant } from '../interfaces'; /** * Mock implementation of TenantContextService for testing */ export declare class MockTenantContextService { private tenant; constructor(tenant?: Tenant); /** * Set the current tenant for tests */ setTenant(tenant: Tenant | undefined): void; /** * Get the current tenant */ getTenant(): Tenant | undefined; /** * Get the current tenant ID */ getTenantId(): string | undefined; /** * Check if a tenant is set */ hasTenant(): boolean; /** * Run a function within a tenant context (no-op for mock, just calls fn) */ run(tenant: Tenant, fn: () => T): T; /** * Clear the tenant (useful for test cleanup) */ clear(): void; } /** * Create a mock TenantContextService with an optional initial tenant * * @param tenant - Optional initial tenant to set * @returns MockTenantContextService instance * * @example * ```typescript * // Without initial tenant * const mockContext = createMockTenantContext(); * expect(mockContext.hasTenant()).toBe(false); * * // With initial tenant * const mockContext = createMockTenantContext({ id: 'tenant-123', name: 'Acme Corp' }); * expect(mockContext.getTenantId()).toBe('tenant-123'); * ``` */ export declare function createMockTenantContext(tenant?: Tenant): MockTenantContextService; /** * Create a mock request object with tenant attached * * @param tenant - The tenant to attach to the request * @param overrides - Additional request properties to set * @returns Mock request object * * @example * ```typescript * const req = createMockRequest({ id: 'tenant-123' }, { * method: 'GET', * path: '/api/users', * }); * expect(req.tenant?.id).toBe('tenant-123'); * ``` */ export declare function createMockRequest(tenant?: Tenant, overrides?: Partial<{ method: string; path: string; url: string; hostname: string; headers: Record; query: Record; cookies: Record; }>): { tenant?: Tenant; method: string; path: string; url: string; hostname: string; headers: Record; query: Record; cookies: Record; }; /** * Create a mock execution context for testing guards and decorators * * @param tenant - The tenant to include in the request * @param options - Additional options for the context * @returns Mock ExecutionContext-like object * * @example * ```typescript * const ctx = createMockExecutionContext({ id: 'tenant-123' }); * const guard = new TenantGuard(new Reflector(), mockTenantContext); * expect(guard.canActivate(ctx)).toBe(true); * ``` */ export declare function createMockExecutionContext(tenant?: Tenant, options?: { type?: 'http' | 'graphql' | 'rpc' | 'ws'; handler?: () => unknown; class?: new () => unknown; }): { switchToHttp: () => { getRequest: () => { tenant?: Tenant; }; getResponse: () => Record; getNext: () => () => void; }; switchToRpc: () => { getData: () => { tenant?: Tenant; }; getContext: () => { tenant?: Tenant; }; }; switchToWs: () => { getClient: () => { tenant?: Tenant; }; getData: () => { tenant?: Tenant; }; }; getType: () => string; getHandler: () => () => unknown; getClass: () => new () => unknown; getArgs: () => unknown[]; getArgByIndex: (index: number) => unknown; }; /** * Helper to create a tenant object for testing * * @param id - Tenant ID (required) * @param properties - Additional tenant properties * @returns Tenant object * * @example * ```typescript * const tenant = createTestTenant('tenant-123', { name: 'Acme Corp', plan: 'pro' }); * ``` */ export declare function createTestTenant(id: string, properties?: Record): Tenant; /** * Type-safe helper for creating multiple test tenants * * @param tenants - Array of tenant definitions * @returns Array of Tenant objects * * @example * ```typescript * const tenants = createTestTenants([ * { id: 'tenant-1', name: 'Acme' }, * { id: 'tenant-2', name: 'Globex' }, * ]); * ``` */ export declare function createTestTenants(tenants: ({ id: string; } & Record)[]): Tenant[]; //# sourceMappingURL=index.d.ts.map