import { MinimalTenantContext, TenantContextData } from './context.js'; /** * Reset all tenancy state (for use in beforeEach/afterEach) * * This clears: * - Registered interceptors * - Tenant-scoped class registry * * @example * ```typescript * afterEach(() => { * resetTenancy(); * }); * ``` */ export declare function resetTenancy(): void; /** * Create a test tenant context and run code within it * * Convenience wrapper around withTenant() with sensible defaults for testing. * * @param context - Tenant context (can be minimal, just tenantId) * @param fn - Async function to run in the context * * @example * ```typescript * await createTestTenantContext({ tenantId: 'test-tenant' }, async () => { * const product = await collection.create({ name: 'Test' }); * expect(product.tenantId).toBe('test-tenant'); * }); * ``` */ export declare function createTestTenantContext(context: MinimalTenantContext | TenantContextData, fn: () => Promise): Promise; /** * Create multiple tenant contexts for isolation testing * * @param tenantIds - Array of tenant IDs to create contexts for * @param fn - Function that receives an object mapping tenant IDs to context runners * * @example * ```typescript * await testTenantIsolation(['tenant-a', 'tenant-b'], async (tenants) => { * // Create in tenant A * const docA = await tenants['tenant-a'](async () => { * return collection.create({ title: 'A doc' }); * }); * * // Verify not visible in tenant B * await tenants['tenant-b'](async () => { * const found = await collection.get(docA.id); * expect(found).toBeNull(); * }); * }); * ``` */ export declare function testTenantIsolation(tenantIds: string[], fn: (tenants: Record(runner: () => Promise) => Promise>) => Promise): Promise; /** * Options for `setupTestTenancy()`. * * @see setupTestTenancy */ export interface SetupTestTenancyOptions { /** * Enable tenancy interceptors * @default true */ enableInterceptors?: boolean; /** * Raw query policy for tests * @default 'throw' */ rawQueryPolicy?: 'throw' | 'warn' | 'allow'; } /** * Set up tenancy for a test suite * * Call in beforeAll or at the start of tests to configure tenancy. * * @param options - Setup options * * @example * ```typescript * beforeAll(() => { * setupTestTenancy({ enableInterceptors: true }); * }); * * afterAll(() => { * resetTenancy(); * }); * ``` */ export declare function setupTestTenancy(options?: SetupTestTenancyOptions): void; /** * Assert that executing `fn` throws a `TenantContextError`. * * Fails with a descriptive message if `fn` completes without throwing, or if * it throws a different error type. Optionally verifies that the error message * contains a specific substring. * * Useful for testing that business-logic code correctly rejects calls that are * made outside a tenant context. * * @param fn - Async function that should throw `TenantContextError`. * @param messageContains - Optional substring the error message must include. * * @example * ```typescript * await assertTenantContextRequired(async () => { * // No withTenant() in scope * await documentCollection.list({}); * }); * ``` * * @see assertTenantIsolationViolation * @see TenantContextError */ export declare function assertTenantContextRequired(fn: () => Promise, messageContains?: string): Promise; /** * Assert that executing `fn` throws a `TenantIsolationError`. * * Fails with a descriptive message if `fn` completes without throwing, or if * it throws a different error type. Optionally verifies that the error message * contains a specific substring. * * Use this to verify that cross-tenant data access attempts are correctly * blocked by the interceptor. * * @param fn - Async function that should throw `TenantIsolationError`. * @param messageContains - Optional substring the error message must include. * * @example * ```typescript * await withTenant({ tenantId: 'tenant-a' }, async () => { * await assertTenantIsolationViolation(async () => { * // Attempt to filter by a different tenant * await collection.list({ where: { tenantId: 'tenant-b' } }); * }); * }); * ``` * * @see assertTenantContextRequired * @see TenantIsolationError */ export declare function assertTenantIsolationViolation(fn: () => Promise, messageContains?: string): Promise; //# sourceMappingURL=testing.d.ts.map